Counting total number of solutions with minizinc
Asked Answered
R

1

6

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?

Revoice answered 24/12, 2016 at 4:24 Comment(0)
C
6

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.

Cudbear answered 24/12, 2016 at 7:23 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.