Examples
Runnable Examples
Example Gallery
Use the repository demos as small, isolated references for file-based solving, in-memory modeling, 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/*-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. For the example-only path, build the core library first, then prepare and compile the 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 in memory with objective sense, variables, bounds, constraint ranges, integrality, and solution queries.
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
Local_MIP solver;
const double inf = std::numeric_limits<double>::infinity();
solver.enable_model_api();
solver.set_sense(Model_API::Sense::maximize);
int x1 = solver.add_var("x1", 0.0, 40.0, 1.0, Var_Type::real);
int x4 = solver.add_var("x4", 2.0, 3.0, 1.0, Var_Type::general_integer);
solver.add_con(-inf, 20.0,
std::vector<int>{x1, x4},
std::vector<double>{-1.0, 10.0});
solver.run();
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 API methods, 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.pyMirrors the C++ Model API demo using lm.LocalMIP, lm.Sense, and lm.VarType.
python-bindings/test_python_api.pyCovers parameter files, callback contexts, and exposed API methods.