chocoteam / choco-solver

An open-source Java library for Constraint Programming
http://choco-solver.org/
BSD 4-Clause "Original" or "Old" License
683 stars 137 forks source link

[BUG] MiniZinc parser crashes on a model with float vars #1098

Open SYury opened 1 month ago

SYury commented 1 month ago

Describe the bug Consider the following MiniZinc model:

var -100.0..100.0: x;
var -100.0..100.0: y;
constraint 2 * x + 3 * y >= 10;
solve satisfy;

When I run Choco on this model in MiniZinc IDE, it crashes with the following stacktrace:

%% Choco 231102
line 1:44 mismatched input '.' expecting {',', ']'}
Exception in thread "main" java.lang.UnsupportedOperationException: Parameter#buildArray ARRAY: unexpected type for X_INTRODUCED_2_
    at org.chocosolver.parser.flatzinc.ast.FParameter.buildArray(FParameter.java:162)
    at org.chocosolver.parser.flatzinc.ast.FParameter.make_parameter(FParameter.java:49)
    at org.chocosolver.parser.flatzinc.Flatzinc4Parser.param_decl(Flatzinc4Parser.java:1168)
    at org.chocosolver.parser.flatzinc.Flatzinc4Parser.flatzinc_model(Flatzinc4Parser.java:212)
    at org.chocosolver.parser.flatzinc.Flatzinc.parse(Flatzinc.java:199)
    at org.chocosolver.parser.flatzinc.Flatzinc.buildModel(Flatzinc.java:152)
    at org.chocosolver.parser.flatzinc.ChocoFZN.main(ChocoFZN.java:27)

It looks like the line array [1..2] of float: X_INTRODUCED_2_ = [-2.0,-3.0]; in generated flatzinc representation kills the parser. When I change the variables to ints it works. Environment (please complete the following information):

cprudhom commented 1 month ago

That's because the flatzinc parser of choco-solver does not support float variables and constraints.

SYury commented 1 month ago

That's because the flatzinc parser of choco-solver does not support float variables and constraints.

That's unfortunate. Is there any way to pass a model with float variables to choco-solver without writing the Java code by hand?

cprudhom commented 1 month ago

Sadly, no, it requires to update the parser in order to support float variables and float constraints declaration. It is probably not too difficult, a copying-and-pasting strategy could be applied, but I already have two projects underway.