You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there an easy way to mimic the afaik-non-existing-yet "solve tally" objective (one could call it "solve count", but "count" is already a predicate/function) for just counting (rather than displaying) solutions (to a CSP)?
One can of course, from the command line, pipe the output into wc (word count), subtract 1 from the line count (due to the final line starting with =====) and divide by 2 (in order to avoid counting all ----------), but that's clumsy.
Btw, what combination of values for the command-line options "soln-sep" and "soln-comma" eliminates the apparently forced line between two consecutive displayed solutions (so that one can skip the division by 2 above)?
Instead of wc you could use awk for piping. For example:
$ minizinc a.mzn -a | awk '/^----------/ {a++;print "% sol_no = " a ";"} {print}'
The output looks as follows
x = 1;
y = 5;
% sol_no = 1;
----------
x = 1;
y = 6;
% sol_no = 2;
----------
x = 2;
y = 6;
% sol_no = 3;
----------
==========
for this model.
var 1..6: x :: add_to_output;
var 1..6: y :: add_to_output;
constraint x + 3 < y;
solve satisfy;
Instead of declaring the "solve tally" inside the model, imo, it is better to add an option to minizinc and solns2out similar to --output-time, which adds the "solve tally" in the output as a comment.
Activity
schutta commentedon Sep 30, 2018
Instead of
wcyou could useawkfor piping. For example:The output looks as follows
for this model.
Instead of declaring the "solve tally" inside the model, imo, it is better to add an option to
minizincandsolns2outsimilar to--output-time, which adds the "solve tally" in the output as a comment.Pierre-Flener commentedon Oct 3, 2018
Thanks (it's been some time I played with awk)!
I like the suggested idea of adding a new command-line option for tallying, so that's for my wish list!
Print number of solutions as mzn-stat after solving. Fixes #244.
guidotack commentedon Jun 4, 2019
The next release will print a statistics line with the number of solutions after solving has finished (enabled using the -s command line switch).