Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added output fails on enum type. #38

Closed
Moisan opened this issue Jul 25, 2019 · 3 comments
Closed

Added output fails on enum type. #38

Moisan opened this issue Jul 25, 2019 · 3 comments
Assignees
Labels

Comments

@Moisan
Copy link
Contributor

Moisan commented Jul 25, 2019

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:

import pymzn
pymzn.minizinc("temperature.mzn", keep=True)

You can note the show(ACTION) in the output of the generated mzn file. When removing that part of the line, the model works fine.

@paolodragone
Copy link
Owner

paolodragone commented Jul 29, 2019

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.

@paolodragone paolodragone self-assigned this Jul 29, 2019
@Moisan
Copy link
Contributor Author

Moisan commented Jul 30, 2019

I think that might be this issue. It seems to have been solved in the develop branch.

@paolodragone
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants