Metaheuristic optimization engine for routing, scheduling, timetabling and allocation — 24 ready-to-use models.
Maintained. Last release 3 days ago, commits in 5 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install optimaruREADME as published on PyPI with version 0.13.0.
optimaru
A metaheuristic optimization engine for real-world routing, scheduling, timetabling and allocation problems — with 24 ready-to-use models.
The solver core is C++17 and ships compiled in the wheel; you use it from Python. Every business rule and preference is a constraint plugin: switch it on or off, change its weight, make it hard or soft, or pick it several times with different settings — without touching the solver.
pip install optimaru
Requires Python 3.11+ (wheels for CPython 3.11–3.14) and pydantic 2.11+, which comes with the package. Wheels are published for Linux, macOS and Windows.
Every use case has two entry points: solve(problem, ...) for a problem built in Python, and solve_request(request) for a pydantic request (JSON in, JSON out), whose settings have the names of solve's keywords.
Example: vehicle routing
from optimaru import vehicle_routing as vrp
from optimaru.vehicle_routing.constraints import (
TravelTimeCost, UnassignedVisitsCost, VehicleCapacityCost, get_constraints,
)
locations = [vrp.Location(37.5665, 126.9780)] # 0: depot
visits = []
for i, (lat, lon) in enumerate([(37.5700, 126.9820), (37.5512, 126.9882), (37.5133, 127.1001)]):
locations.append(vrp.Location(lat, lon))
# id name location demand ready due service (s)
visits.append(vrp.Visit(f"C{i}", f"Customer {i}", i + 1, 2, 8 * 3600, 20 * 3600, 600))
vehicles = [vrp.Vehicle("V1", 6, 0, departure_time=7 * 3600)]
plan = vrp.VehicleRoutePlan("demo", locations, vehicles, visits)
config = vrp.SolverConfig()
config.stop.time_limit_seconds = 2
solver = vrp.Solver(config)
solver.solve(plan) # default constraints
print(plan.score, plan.routes())
# Pick constraints and reweight them — the solver itself does not change.
# Only the listed constraints are scored: leave out UnassignedVisitsCost() and
# skipping every visit becomes free.
solver.solve_with_constraints(plan, get_constraints([
VehicleCapacityCost(),
UnassignedVisitsCost(),
TravelTimeCost(weight=10),
]))
print(plan.score, plan.routes())
# Pick one constraint twice: every driving second, plus the square of the
# seconds a route drives beyond 10 minutes.
solver.solve_with_constraints(plan, get_constraints([
VehicleCapacityCost(),
UnassignedVisitsCost(),
TravelTimeCost(),
TravelTimeCost(exponent=2, offset=600),
]))
print(plan.score, plan.routes())