You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a model contains variables whose value are of type enum, pymzn includes the enum in the output with a show function which fails on enumerated enums (that are not ranges like 1..10).
Here is a small example coming from the minizinc coursera course (temperature.mzn):
var int: cost;
array[int] of int: readings = [35,35,20,20,20];
int: start = 25;
int: n = length(readings);
set of int: HOUR = 1..n;
set of int: HOUR0 = 0..n;
array[HOUR] of var ACTION: choice;
enum ACTION = {heat, strong_heat, cool, strongly_cool, do_nothing};
array[HOUR0] of var int: temp;
array[ACTION] of int: adjust = [+1, 4, -2, -5, 0];
array[ACTION] of int: adjust_cost = [1, 5, 3, 9, 0];
constraint temp[0] = start;
constraint forall(h in HOUR) (temp[h] = (temp[h-1] + readings[h]) div 2 + adjust[choice[h]]);
constraint cost = sum(t in HOUR)(adjust_cost[choice[t]]);
constraint forall(h in HOUR) (temp[h] >= 25);
constraint forall(h in HOUR) (temp[h] <= 30);
solve minimize cost;
minizinc temperature.mzn leads to a solution while the following script fails with INCOMPLETE:
Hi @Moisan, thank you for reporting this. This looks more likely to be a bug in MiniZinc. I can reproduce it with a much simpler model:
enum ACTION = {A1, A2};
array[1 .. 10] of var ACTION: choice;
solve satisfy;
output [show(ACTION), " ", show(choice)];
Running minizinc on this model gives me the same error I get with your model using PyMzn:
MiniZinc: evaluation error: not an array expression
It would be probably better if you could open an issue on libminizinc?
In the meantime I found a workaround: swapping the order of show(ACTION) (the enum) and show(choice) (the array) in the output statement makes minizinc (and pymzn) succeed. I'll implement a fix for the bug with this workaround in the next few days.
Ok, good to know! Thanks. I'll check whether it makes sense to make a fix in PyMzn in the near future then. I'll keep this issue open until either I make a fix using the workaround or the bug is fixed in MiniZinc.
When a model contains variables whose value are of type enum, pymzn includes the enum in the output with a
show
function which fails on enumerated enums (that are not ranges like1..10
).Here is a small example coming from the minizinc coursera course (
temperature.mzn
):minizinc temperature.mzn
leads to a solution while the following script fails withINCOMPLETE
:You can note the
show(ACTION)
in theoutput
of the generated mzn file. When removing that part of the line, the model works fine.The text was updated successfully, but these errors were encountered: