Counting total number of solutions with minizinc

1.6k views Asked by At

Let's say I want to count the number of 80 element subsets of {1,2,..100} such that their sum is 3690.

I have the following model:

array[1..100] of var 0..1: b;

constraint (sum (i in 1..100) (i*b[i])) == 3690;
constraint (sum (i in 1..100) (b[i])) == 80;

solve satisfy;

To count the total number of solutions, I run

$ ./minizinc --all-solutions ~/Documents/code/xmas.mzn > sol.out
$ wc -l sol.out

Essentially, I am printing out all the solutions and counting them. Is there a simpler minizinc statement instead of solve satisfy that lets me count the solutions instead of finding them?

1

There are 1 answers

0
hakank On

There is no MiniZinc statement that let you do that.

However, many FlatZinc solvers - such as Gecode - show the number of solutions when the statistics parameter (usually "-s") is set. Exactly how this statistics is shown is not in the MiniZinc/FlatZinc standard.