Problem definition container for PATHOS search algorithms.
Declare what your problem can do using decorator hooks.
The auto-solver selects the most powerful compatible algorithm.
Example
space = Space().initial("A")
@space.successors
... def expand(state): yield "go_B", "B"
@space.goal
... def is_goal(state): return state == "B"
result = space.solver().solve()
Source code in pathos/core/space.py
| def __init__(self) -> None:
self.capabilities: set[Capability] = set()
self._initial_value: Any = None
self._initial_factory: Callable[[], Any] | None = None
self._timeout: float | None = None
self._mode: Mode = "auto"
self._cancel_token: CancelToken = CancelToken()
# Total wall-clock deadline (perf_counter() basis) set by Solver
# when a timeout is given. Meta-algorithms read it to allocate
# per-phase budgets without needing to know the timeout themselves.
self._deadline_at: float | None = None
# Per-phase deadline installed by meta-algorithms (e.g. AnytimeLocal)
# so cooperating phases break early via `_cancel_requested()`. None
# means no phase-level deadline; only the cancel token / global
# deadline apply.
self._phase_deadline_at: float | None = None
self._n_workers: int = 1
self._adversarial: bool = False
self._players: int = 2
self._maximizing_player: int = 0
# These are set via decorator hooks before any algorithm uses them;
# typed as Any to avoid false-positive "None not callable" mypy errors.
self._successors: Any = None
self._goal: Any = None
self._heuristic: Any = None
self._evaluate: Any = None
self._terminal: Any = None
self._utility: Any = None
self._reverse_successors: Any = None
|
mode
mode(mode: Mode) -> Space
Declare the selection mode for the auto-solver.
- "exact" (current default — flips to "auto" once AnytimeAStar
is registered): admissible algorithms preferred.
- "approximate": bounded-suboptimal A* variants outrank exact
ones — useful when A*'s admissibility bill is too expensive.
- "auto": cascade meta-algorithm wins selection (anytime
delivery: best incumbent at any point in time).
Mirrors the .timeout() pattern: the value is read by
Algorithm.score_for(space) at selection time.
Source code in pathos/core/space.py
| def mode(self, mode: Mode) -> Space:
"""Declare the selection mode for the auto-solver.
- "exact" (current default — flips to "auto" once AnytimeAStar
is registered): admissible algorithms preferred.
- "approximate": bounded-suboptimal A* variants outrank exact
ones — useful when A*'s admissibility bill is too expensive.
- "auto": cascade meta-algorithm wins selection (anytime
delivery: best incumbent at any point in time).
Mirrors the .timeout() pattern: the value is read by
Algorithm.score_for(space) at selection time.
"""
if mode not in _VALID_MODES:
raise ValueError(
f"mode must be one of {sorted(_VALID_MODES)}, got {mode!r}"
)
self._mode = mode
return self
|