Skip to content
cpbenchy 0.1.0.dev0 is in alpha: until version 1.0, commands, options, the Python API and the result format may still change. Pin the version you use.

ModelSize

Notes how big each model is, to relate solving times to model size.

Updated View as Markdown
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

What 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.

src/cpbenchy/observers.pypython
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))
Navigation

Type to search…

↑↓ navigate↵ selectEsc close