Runnable Examples
Example Gallery
Use the repository demos as small, isolated references for file-based solving, in-memory modeling, shared-model multi-seed runs, callback hooks, neighbor configuration, and custom scoring.
One demo per extension point
The solver repository keeps C++ examples under example/ and Python demos under python-bindings/. Each demo focuses on one public interface so it can be copied into experiments with minimal context.
example/simple-api/Load an MPS/LP file, set common parameters, run, and query results.
example/model-api/Build a small MIP from variables and bounded linear constraints.
example/parallel-multiseed/Run independent solver seeds in caller-owned threads without copying model data.
--start_sol_pathLoad partial .sol assignments with domain validation, or choose one of four built-in start methods.
example/*-callback/Replace starts, restarts, weights, neighbors, and scoring behavior.
python-bindings/*.pyUse the pybind11 module for file-based runs, Model API demos, and smoke tests.
Prepare examples from the solver root
Use ./build.sh all from the solver root when you want the core library, examples, and Python bindings prepared together. The local bindings step expects CPython 3.8-3.12 and pybind11>=2.10,<3. For the example-only path, build the core library first, then prepare and compile the C++ demos.
Build everything
./build.sh all
Prepare and build demos
./build.sh release
cd example
./prepare.sh
./build.sh
Run a short demo first
cd example
./model-api/model_api_demo
Run these commands from the solver repository root. The in-memory Model API demo finishes quickly; file-backed demos resolve the bundled sample instance and use their source-defined time limits, often 30-60 seconds. Pass a custom model path as argv[1] when needed.
Find the demo that matches the module
This map mirrors the strategy modules in Tutorials and points to runnable repository directories.
Simple API
Minimal C++ flow: create Local_MIP, set a model file, set a time limit and output path, run, then query feasibility and objective value.
Model API
Build a small MIP with Model_Builder, freeze it with prepare(), then solve it through Local_MIP(model).
Parallel Multi-seed
Prepare one immutable model, create independent solver instances with different seeds, run them in application-owned threads, and select the best finite feasible objective.
Start Callback
Customize initial values before search begins. The demo accesses current values, binary variable indices, RNG, and optional user data.
Restart Callback
Customize restart behavior after stagnation, including current assignment perturbation and weight changes.
Weight Callback
Customize constraint and objective weights. Use this when the default monotone or smooth behavior needs problem-specific changes.
Neighbor Config
Reset or reorder the built-in neighbor list, tune BMS counts, and mix predefined operators with custom neighbors.
Neighbor Userdata
Pass custom state into neighbor callbacks to collect statistics or make adaptive decisions across invocations.
Neighbor Scoring
Replace infeasible-phase move ranking with a custom scoring function and tie-breaking logic.
Lift Scoring
Replace feasible-phase lift move ranking, for example to keep objective improvement while changing tie-breaking behavior.
Copy the small pattern, not the whole page
File-backed C++ solve
Local_MIP solver;
solver.set_model_file("test-set/2club200v15p5scn.mps");
solver.set_sol_path("example_simple.sol");
solver.set_time_limit(10.0);
solver.set_log_obj(true);
solver.run();
if (solver.is_feasible()) {
printf("Objective value: %.10f\n", solver.get_obj_value());
}
Range constraints in memory
Model_Builder builder;
const double inf = std::numeric_limits<double>::infinity();
builder.set_sense(Model_Builder::Sense::maximize);
int x1 = builder.add_var("x1", 0.0, 40.0, 1.0, Var_Type::real);
int x4 = builder.add_var("x4", 2.0, 3.0, 1.0, Var_Type::general_integer);
builder.add_con(-inf, 20.0,
std::vector<int>{x1, x4},
std::vector<double>{-1.0, 10.0});
auto model = builder.prepare();
Local_MIP solver(model);
solver.run();
Independent solver seeds
Model_Prepare_Options options;
auto model = Prepared_Model::from_file("instance.mps", options);
Local_MIP seed_1(model);
Local_MIP seed_2(model);
seed_1.set_random_seed(1);
seed_2.set_random_seed(2);
std::thread first([&] { seed_1.run(); });
std::thread second([&] { seed_2.run(); });
first.join();
second.join();
Change the neighbor list
Local_MIP solver;
solver.clear_neighbor_list();
solver.add_custom_neighbor("my_random_flip", my_random_flip_neighbor);
solver.add_neighbor("unsat_mtm_bm", 12, 8);
solver.add_neighbor("flip", 0, 12);
solver.add_custom_neighbor("my_gradient_descent", my_gradient_descent_neighbor);
solver.set_model_file("test-set/2club200v15p5scn.mps");
solver.set_time_limit(10.0);
solver.run();
Use the pybind11 module when scripting
The Python bindings expose core configuration, result queries, parameter-file loading, model builders, prepared models, and structured callback contexts. For a venv-safe install command, start from Quick Start.
python-bindings/sample.pyLoads a bundled sample model, runs the solver, and writes py_example.sol.
python-bindings/model_api_demo.pyBuilds with lm.ModelBuilder, prepares the model, and solves it with lm.LocalMIP(model).
lm.PreparedModelShares frozen model data across independent Python workers; run() releases the GIL.
python-bindings/test_python_api.pyCovers parameter files, callback contexts, and exposed API methods.