paolodragone / pymzn

A Python wrapper for the MiniZinc tool pipeline.
MIT License
55 stars 15 forks source link

FlatZinc::AST::TypeError with chuffed and output_vars #20

Closed HelgeS closed 6 years ago

HelgeS commented 6 years ago

When generating a MiniZinc model with output variables, pymzn adds output annotations, such as output_array([1..52]). When using Chuffed as a solver, this leads to an error FlatZinc::AST::TypeError.

Example

Using the attached files, running chuffed fails, while mzn-gecode works:

$ mzn-chuffed pymzn_lo34fh_5.mzn pymzn_lo34fh_5.dzn
terminate called after throwing an instance of 'FlatZinc::AST::TypeError'

The error is issued by the annotations in lines 5-6 in the mzn file:

array[1..52] of var 1..52: x :: output_array([1..52]);
array[1..52] of var 1..52: y :: output_array([1..52]);

In pymzn, they are added in _redefine_output_vars in model.py.

pymzn was invoked via: pymzn.minizinc('black-hole.mzn' , data={'layout': [[10, 11, 12], [30, 7, 4], [20, 36, 22], [37, 18, 9], [33, 19, 29], [26, 2, 51], [31, 44, 25], [50, 52, 43], [38, 48, 41], [27, 49, 42], [34, 3, 46], [5, 47, 24], [28, 21, 16], [45, 14, 15], [32, 23, 40], [39, 6, 35], [8, 17, 13]]}, all_solutions=False, solver=pymzn.chuffed, output_vars=['x', 'y'], output_mode='dict', force_flatten=True, keep=False)

force_flatten=True is not relevant for the problem, but a workaround for this issue.

I'm not entirely sure in which cases the output annotations might be necessary. For now, I've removed the call to this method locally, but that's only a workaround.

pymzn_lo34fh_5.dzn.txt pymzn_lo34fh_5.mzn.txt black-hole.mzn.txt

paolodragone commented 6 years ago

I don't recall exactly in which case the output annotations were needed, probably when using some old version of MiniZinc in some very particular case, such as when you have no optimization variables but you want to compute a function of the input using solve satisfy. I will add the option to avoid using output annotations when compiling the model.

paolodragone commented 6 years ago

Solved in version 0.16.9. You can now add the option no_output_annotations=True to the function pymzn.minizinc to disallow output annotation when compiling the model.