Quick reference¶
How to call cbls, as a command or a library, and what it prints.
Terminal¶
# Build the C++ CLI, ./build/cbls, from a clone
git clone https://github.com/spoorendonk/cbls && cd cbls
cmake -B build
cmake --build build -j4
# Install for Python: import cbls, and the cbls command (needs a C++17 compiler and zlib)
pip install git+https://github.com/spoorendonk/cbls
# Solve a file: .cbls, .mps, .mps.gz or .nl (also python -m cbls; ./build/cbls: .cbls only)
cbls examples/simple.cbls --time-limit 1
# Every option and default, and the exit status (the same for python -m cbls and ./build/cbls)
cbls --help
A MINLPLib .nl file (st_e38, a pressure-vessel design, optimum 7197.727149)
and a MIPLIB .mps.gz file (neos5, 63 columns), from a clone’s root; the
test suite runs both lines:
cbls benchmarks/instances/minlplib/st_e38.nl --time-limit 2 --threads 1 --seed 42 --quiet
cbls benchmarks/instances/miplib-fj/neos5.mps.gz --time-limit 2 --threads 1 --seed 42 --format jsonl --quiet
Output.
--format human: progress rows (*on a new best), thenStatus:,Objective:,Time:andSolution:lines.--format jsonl: one JSON object per line,start,progress, thenresultwithstatus,feasible,objective(null when none),termination,time,iterationsandsolution(its names sorted as text:d1,d10,d11, …).Exit status. 0 when a feasible point was found; 1 when not, and on a bad argument or model file (the message on stderr).
Python¶
import cbls
# Build a model and solve it, any option as a keyword
m = cbls.Model()
x, y = m.Int(0, 10, "x"), m.Float(0, 10, "y")
m.add_constraint(x + y >= 3)
m.minimize(x * x + y)
m.close()
result = cbls.solve(m, time_limit=1, seed=42, threads=1)
print(result.feasible, result.objective, result.value(x))
# Load a file, one loader per format (paths from a clone's root)
model = cbls.load_model("examples/simple.cbls")
converted = cbls.nl_to_model(cbls.read_nl("benchmarks/instances/minlplib/st_e38.nl"))
# converted = cbls.mps_to_model(cbls.read_mps("benchmarks/instances/miplib-fj/neos5.mps.gz"))
result = cbls.solve(converted.model, time_limit=2)
print(result.feasible, converted.original_values()) # one value per file column
.nlfiles. Solve one only ifconverted.supported; elseconverted.skipped_reasonsnames the operators cbls does not model. A maximisation keeps its sense inresult.objective;result.search.objectiveis the engine’s minimised value..mpsfiles. Infinite bounds are derived from the rows where they can be, else clamped to 1e9, which can cut off solutions (converted.n_clamped_columnscounts them).OBJSENSE MAXis refused: negate the costs.Whole programs that solve a file and verify the point independently:
examples/minlplib.py,examples/mip.py, and their C++ versions beside them.
C++¶
Link the target cbls::cbls: the C++ reference has the CMake file.
Reference: C++, Python; all the docs as text: https://spoorendonk.dk/cbls/llms.txt, https://spoorendonk.dk/cbls/llms-full.txt.