4

Try to learn minizinc but after going through examples, may I just confirm that I actually have to write some procedural language if I want to get multiple output or there is a more "natural to minizinc" way to get it.

For example, suppose I want to have all distinct digits add up to 3 the answers should be 0+3 1+2 2+1 3+0 ...

My mininzinc here:

% how to generate more than one result meeting the constraints

int: n=3;

var 0..9: a;
var 0..9: b;

include "alldifferent.mzn";
constraint all_different([a, b]);
constraint a + b = n;

solve satisfy;

output [
"a + b = n \t\n",
 show(a), " + ",
 show(b), " = ",
 show(n)];

produce only 3+0. How to get to the other answers? Thanks for any advice in advance.

I looked at a post for minizinc 1.6 and it seemed to say left out the output statement would produce all the output (Easy way to print full solution (all decision variables) in minizinc). It does not work. Only one is output.

Community
  • 1
  • 1
Dennis Ng
  • 361
  • 3
  • 11

2 Answers2

3

First of all, the default is to print all variables and their values for a solution, not all solutions.

Use the option -a to get all solutions. mzn-gecode --help to see all options. In your case mzn-gecode -a test.mzn which gives:

a + b = n   
3 + 0 = 3
----------
a + b = n   
0 + 3 = 3
----------
a + b = n   
2 + 1 = 3
----------
a + b = n   
1 + 2 = 3
----------
==========
Kobbe
  • 809
  • 5
  • 16
1

Under configuration there is an option to change the default from printing the first solution after satisfaction. Change it to user-defined-behaviour: print all solutions ... You can have output statement, btw, as well.

Dennis Ng
  • 361
  • 3
  • 11
  • 1
    Down vote since no answer to the confusion about that the default should print all solutions. There should be an actual answer and not "see documentation" where you don't even say how to find the documentation. – Kobbe Mar 26 '16 at 09:07
  • Not understand. The default is 1 solution. But unlike usual the configuration is in a tab. For the batch one, someone told me. – Dennis Ng Mar 29 '16 at 05:00