PATHOS¶
Production-ready classical AI search algorithms for Python — no machine learning, pure search.
PATHOS is problem-centric: you declare what your problem can do with decorator hooks; the auto-solver picks the best compatible algorithm.
from pathos import Space
space = Space().initial("Madrid")
@space.successors
def neighbors(city):
for next_city, km in roads[city]:
yield next_city, next_city
@space.goal
def reached(city): return city == "Lisboa"
@space.heuristic
def h(city): return straight_line_km(city, "Lisboa")
# Default mode is anytime — returns proven optimal if it finishes,
# best incumbent if the budget runs out. Never not_found if any
# feasible path exists.
result = space.solver(timeout=10).solve()
print(result.path, result.cost, result.algorithm, result.optimal)
Install¶
Requires Python 3.11+. MIT license.
Highlights¶
-
Problem-centric
Declare your problem's structure with decorators. The solver figures out which algorithm fits.
-
Anytime by default
solver().solve()runs a cascade tuned to your problem family (informed, local, CSP, adversarial) and always delivers the best incumbent within your budget — nevernot_foundwhen a feasible answer exists. -
Cooperative cancellation
Every algorithm checks a cancel token in its main loop. Set a timeout and metaheuristics return their best individual seen — automatically.
-
Comprehensive coverage
Uninformed (BFS, DFS, IDDFS, UCS), informed (A*, IDA*, WAStar, Greedy, Bidirectional), local search (HC, Tabu, Beam), evolutionary (GA, DE, PSO, SA), adversarial (Minimax, AlphaBeta, MCTS), CSP (Backtracking, FC, MC).
Algorithm families¶
| Declare | Algorithms available |
|---|---|
@evaluate |
SA, GA, DE, PSO |
@successors + @goal |
BFS, DFS, IDDFS (DFS is non-optimal — for shortest paths prefer BFS/UCS) |
@successors + @evaluate |
AnytimeLocal (default under mode="auto"), HillClimbing, TabuSearch, LocalBeamSearch, SimulatedAnnealing |
@successors + @goal + @heuristic |
GreedyBestFirst |
@successors + @goal + @heuristic + @evaluate |
AnytimeAStar (default under mode="auto"), AStar, IDAstar, WeightedAStar, BidirectionalAStar, UCS |
.adversarial() + @terminal + @utility |
AnytimeAdversarial (default under mode="auto"), Minimax, AlphaBeta, Negamax, MCTS |
CSPSpace + @constraint |
AnytimeCSP (default under mode="auto"), Backtracking, ForwardChecking, MinConflicts |