cbc 2.10.13
Overview
Cbc (Coin-or Branch and Cut) is an open-source mixed-integer linear programming (MILP) solver written in C++. It implements branch-and-cut with configurable cut generators, heuristics, branching rules, and node selection strategies. It can be used as:
- Standalone CLI tool —
cbc executable reads MPS/LP files and solves interactively
- C API —
#include <Cbc_C_Interface.h> for C programs
- C++ API —
#include <CbcModel.hpp> for full control
- OsiSolverInterface —
#include <OsiCbcSolverInterface.hpp> as a drop-in LP solver replacement
Key capabilities: branch-and-bound with cuts (Gomory, clique, cover, probing, MIR), primal heuristics (rounding, feasibility pump, diving), SOS1/SOS2 constraints, solution pools, MIP start, parallel solving (multi-threaded and multi-process), custom cut callbacks, event handlers, and AMPL/GAMS interfaces.
Usage
CLI
# Solve an MPS file
cbc model.mps
# Interactive mode with parameters
cbc model.mps -solve -quit
# With time limit and other options
cbc model.mps -timeLimit 300 -logLevel 2 -solve -quit
# Read from stdin
cat model.lp | cbc -stdin
C API (minimal)
#include <Cbc_C_Interface.h>
Cbc_Model *model = Cbc_newModel();
Cbc_readMps(model, "model.mps");
Cbc_setMaximumSeconds(model, 300);
Cbc_solve(model);
if (Cbc_isProvenOptimal(model)) {
double obj = Cbc_getObjValue(model);
const double *sol = Cbc_getColSolution(model);
}
Cbc_deleteModel(model);
C++ API (minimal)
#include <OsiClpSolverInterface.hpp>
#include <CbcModel.hpp>
OsiClpSolverInterface solver;
solver.readMps("model.mps");
CbcModel model(solver);
model.branchAndBound();
if (!model.status()) { // 0 = finished
double obj = model.getObjValue();
const double *sol = model.bestSolution();
}
C++ API with CbcMain (full standalone solver features)
#include <OsiClpSolverInterface.hpp>
#include <CbcModel.hpp>
#include <CbcSolver.hpp>
OsiClpSolverInterface solver;
solver.readMps("model.mps");
CbcModel model(solver);
CbcMain0(model); // Initialize with default parameters
const char *args[] = { "prog", "-solve", "-quit" };
CbcMain1(3, args, model);
OsiCbcSolverInterface (drop-in solver)
#include <OsiCbcSolverInterface.hpp>
OsiCbcSolverInterface solver;
solver.readMps("model.mps");
solver.initialSolve();
solver.branchAndBound();
Gotchas
- Do not reuse a
CbcModel for multiple solves — Cbc_solve() and branchAndBound() mutate internal state. Clone the model with Cbc_clone() or create a new one.
CbcMain0 must be called before CbcMain1 — CbcMain0 initializes default parameters; skipping it means no cut generators, heuristics, or strategy setup.
- Model access methods are invalid after solving —
getColLower(), setObjCoeff(), etc. are not valid after Cbc_solve() or branchAndBound(). Read all data before solving, or clone first.
- Solution from solver vs model — After
CbcMain1, the solver is cloned internally. Use model.solver()->getColSolution() (current solver) or model.bestSolution() (best integer solution found).
- Preprocessing loses original variable mapping — If using
CglPreProcess, post-process with process.postProcess(*solver) to map solutions back to original variables.
OsiCbcSolverInterface wraps Cbc inside Osi — It works as a drop-in replacement for any Osi-based code, but gives less fine-grained control than CbcModel.
- Parallel solving requires
CBC_THREAD define — Multi-threaded branch-and-bound needs the library compiled with pthread support. Use -threads N CLI flag or model.setNumberThreads(N) in C++.
- Status codes need secondary status check —
status() == 0 means "finished" but could be optimal or infeasible. Check isProvenOptimal() or secondaryStatus() to distinguish.
- Cut generators must outlive the model — When adding cut generators with
model.addCutGenerator(&gen, ...), the pointer is stored. Do not let the generator go out of scope during solving. Use heap allocation (new) for safety.
- AMPL interface needs ASL library — The AMPL/GMPL interface requires the Ampl Solver Library (ASL). Build with
ThirdParty-ASL via coinbrew or install separately.
References
- 01-installation — Dependencies, building from source, package managers, coinbrew
- 02-cli-reference — Full CLI parameter reference and interactive shell
- 03-c-api — C API functions, model creation, solving, solution retrieval
- 04-cpp-api-basics — CbcModel, OsiCbcSolverInterface, basic solve patterns
- 05-cpp-api-advanced — Cut generators, heuristics, branching, callbacks, event handlers
- 06-modeling-integration — PuLP, cvxpy, Pyomo, JuMP, MiniZinc, AMPL, GAMS
- 07-python-usage — Detailed Python usage: PuLP, cvxpy, Pyomo, OR-Tools, python-mip, yaposib, subprocess patterns
1---2name: cbc-2-10-133description: COIN-OR Cbc (Coin-or Branch and Cut) 2.10.13 — open-source MILP solver. Use this skill whenever the user needs to solve mixed-integer linear programs, integer programming, MIP, branch-and-cut, branch-and-bound, or any optimization problem with discrete/integer variables. Covers CLI usage (`cbc` executable), C API (`Cbc_C_Interface.h`), and C++ API (`CbcModel`, `OsiCbcSolverInterface`). Also covers cut generators, heuristics, custom branching, event handlers, callbacks, SOS constraints, solution pools, parallel solving, AMPL interface, and integration with modeling languages (PuLP, cvxpy, Pyomo, JuMP, MiniZinc). Trigger on: MILP, MIP solver, branch-and-cut, integer programming, Cbc solver, COIN-OR optimization, mixed-integer optimization.4---56# cbc 2.10.1378## Overview910Cbc (Coin-or Branch and Cut) is an open-source mixed-integer linear programming (MILP) solver written in C++. It implements branch-and-cut with configurable cut generators, heuristics, branching rules, and node selection strategies. It can be used as:11121. **Standalone CLI tool** — `cbc` executable reads MPS/LP files and solves interactively132. **C API** — `#include <Cbc_C_Interface.h>` for C programs143. **C++ API** — `#include <CbcModel.hpp>` for full control154. **OsiSolverInterface** — `#include <OsiCbcSolverInterface.hpp>` as a drop-in LP solver replacement1617Key capabilities: branch-and-bound with cuts (Gomory, clique, cover, probing, MIR), primal heuristics (rounding, feasibility pump, diving), SOS1/SOS2 constraints, solution pools, MIP start, parallel solving (multi-threaded and multi-process), custom cut callbacks, event handlers, and AMPL/GAMS interfaces.1819## Usage2021### CLI2223```bash24# Solve an MPS file25cbc model.mps2627# Interactive mode with parameters28cbc model.mps -solve -quit2930# With time limit and other options31cbc model.mps -timeLimit 300 -logLevel 2 -solve -quit3233# Read from stdin34cat model.lp | cbc -stdin35```3637### C API (minimal)3839```c40#include <Cbc_C_Interface.h>4142Cbc_Model *model = Cbc_newModel();43Cbc_readMps(model, "model.mps");44Cbc_setMaximumSeconds(model, 300);45Cbc_solve(model);4647if (Cbc_isProvenOptimal(model)) {48 double obj = Cbc_getObjValue(model);49 const double *sol = Cbc_getColSolution(model);50}51Cbc_deleteModel(model);52```5354### C++ API (minimal)5556```cpp57#include <OsiClpSolverInterface.hpp>58#include <CbcModel.hpp>5960OsiClpSolverInterface solver;61solver.readMps("model.mps");62CbcModel model(solver);63model.branchAndBound();6465if (!model.status()) { // 0 = finished66 double obj = model.getObjValue();67 const double *sol = model.bestSolution();68}69```7071### C++ API with CbcMain (full standalone solver features)7273```cpp74#include <OsiClpSolverInterface.hpp>75#include <CbcModel.hpp>76#include <CbcSolver.hpp>7778OsiClpSolverInterface solver;79solver.readMps("model.mps");80CbcModel model(solver);81CbcMain0(model); // Initialize with default parameters82const char *args[] = { "prog", "-solve", "-quit" };83CbcMain1(3, args, model);84```8586### OsiCbcSolverInterface (drop-in solver)8788```cpp89#include <OsiCbcSolverInterface.hpp>9091OsiCbcSolverInterface solver;92solver.readMps("model.mps");93solver.initialSolve();94solver.branchAndBound();95```9697## Gotchas9899- **Do not reuse a `CbcModel` for multiple solves** — `Cbc_solve()` and `branchAndBound()` mutate internal state. Clone the model with `Cbc_clone()` or create a new one.100- **`CbcMain0` must be called before `CbcMain1`** — `CbcMain0` initializes default parameters; skipping it means no cut generators, heuristics, or strategy setup.101- **Model access methods are invalid after solving** — `getColLower()`, `setObjCoeff()`, etc. are not valid after `Cbc_solve()` or `branchAndBound()`. Read all data before solving, or clone first.102- **Solution from solver vs model** — After `CbcMain1`, the solver is cloned internally. Use `model.solver()->getColSolution()` (current solver) or `model.bestSolution()` (best integer solution found).103- **Preprocessing loses original variable mapping** — If using `CglPreProcess`, post-process with `process.postProcess(*solver)` to map solutions back to original variables.104- **`OsiCbcSolverInterface` wraps Cbc inside Osi** — It works as a drop-in replacement for any Osi-based code, but gives less fine-grained control than `CbcModel`.105- **Parallel solving requires `CBC_THREAD` define** — Multi-threaded branch-and-bound needs the library compiled with pthread support. Use `-threads N` CLI flag or `model.setNumberThreads(N)` in C++.106- **Status codes need secondary status check** — `status() == 0` means "finished" but could be optimal or infeasible. Check `isProvenOptimal()` or `secondaryStatus()` to distinguish.107- **Cut generators must outlive the model** — When adding cut generators with `model.addCutGenerator(&gen, ...)`, the pointer is stored. Do not let the generator go out of scope during solving. Use heap allocation (`new`) for safety.108- **AMPL interface needs ASL library** — The AMPL/GMPL interface requires the Ampl Solver Library (ASL). Build with `ThirdParty-ASL` via coinbrew or install separately.109110## References111112- [01-installation](references/01-installation.md) — Dependencies, building from source, package managers, coinbrew113- [02-cli-reference](references/02-cli-reference.md) — Full CLI parameter reference and interactive shell114- [03-c-api](references/03-c-api.md) — C API functions, model creation, solving, solution retrieval115- [04-cpp-api-basics](references/04-cpp-api-basics.md) — CbcModel, OsiCbcSolverInterface, basic solve patterns116- [05-cpp-api-advanced](references/05-cpp-api-advanced.md) — Cut generators, heuristics, branching, callbacks, event handlers117- [06-modeling-integration](references/06-modeling-integration.md) — PuLP, cvxpy, Pyomo, JuMP, MiniZinc, AMPL, GAMS118- [07-python-usage](references/07-python-usage.md) — Detailed Python usage: PuLP, cvxpy, Pyomo, OR-Tools, python-mip, yaposib, subprocess patterns