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
Flatzinc losing constraint information that leads to incorrect solutions #259
Comments
Hi @lalithsuresh, The two code samples are not equivalent. The first code sample allows for the sum to be 0, while the second sample doesn't. When the sum is zero, it does not constrain the variable
|
Yikes, posted a wrong minimal test case. Sorry about that. Long day. :) The way I got there was:
The above code returns x=-1, 0, 1. I understand 'length' is not a function that I should use for this purpose, but in the absence of an error messsage, I was confused. So when I tried this instead:
I get "MiniZinc: evaluation error: cannot evaluate expression 'x'". Is this expected? |
There's a section in the manual that explains the behaviour of the length function in this case ("2.4.2 Hidden option types"). So the array you declare in the comprehension will always be of length 2, no matter what value x takes, because MiniZinc doesn't support variable-length arrays. The error you get is indeed not expected, I will try to fix it for the next release. |
Thanks @guidotack @Dekker1. I appreciate your quick responses! |
Here's another variant of the problem I was encountering with opt variables.
This returns every entry in the domain of x as valid solutions:
Which is wrong, because if I assign some of those values to x directly like this:
... it correctly warns me that there's a model inconsistency and declares UNSAT. Also related is if I treat x as a var like before, but do:
It says x = array1d(1..2, [1, 2]); is a solution. And lastly, if I write the predicate out directly inside the forall statement:
I get "Cannot evaluate expression 'X_INTRODUCED_0_'". |
Sorry for the delayed reply, I hope it's still useful. We've been able to fix the issues that result in "cannot evaluate expression..." errors. For the unexpected behaviour (satisfiable vs. unsatisfiable), at least I can offer an explanation. The problem is the expression |
The following code should get x=1 as the only solution, but it instead gives -1, 0, and 1 as solutions (or -Int.Max to +Int.Max if I don't specify bounds for x).
(The behavior is just as bad if I don't constraint i in the generator expression with 1..2. My original code was using another array 'z' instead of 1..2).
However, the following code does the right thing:
The text was updated successfully, but these errors were encountered: