【发布时间】:2021-10-02 14:29:20
【问题描述】:
我想解决图表着色的问题。当一个图形应该用最少数量的颜色着色时,问题就是没有相邻顶点被着色为相同的颜色。 这是我的带有玩具图的代码。
int: N_Vertices=4;
int: N_Edges=3;
array[1..N_Edges, 1..2] of int: Adjacency;
Adjacency = [| 0, 1
| 1, 2
| 1, 3|];
array [1..N_Vertices] of var int: coloring;
constraint forall(e in 1..N_Edges)(coloring[Adjacency[e, 1]] != coloring[Adjacency[e, 2]]);
constraint forall(c in coloring)(c >= 0);
solve minimize (max(coloring));
但它给了
WARNING: undefined result becomes false in Boolean context
(array access out of bounds)
Playground:11:
in call 'forall'
in array comprehension expression
with e = 1
in binary '!=' operator expression
in array access
WARNING: model inconsistency detected
Playground:11:
in call 'forall'
in array comprehension expression
with e = 1
in binary '!=' operator expression
in array access
=====UNSATISFIABLE=====
我想我在第一个约束中对 Adjacency 迭代做错了。应该怎么做呢?
【问题讨论】:
标签: arrays constraint-programming minizinc