ObserverBuilt incomes with cpbenchy
cpbenchy run instances/ -s ortools -t 60 -p cpbenchy.observers:ModelSize- Version
- cpbenchy 0.1.0.dev0
- Last updated
- 6 Oct 2026 · 1 commit
- Authors
- ThomSerg
- Tags
- statisticsmodel
What it does
Counts the variables (and how many are Boolean) and the constraints of every model, as loaded, so you can relate solving times to model size.
Use it
import cpbenchy
from cpbenchy import observers
results = cpbenchy.run("instances/", solvers=["ortools"], time_limit=60, plugins=[observers.ModelSize()])
results.to_pandas().groupby(["solver", "status"])["extra.n_variables"].describe()cpbenchy run instances/ -s ortools -t 60 -p cpbenchy.observers:ModelSize
cpbenchy show --by solver,statusWhat it records
extra["n_variables"] |
the model’s decision variables |
extra["n_boolvars"] |
of which Boolean |
extra["n_constraints"] |
the model’s top-level constraints |
Implementation
The ModelSize in src/cpbenchy/observers.py, lines 190–201 of 222, as of this version of the docs.
class ModelSize(Observer):
"""Record the size of each model: `n_variables` (of which `n_boolvars` Boolean) and `n_constraints`."""
def on_finish(self, ctx):
if ctx.model is None: # loading failed
return
from cpmpy.transformations.get_variables import get_variables_model
variables = get_variables_model(ctx.model)
ctx.record("n_variables", len(variables))
ctx.record("n_boolvars", sum(1 for v in variables if v.is_bool()))
ctx.record("n_constraints", len(ctx.model.constraints))