Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Counting total number of solutions with minizinc

Tags:

minizinc

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?

like image 663
Agnishom Chattopadhyay Avatar asked Dec 24 '16 04:12

Agnishom Chattopadhyay


1 Answers

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.

like image 121
hakank Avatar answered Sep 23 '22 05:09

hakank