Skip to content

solve tally (or: solve count) #244

Closed
Closed

Description

@Pierre-Flener

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)?

Activity

  1. schutta commented on Sep 30, 2018

    @schutta
    Member

    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.

  2. Pierre-Flener commented on Oct 3, 2018

    @Pierre-Flener
    Author

    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!

  3. added a commit that references this issue on Jun 4, 2019
    34199aa
  4. guidotack commented on Jun 4, 2019

    @guidotack
    Member

    The next release will print a statistics line with the number of solutions after solving has finished (enabled using the -s command line switch).

  5. added theissue type on Jan 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions