PluginBuilt incomes with cpbenchy
on by default; --no-solutions turns it off
- Version
- cpbenchy 0.1.0.dev0
- Last updated
- 6 Oct 2026 · 1 commit
- Authors
- ThomSerg
- Tags
- built-inanytime
What it does
Records every run’s solutions over time: for optimization problems, each better objective value the solver finds, with when it found it. It is on by default, for every run, through CPMpy’s solution callback. Runs that are killed keep what they recorded.
Use it
Nothing to do. To turn it off (no solution callback, for solvers where it costs time):
import cpbenchy
cpbenchy.run("instances/", solvers=["ortools"], time_limit=60, args=["--no-solutions"])cpbenchy run instances/ -s ortools -t 60 --no-solutionsWhat it records
extra["solutions"] |
[[seconds, objective], ...] |
Implementation
The file src/cpbenchy/solutions.py, 23 lines, as of this version of the docs.
"""Built-in plugin: record each run's solutions over time, as `extra["solutions"]`: [[seconds, objective], ...].
The worker reports solutions of optimization problems through CPMpy's `display` callback (see
`cpbenchy.worker.solvers`). Recorded from the events, so also for runs that get killed.
"""
from cpbenchy import hookimpl
@hookimpl
def cpbenchy_addoption(parser):
parser.getgroup("run").addoption(
"--no-solutions",
dest="solutions",
action="store_false",
help="don't report intermediate solutions (no solution callback)",
)
@hookimpl
def cpbenchy_run_event(run, event):
if event.kind == "solution":
run.extra.setdefault("solutions", []).append([round(event.t, 3), event.data["objective"]])