简体   繁体   English

Minizinc:if-then-else语句中的数组分配问题

[英]Minizinc: Issue in array assignment in if-then-else statement

var 1..5: k=1;
array[1..2] of var 1..48: key2;
constraint forall(i in 1..4,j in 1..48 where k= ceil(j/24))(if 
                 table[i,j]!=0 then key2[k]=j else true endif);

I am trying to apply this constraint in my minizinc program.Objective is to maximize cost function and this is one of the constraints but when i run this code it shows 我试图在我的minizinc程序中应用此约束。目标是最大化成本函数,这是约束之一,但是当我运行此代码时,它显示

Finished in 203msec
Compiling first.mzn with data empdata2.dzn
Running first.mzn
=====UNSATISFIABLE=====
Finished in 189msec

If I replace key2[k]=j with true then it compiles and run without any errors. 如果我将key2 [k] = j替换为true,那么它将编译并运行而没有任何错误。 I am not using key2 array anywhere else in my program.I am using datafile to give input and i have initiailised key2 array as key2=[1,1]. 我不在程序中的其他任何地方使用key2数组。我正在使用数据文件提供输入,并且我已将key2数组初始化为key2 = [1,1]。 I am beginner in minizinc and I am not understanding why is there problem in assigning number to array in this case? 我是minizinc的初学者,我不明白为什么在这种情况下将数字分配给数组会出现问题?

I ran the following model and it gave a lot of solutions (using "solve satisfy") for both Gecode and G12fd solvers. 我运行了以下模型,它为Gecode和G12fd求解器提供了很多解决方案(使用“ solve满足”)。 Which MiniZinc version do you use? 您使用哪个MiniZinc版本? I use the latest Git version MiniZinc 2.0 which is about the same as v2.0.2. 我使用最新的Git版本MiniZinc 2.0,与v2.0.2大致相同。

var 1..5: k=1;
array[1..2] of var 1..48: key2;
array[1..4,1..48] of var 0..1: table;

solve satisfy;

constraint forall(i in 1..4,j in 1..48 where k= ceil(j/24))(if 
              table[i,j]!=0 then key2[k]=j else true endif);

output [
    "key2:", show(key2), "\n",
    "table: ", show(table), "\n",
];

Do you have other constraints in the model not shown here? 您在模型中是否还有其他约束未在此处显示?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM