Skip to content

Home

solvOR logo

Solvor all your optimization needs.

solvOR is a pure Python optimization library designed for learning and experimentation. No numpy, no scipy, no compiled extensions. Each algorithm fits in one readable file you can study, modify, and extend.

Learn optimization by reading the code.

Build Status Docs codecov PyPI Downloads License: Apache 2.0 Python 3.12 | 3.13 | 3.14 uv Code style: ruff Typing: ty


Why solvOR?

  • Readable Code


    Every algorithm is implemented in clear, documented Python. No magic, no hidden complexity. Perfect for understanding how solvers actually work.

  • Educational First


    Designed for students and learners. Each solver includes Wikipedia links, complexity analysis, and practical tips. Learn the theory by reading working code.

  • Easy to Customize


    Want to add a custom heuristic? Modify the neighborhood function? Everything is accessible Python you can copy, tweak, and experiment with.

  • Practical Performance


    While not as fast as OR-Tools on large instances, solvOR handles real problems effectively. Solves Sudoku instantly, TSP-100 in seconds, and scales to thousands of variables for many problem types.


Quick Start

uv add solvor
from solvor import solve_lp

# Minimize 2x + 3y subject to x + y >= 4
result = solve_lp(c=[2, 3], A=[[-1, -1]], b=[-4])
print(result.solution)  # Optimal x, y
print(result.objective) # Minimum cost
from solvor import dijkstra

graph = {'A': [('B', 1), ('C', 4)], 'B': [('C', 2)], 'C': []}
result = dijkstra('A', 'C', lambda n: graph.get(n, []))
print(result.solution)  # ['A', 'B', 'C']
print(result.objective) # 3 (total distance)
from solvor import Model

m = Model()
x, y, z = [m.int_var(1, 9, name) for name in 'xyz']
m.add(m.all_different([x, y, z]))
m.add(x + y + z == 15)
result = m.solve()
print(result.solution)  # {'x': 3, 'y': 5, 'z': 7}
from solvor import solve_tsp

distances = [
    [0, 29, 20, 21],
    [29, 0, 15, 17],
    [20, 15, 0, 28],
    [21, 17, 28, 0]
]
result = solve_tsp(distances)
print(result.solution)  # Best tour found
print(result.objective) # Tour length

What's in the Box?

Category Algorithms Learn About
Linear Programming solve_lp, solve_milp Simplex method, branch and bound
Constraint Programming solve_sat, Model, solve_exact_cover SAT solving, Dancing Links
Metaheuristics anneal, tabu_search, lns, evolve Local search, genetic algorithms
Continuous Optimization adam, bfgs, nelder_mead, bayesian_opt Gradient descent, quasi-Newton methods
Graph Algorithms dijkstra, astar, bellman_ford, floyd_warshall Shortest paths, A* search
Graph Analysis topological_sort, scc, pagerank, louvain, kcore Dependency order, centrality, community detection
Network Flow max_flow, min_cost_flow, kruskal, prim Ford-Fulkerson, MST algorithms
Combinatorial solve_knapsack, solve_bin_pack, solve_job_shop Dynamic programming, scheduling
Assignment solve_hungarian, network_simplex Hungarian algorithm

Choosing an Algorithm

I need a provably optimal solution:

  • Linear constraints, continuous variables → solve_lp
  • Integer or binary variables → solve_milp
  • Boolean satisfiability → solve_sat
  • Complex constraints (all-different, etc.) → Model

A good solution quickly is fine:

Graph or network problem:

Full decision guide


  • Sudoku Solver


    Constraint programming with all_different. Classic puzzle, elegant solution.

  • Traveling Salesman


    Tabu search for TSP. See how local search escapes local optima.

  • Shortest Path Grid


    A* pathfinding on a 2D grid. Understand heuristics in action.

  • N-Queens


    Place N queens with no conflicts. A constraint satisfaction classic.

All cookbook examples · More examples


Philosophy

Design principles

  1. Working > perfect — Ship code that solves problems
  2. Readable > clever — Tomorrow-you needs to understand today-you's code
  3. Simple > general — Solve the problem at hand, not all possible problems

solvOR is not trying to compete with production solvers like OR-Tools, Gurobi, or CPLEX. It's designed to help you understand how these algorithms work, so you can make informed decisions about which tools to use and how to apply them.


Get Started Browse Examples API Reference