Solvers#
The Routing library provides multiple solver backends for different needs.
Overview#
Category |
Solvers |
Best For |
|---|---|---|
Metaheuristics |
GA, MA, VNS, PSO, LS, ALNS |
Large instances, fast approximations |
MIP |
CPLEX, HiGHS |
Proven optimality, small-medium instances |
CP |
CPLEX CP Optimizer, OR-Tools, XCSP3 |
Complex constraints, scheduling |
Metaheuristics#
Fast, scalable solvers for large instances where optimal solutions aren’t required.
Solver |
Name |
Description |
|---|---|---|
GA |
|
Genetic Algorithm - good balance of quality and speed |
MA |
|
Memetic Algorithm - GA with local search intensification |
VNS |
|
Variable Neighborhood Search - systematic local search |
PSO |
|
Particle Swarm Optimization - swarm-based metaheuristic |
LS |
|
Local Search - fast improvement heuristic |
ALNS |
|
Adaptive Large Neighborhood Search - multi-destroy/repair with adaptive weights |
Parameters#
Iteration Budget#
Parameter |
Type |
Applies To |
Description |
|---|---|---|---|
|
int |
GA, MA, VNS, PSO, ALNS |
Maximum iterations for main loop |
GA/MA Feasibility Controls#
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
bool |
|
Enforce feasibility during decoding |
|
float |
|
Penalty weight for infeasible solutions |
|
float |
|
Penalty per unserved client |
ALNS Adaptive Parameters#
ALNS uses adaptive operator selection that learns which destroy/repair combinations work best during search.
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
float |
|
Weight update reaction factor (0-1) |
|
float |
|
Weight decay factor per segment (0-1) |
|
float |
|
Initial temperature for simulated annealing |
|
float |
|
Temperature cooling rate per iteration |
|
int |
|
Iterations between weight updates |
|
float |
|
Minimum temperature for acceptance |
ALNS Destroy Operators:
RandomRemoval: Removes random subset of clients (configurable fraction)
WorstRemoval: Removes clients with highest cost impact (with randomness)
ShawRemoval: Removes similar clients (based on distance, demand, time windows)
RouteRemoval: Removes entire routes from solution
ALNS Repair Operators:
GreedyRepair: Re-inserts clients using greedy best-insertion
RegretRepair: Re-inserts using regret-k heuristic (balances multiple good positions)
RandomRepair: Randomly re-inserts clients
Examples#
GA Example#
import routing
from routing.constants import Attribute
routing.init()
problem = routing.Problem()
# ... add entities with attributes ...
solution = routing.solve(problem, "ga", timeout=60)
print(f"Cost: {solution.cost:.2f}")
ALNS Example#
solution = routing.solve(problem, "alns", timeout=60)
print(f"Cost: {solution.cost:.2f}")
MIP (Mixed-Integer Programming)#
Exact methods that can prove optimality for small-medium instances.
Solver |
Name |
Backend |
License |
|---|---|---|---|
CPLEX MIP |
|
IBM CPLEX |
Commercial |
HiGHS MIP |
|
HiGHS |
Open-source (MIT) |
Example#
# Open-source MIP solver
solution = routing.solve(problem, "mip/highs", timeout=300)
if solution:
print(f"Cost: {solution.cost:.2f}")
CP (Constraint Programming)#
Powerful for problems with complex constraints like time windows and precedences.
Solver |
Name |
Backend |
License |
|---|---|---|---|
CPLEX CP |
|
IBM CP Optimizer |
Commercial |
OR-Tools |
|
Google OR-Tools CP-SAT |
Open-source (Apache 2.0) |
XCSP3 |
|
Open standard |
XCSP3 Integration#
XCSP3 - XML-based CP Format
XCSP3 is an XML-based format for representing constraint satisfaction and optimization problems. The Routing library can:
Export problems to XCSP3 format for use with any XCSP3-compatible solver
Solve using external XCSP3 solvers like ACE, Choco, or PicatSAT
This enables interoperability with broader constraint programming ecosystem.
Key Benefits of XCSP3:
Solver Independence: Export once, solve with any XCSP3 solver
Benchmarking: Compare different CP solvers on same model
Research: Standard format for academic publications
Competitions: Official format for XCSP competitions
Example: Export to XCSP3#
solver = routing.create_solver("cp/ace", problem)
solver.export_model("routing_problem.xml")
Example: OR-Tools CP-SAT#
solution = routing.solve(problem, "cp/ortools", timeout=120)
print(f"Cost: {solution.cost:.2f}")
Solver Selection Guide#
Quick Recommendations#
Scenario |
Recommended Solver |
|---|---|
Quick solution needed |
|
Best quality, large instance |
|
Adaptive exploration of neighborhoods |
|
Proven optimality needed |
|
Complex time windows |
|
Benchmarking/Research |
|
Open-source only |
|
ALNS vs Other Metaheuristics#
Aspect |
ALNS |
GA/MA/PSO |
VNS |
|---|---|---|---|
Neighborhood Exploration |
Multiple adaptive |
Population-based |
Systematic |
Diversification |
Destroy operators |
Crossover/mutation |
Shaking |
Intensification |
Repair operators |
Selection/local search |
Best improvement |
Adaptivity |
Dynamic operator weights |
Parameter tuning |
Fixed |
Best For |
Rich neighborhood structure |
Diverse solutions |
Local improvement |
Complexity |
Medium |
Low-Medium |
Low |
See Also#
Installation - Installing solver backends
Benchmarks - Performance comparisons
XCSP3 Website - Official XCSP3 documentation