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.

Overview

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.

File-backed solvingexample/simple-api/

Load an MPS/LP file, set common parameters, run, and query results.

Programmatic modelingexample/model-api/

Build a small MIP from variables and bounded linear constraints.

Shared prepared modelexample/parallel-multiseed/

Run independent solver seeds in caller-owned threads without copying model data.

Warm starts--start_sol_path

Load partial .sol assignments with domain validation, or choose one of four built-in start methods.

Callbacksexample/*-callback/

Replace starts, restarts, weights, neighbors, and scoring behavior.

Pythonpython-bindings/*.py

Use the pybind11 module for file-based runs, Model API demos, and smoke tests.

Build and Run

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.

All-in-one

Build everything

./build.sh all
Example-only

Prepare and build demos

./build.sh release
cd example
./prepare.sh
./build.sh
Representative runs

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.

Example Map

Find the demo that matches the module

This map mirrors the strategy modules in Tutorials and points to runnable repository directories.

File-backed solving

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.

example/simple-api/simple_api.cpp
Programmatic modeling

Model API

Build a small MIP with Model_Builder, freeze it with prepare(), then solve it through Local_MIP(model).

example/model-api/python-bindings/model_api_demo.py
Caller-managed parallelism

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.

example/parallel-multiseed/Prepared_Model::from_file
Start module

Start Callback

Customize initial values before search begins. The demo accesses current values, binary variable indices, RNG, and optional user data.

example/start-callback/set_start_cbk
Restart module

Restart Callback

Customize restart behavior after stagnation, including current assignment perturbation and weight changes.

example/restart-callback/set_restart_cbk
Weighting module

Weight Callback

Customize constraint and objective weights. Use this when the default monotone or smooth behavior needs problem-specific changes.

example/weight-callback/set_weight_cbk
Neighbor generation

Neighbor Config

Reset or reorder the built-in neighbor list, tune BMS counts, and mix predefined operators with custom neighbors.

example/neighbor-config/clear_neighbor_listadd_neighbor
Stateful neighbor

Neighbor Userdata

Pass custom state into neighbor callbacks to collect statistics or make adaptive decisions across invocations.

example/neighbor-userdata/add_custom_neighbor
Neighbor scoring

Neighbor Scoring

Replace infeasible-phase move ranking with a custom scoring function and tie-breaking logic.

example/scoring-neighbor/set_neighbor_scoring_cbk
Lift scoring

Lift Scoring

Replace feasible-phase lift move ranking, for example to keep objective improvement while changing tie-breaking behavior.

example/scoring-lift/set_lift_scoring_cbk
Quick Recipes

Copy the small pattern, not the whole page

Simple API

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());
}
Model API

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();
Prepared Model

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();
Neighbor Config

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();
Python Demos

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.

File runpython-bindings/sample.py

Loads a bundled sample model, runs the solver, and writes py_example.sol.

Modelingpython-bindings/model_api_demo.py

Builds with lm.ModelBuilder, prepares the model, and solves it with lm.LocalMIP(model).

Parallel seedslm.PreparedModel

Shares frozen model data across independent Python workers; run() releases the GIL.

Smoke testspython-bindings/test_python_api.py

Covers parameter files, callback contexts, and exposed API methods.

Next Steps

Connect examples back to the docs