条件输出minizinc
Conditional output minizinc
我正在使用 minizinc,我正在尝试实现条件输出,如果数组元素具有值 'true',程序将输出有关这些元素的数组索引的信息。这是我的:
include "globals.mzn";
int: time=5;
int: n=3;
int: l=n*n;
array[1..4,0..time,1..l] of var bool: X;
constraint X[1,5,7]=true;
constraint X[2,5,3]=true;
constraint X[3,5,9]=true;
constraint X[4,5,7]=true;
solve satisfy;
我尝试使用 concat 来解决这个问题,如下所示:
output ["X_"++concat(["\(r)_\(t)_\(pos)"
| pos in 1..l, r in 1..4, t in 0..time, where X[r,t,pos]==true])++"\n"];
但是我不允许,
"MiniZinc: type error: no function or predicate with this signature found: `concat(array[int] of var opt string)'"
我想要的是,
for pos in 1..l, r in 1..4, t in 0..time
if X[r,t,pos]==true
output ["X_\(r)_\(pos)_\(t)"]
如何实现?
尝试在 where
子句中围绕决策变量使用 fix(...)
,例如
output ["X_"++concat(["\(r)_\(t)_\(pos)"
| pos in 1..l, r in 1..4, t in 0..time, where fix(X[r,t,pos])==true])++"\n"];
fix
在使用决策变量的实际值时(经常)需要,例如用于比较其值等
(关于 var opt string
的消息在这种情况下可能具有误导性。)
我正在使用 minizinc,我正在尝试实现条件输出,如果数组元素具有值 'true',程序将输出有关这些元素的数组索引的信息。这是我的:
include "globals.mzn";
int: time=5;
int: n=3;
int: l=n*n;
array[1..4,0..time,1..l] of var bool: X;
constraint X[1,5,7]=true;
constraint X[2,5,3]=true;
constraint X[3,5,9]=true;
constraint X[4,5,7]=true;
solve satisfy;
我尝试使用 concat 来解决这个问题,如下所示:
output ["X_"++concat(["\(r)_\(t)_\(pos)"
| pos in 1..l, r in 1..4, t in 0..time, where X[r,t,pos]==true])++"\n"];
但是我不允许, "MiniZinc: type error: no function or predicate with this signature found: `concat(array[int] of var opt string)'"
我想要的是,
for pos in 1..l, r in 1..4, t in 0..time
if X[r,t,pos]==true
output ["X_\(r)_\(pos)_\(t)"]
如何实现?
尝试在 where
子句中围绕决策变量使用 fix(...)
,例如
output ["X_"++concat(["\(r)_\(t)_\(pos)"
| pos in 1..l, r in 1..4, t in 0..time, where fix(X[r,t,pos])==true])++"\n"];
fix
在使用决策变量的实际值时(经常)需要,例如用于比较其值等
(关于 var opt string
的消息在这种情况下可能具有误导性。)