cpbenchy run instances/ -s ortools -t 60 -p cpbenchy.observers:XCSP3Output- Version
- cpbenchy 0.1.0.dev0
- Last updated
- 6 Oct 2026 · 1 commit
- Authors
- ThomSerg
- Formats
- xcsp3
- Requires
- pycsp3, to read XCSP3; java, for the official checker
- Homepage
- xcsp.org/competitions
- Tags
- xcsp3competitionoutput
What it does
Writes what a solver in the XCSP3 competition prints, for each run on
an XCSP3 instance, with the solution as an XML <instantiation> of the instance’s variables:
o 12
o 9
s OPTIMUM FOUND
v <instantiation type="optimum" cost="9">
v <list>x[0] x[1] x[2] y</list>
v <values>2 1 0 3</values>
v </instantiation>Each competition specifies what a solver prints:
olines with each better objective value, while it solves- an
sline with its answer:OPTIMUM FOUND,SATISFIABLE,UNSATISFIABLEorUNKNOWN vlines with the solution
The output goes to each run’s logs/<run_id>.xcsp3.out, written inside the measured run, as a
competition solver would print it, so it costs the run the time it would cost in the competition. A run
that is killed keeps its o lines. Under cpbenchy solve, the output goes to stdout,
where competitions read it.
Given the competition’s solution checker, it also checks every solution with it, after the run and outside its measured time.
Use it
import cpbenchy
from cpbenchy import observers
cpbenchy.run("xcsp3/", solvers=["ortools"], time_limit=60, plugins=[observers.XCSP3Output()])
cpbenchy.run("xcsp3/", solvers=["ortools"], time_limit=60, plugins=[observers.XCSP3Output(checker="checker.jar")])cpbenchy run xcsp3/ -s ortools -t 60 -p cpbenchy.observers:XCSP3Output
cpbenchy run xcsp3/ -s ortools -t 60 -p "cpbenchy.observers:XCSP3Output(checker='checker.jar')"The XCSP3 rules enable it, with the competition’s limits.
Options
| Argument | |
|---|---|
checker |
path of the XCSP3 solution checker jar; needs java. Default: no check |
What it records
logs/<run_id>.xcsp3.out |
the competition output |
extra["xcsp3_check"] |
with a checker: "OK", or what the checker says is wrong |
Implementation
The XCSP3Output in src/cpbenchy/observers.py, lines 74–92 of 222, as of this version of the docs.
class XCSP3Output(CompetitionOutput):
"""XCSP3 competition output. With `checker` (the path of the competition's checker jar, needs java),
the parent also checks every solution after its run, outside the measured time, and records the
verdict as `extra["xcsp3_check"]`: "OK", or what is wrong."""
name = "xcsp3"
formats = ("xcsp3",)
def __init__(self, checker=None):
self.checker = checker
def solution(self, ctx):
cost = ctx.objective if ctx.model.has_objective() else None
return fmt.xcsp3_instantiation(fmt.instance_variables(ctx.model), cost).splitlines()
def on_result(self, run, result):
output = self.output(run)
if self.checker and result.status in ("optimal", "feasible") and output.exists():
result.extra["xcsp3_check"] = xcsp3_check(self.checker, run.spec.instance.path, output)Related
- CompetitionOutputThe starting point for the output of another competition: you describe the solution, the rest is done.
- xcsp3-2025Run as in the XCSP3 Competition 2025: its time and memory limits, its output.
- CheckSolutionsCatches wrong answers: every solution is checked against the model, and a wrong one counts as an error.