2

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

kirbo
  • 1,707
  • 5
  • 26
  • 32
  • 3
    The only thing I can think with the information you give is that `fzn-gecode` will not output the variables according to the output statement, but by whatever is deemed a variable. Depending on the rest of your model the compiler might already solve the problem and `fzn-gecode` will not output anything. You can solve this by running your model directly using `mzn-gecode -a model.mzn test.mzn`. If that does not work, then we need more information to help you: what version of MiniZinc/Gecode you are working with, the rest of your model, and the output you get in both cases. – Dekker1 Jun 07 '17 at 09:26

2 Answers2

3

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:

  • Try to output your matrix F first, then target variable

output [show(F),show(target)];

  • Directs solver to assign values to F first during solve

solve ::int_search(array1d(F),input_order, indomain, complete) minimize target;

0

output [ "target: " ++ show(target) ++ "\n"];

Thomas Li
  • 1
  • 1