【问题标题】:Conditional output minizinc条件输出 minizinc
【发布时间】:2017-11-29 20:16:43
【问题描述】:

我正在搞乱 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:类型错误:找不到具有此签名的函数或谓词:`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)"]

我怎样才能实现它?

【问题讨论】:

    标签: minizinc


    【解决方案1】:

    尝试在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 的消息在这种情况下可能具有误导性。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-30
      • 2023-01-07
      • 2013-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多