Reputation: 357
I am currently trying to develop a (fairly basic) model in Minizinc.
I have reached a point up until now, where I can run the model and a satisfactory solution is found (basically calling "solve satisfy" gives a solution, haven't yet moved to optimization).
With one particular instance I am getting the solution in about 3.5 minutes. However, when I add an "output" statement, all of a sudden it gets way too slow (I stopped the run after around 2 hours).
For some more context, here is what the model looks like roughly:
int: resource1; % to read from input file
int: resource2;
...
array [1..someBound] of float: prices;
...
% some modeling variables
array [1..someBound] of var 1..var1UpperBound: myvar1;
array [1..someBound] of var 1..var2UpperBound: myvar2;
....
% my model constraints here
....
....
solve satisfy;
As I said, this would take around 3.5 mins to come up with a solution.
However, as I was progressing through the modeling, I wanted to find the maximum value in the array prices
, and display it just for a sanity check. So I added:
float: max_price = max(prices);
....
solve satisfy;
output[show(max_price)];
This suddenly made it so that it was not being solved at all (I stopped running after 2 hours, something is clearly wrong).
When playing around with it, I found that if I remove only the output
statement from the model, then it is solved within the normal 3.5 minutes, which is weird to me because this should mean that the maximum price is still being found.
Any idea on this? I did a bit of searching for similar questions / issues, but I could not find anything. Most results simply seem to point at the documentation, and I did not come across anything related there.
I am fairly new to CSP and newer still to Minizinc, so it might be something very basic which I am missing, however I have had no luck so far. Any input appreciated! Thanks!
EDIT 1: If this is related, I am using the Minizinc IDE with the default Gecode solver v6.3.0
EDIT 2: I came across this so question from before. I believe it is different from my question, because my output does not depend on a modelling variable like in this question. In my case, the solver knows the whole unchanging contents of the array as part of the input.
Upvotes: 1
Views: 248
Reputation: 357
Similarly to the upvoted solution in this question, I solved this by writing:
solve satisfy;
output[show(decisionVar1), show(decisionVar2), ..., show(decisionVarN), show(max_price)]
Essentially, I forced the output of ALL the decision variables first, and then the variable I was looking to output from the beginning.
Upvotes: 1