Reputation: 1727
I have a simple model written in minizinc and I use gecode to solve it by compiling it into flat-zinc first. As an input, the model takes some constants, arrays, and matrices (in the form of 2-dimensional arrays). The output of the model is another 2d matrix that has to satisfy some constraints.
Target optimization is to minimize the value of "target" which is a particular function of the output matrix and defined as following:
var float: target = sum(i in 1..nodes, j in 1..nodes) (F(i, j) * output_matrix[i, j]);
solve minimize target;
When I execute this model as follows:
mzn2fzn model.mzn model.dzn
fzn-gecode -a model.fzn
I can see a stream of possible solutions with the last one in the list to be the optimal. However, if I add an output statement into the model to print the value of the "target" variable - gecode hangs for hours without finding any solutions at all and prints ==UNKNOWN== if interrupted.
output [
"target: ", show(target), "\n"
];
Is this is an expected behavior, if so, could you explain why?
Cheers
Upvotes: 3
Views: 621
Reputation: 629
This happens because output statement has influence on variables order during the solve phase.
In your case you output "target", so solver will try to assign value first to "target", then assign values to F matrix (i assume that F is your decision variables?), and this order of solving might take forever.
2 options:
output [show(F),show(target)];
solve ::int_search(array1d(F),input_order, indomain, complete) minimize target;
Upvotes: 4