Solvor all your optimization needs. What's in the box? Category | Solvors | Use Case | Linear/Integer | solvelp, solvelpinterior, solvemilp, MilpModel, solvelexicographic, solvecg, solvebp | Resource allocation, cutting stock, multi-objective | Constraint | solvesat, Model | Sudoku, puzzles, and that one config problem that's been bugging you | Combinatorial | solveknapsack, solvebinpack, solvejobshop, solvevrptw |…
Optimization solvers in pure Python: LP, MILP, SAT, constraint programming, graph and metaheuristics. No dependencies. Solvor all your optimization needs.
For “is this configuration valid?” problems. Dependencies, exclusions, implications - anything that boils down to boolean constraints.
# (x1 OR x2) AND (NOT x1 OR x3) AND (NOT x2 OR NOT x3)
result = solve_sat([[1, 2], [-1, 3], [-2, -3]])
print(result.solution) # {1: True, 2: False, 3: True}
Model
Constraint programming for puzzles and scheduling with “all different”, arithmetic, and logical constraints. Sudoku, N-Queens, timetabling.
m = Model()
cells = [[m.int_var(1, 9, f'c{i}{j}') for j in range(9)] for i in range(9)]
# All different in each row
for row in cells:
m.add(m.all_different(row))
result = m.solve()
Metaheuristics
anneal
Simulated annealing, sometimes you have to go downhill to find a higher peak.
result = anneal(
initial=initial_solution,
objective_fn=cost_function,
neighbors=random_neighbor,
temperature=1000,
cooling=0.9995
)
tabu_search
Greedy local search with a “don’t go back there” list. Simple but surprisingly effective.
Large Neighborhood Search, destroy part of your solution and rebuild it better. ALNS learns which operators work best.
result = lns(initial, objective_fn, destroy_ops, repair_ops, max_iter=1000)
result = alns(initial, objective_fn, destroy_ops, repair_ops, max_iter=1000) # adaptive
evolve / differential_evolution / particle_swarm
Population-based global search. Let a swarm of candidates explore for you. DE and PSO work on continuous spaces.
result = evolve(objective_fn=fitness, population=pop, crossover=cx, mutate=mut)
result = differential_evolution(objective_fn, bounds=[(0, 10)] * n, population_size=50)
result = particle_swarm(objective_fn, bounds=[(0, 10)] * n, n_particles=30)
Continuous Optimization
Gradient-Based
gradient_descent, momentum, rmsprop, adam - follow the slope. Adam adapts learning rates per parameter.
def grad_fn(x):
return [2 * x[0], 2 * x[1]] # gradient of x^2 + y^2
result = adam(grad_fn, x0=[5.0, 5.0])
result = bfgs(objective_fn, grad_fn, x0=[5.0, 5.0])
result = lbfgs(objective_fn, grad_fn, x0=[5.0, 5.0], memory=10)
Derivative-Free
nelder_mead, powell - no gradients needed. Good for noisy, non-smooth, or “I have no idea what this function looks like” situations.
result = nelder_mead(objective_fn, x0=[5.0, 5.0])
result = powell(objective_fn, x0=[5.0, 5.0])
bayesian_opt
When each evaluation is expensive. Builds a surrogate model to sample intelligently. Perfect for hyperparameter tuning or when your simulation takes 10 minutes per run.
result = bayesian_opt(expensive_fn, bounds=[(0, 1), (0, 1)], max_iter=30)
Pathfinding
bfs / dfs
Unweighted graph traversal. BFS finds shortest paths (fewest edges), DFS explores depth-first. Both work with any state type and neighbor function.
# Find shortest path in a grid
def neighbors(pos):
x, y = pos
return [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]
result = bfs(start=(0, 0), goal=(5, 5), neighbors=neighbors)
print(result.solution) # path from start to goal
dijkstra
Weighted shortest paths. Classic algorithm for when edges have costs. Stops early when goal is found.
Optimal one-to-one matching. solve_hungarian is O(n³), direct algorithm for assignment problems.
costs = [
[10, 5, 13],
[3, 9, 18],
[10, 6, 12]
]
result = solve_hungarian(costs)
# result.solution[i] = column assigned to row i
# result.objective = total cost
# For maximization
result = solve_hungarian(costs, minimize=False)
Exact Cover
solve_exact_cover
For “place these pieces without overlap” problems. Sudoku, pentomino tiling, N-Queens, or any puzzle where you stare at a grid wondering why nothing fits.
Result(
solution, # best solution found
objective, # objective value
iterations, # solver iterations (pivots, generations, etc.)
evaluations, # function evaluations
status, # OPTIMAL, FEASIBLE, INFEASIBLE, UNBOUNDED, MAX_ITER
error, # error message if failed (None on success)
solutions, # multiple solutions when solution_limit > 1
)
When to use what?
Problem
Solvor
Linear constraints, continuous
solve_lp, solve_lp_interior
Linear constraints, integers
solve_milp
Cutting stock, crew scheduling
solve_cg, solve_bp
Boolean satisfiability
solve_sat
Discrete vars, complex constraints
Model
Knapsack, subset selection
solve_knapsack
Bin packing
solve_bin_pack
Job shop scheduling
solve_job_shop
Vehicle routing
solve_vrptw
Combinatorial, local search
tabu_search, anneal
Combinatorial, destroy-repair
lns, alns
Global search, continuous
differential_evolution, particle_swarm
Global search, discrete
evolve
Smooth, differentiable, fast
bfgs, lbfgs
Smooth, differentiable, ML
adam, rmsprop
Non-smooth, no gradients
nelder_mead, powell
Expensive black-box
bayesian_opt
Shortest path, unweighted
bfs, dfs
Shortest path, weighted
dijkstra, astar
Shortest path, negative weights
bellman_ford
All-pairs shortest paths
floyd_warshall
Minimum spanning tree
kruskal, prim
Dependency ordering
topological_sort
Circular dependencies
strongly_connected_components
Node importance
pagerank
Community detection
louvain
Single points of failure
articulation_points, bridges
Core vs periphery
kcore_decomposition
Maximum flow
max_flow
Min-cost flow
min_cost_flow, network_simplex
Assignment, matching
solve_hungarian, solve_assignment
Exact cover, tiling
solve_exact_cover
Performance
Have your cake and eat it too. solvOR gives you both:
Readable Python - Every algorithm is implemented in clear, documented Python you can study and modify
Rust Performance - Optional drop-in Rust backends with 3-100x speedup for compute-heavy algorithms
from solvor import floyd_warshall
# "auto" (default) - Uses Rust if available, falls back to Python
result = floyd_warshall(n_nodes, edges)
# "python" - Force pure Python (for learning, debugging, or extending)
result = floyd_warshall(n_nodes, edges, backend="python")
Pre-built wheels include Rust extensions for Linux, macOS, and Windows: one abi3 wheel per platform that works on CPython 3.13 and newer. If Rust isn’t available, solvOR falls back to Python automatically.
See the Performance docs for which algorithms have Rust backends and benchmarks.
Philosophy
Readable first: every algorithm in clear Python you can actually understand
Performance when needed: optional Rust backends, zero-copy where possible
Consistent: same Result format, same minimize/maximize convention
Practical: solves real problems (and AoC puzzles)
Documentation
Full docs at solvor.ai: getting started, algorithm reference, cookbook with worked examples, and troubleshooting.
A little bit of history..
I learned about solvers back in 2011, working with some great minds at a startup in Paris. I started writing python myself around 2018, always as a hobby, and in 2024 I got back into solvers for an energy management system (EMS) and wrote a few tools (simplex, milp, genetic) myself mainly to improve my understanding.
Over time this toolbox got larger and larger, so I decided to publish it on GitHub so others can use it and improve it even further. Since I am learning Rust, the performance-critical algorithms now have optional Rust backends, and more may follow. The name solvOR is a mix of solver(s) and OR (Operations Research).
Disclaimer; I am not a professional software engineer, so there are probably some obvious improvements possible. If so let me know, or create a PR!
评论