1

我有一组变量T_1, T_2, ..., T_N,我想在 CLPFD 中重写以下伪代码:

T_1 in 0..59, 
T_2 in 0..59, 
...
T_n in 0..59,

all_different([T_1, T_2, ..., T_n]),

FOREACH x in 0 to 59 do: 

   IF (x \in [T_1, T_2, T_3, ..., T_n]) THEN 
         Slot_x = 1 
   ELSE 
         Slot_x = 0

ENDFOREACH

我怎样才能做到这一点?

我会使用count

T_1 in 0..59, 
T_2 in 0..59, 
...
count(0, [T_1, T_2, ..., T_n], #=, Slot_0) % The number 0 can be at most once in the list
count(1, [T_1, T_2, ..., T_n], #=, Slot_1) % The number 1 can be at most once in the list
...

但我相信更有经验的程序员不会这样写。

4

1 回答 1

4

您可以摆脱 all_different 和 count 约束,如下所示:

T_1 in 0..59, 
T_2 in 0..59, 
...
T_n in 0..59,

Slot_0 in 0..1,
Slot_1 in 0..1,
...
Slot_59 in 0..1,

global_cardinality([T_1, T_2, ..., T_n], [0-Slot_0, 1-Slot_1, ..., 59-Slot_59]).
于 2013-05-30T10:02:25.013 回答