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.

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.

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. For the example-only path, build the core library first, then prepare and compile the 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 in memory with objective sense, variables, bounds, constraint ranges, integrality, and solution queries.

example/model-api/python-bindings/model_api_demo.py
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

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();
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 API methods, 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

Mirrors the C++ Model API demo using lm.LocalMIP, lm.Sense, and lm.VarType.

Smoke testspython-bindings/test_python_api.py

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

Next Steps

Connect examples back to the docs