Router¶
Some questions a product might ask on the way to a decision are too
hard to answer exactly (splitting a graph into two groups with the most
links between them) or have no algorithm at all (finding every rational
root of an arbitrary polynomial). The router takes such a question,
tagged with how hard it is, and either runs a bounded approximation or
refuses (always for undec, exptime_trap and fpras). Module.decide never calls it; you call it yourself.
Public here: Subgoal, dispatch (top level); RouterResult,
RouterRefuse, available_subgoals, max_cut_spectral,
vertex_cover_matching, refine and WLRejected from the submodules.
How to use it: Use the hardness router;
why it refuses: Questions the library refuses.
dispatch ¶
Hardness-aware solver router.
A subgoal is tagged with an Envelope. The dispatcher never falls
upward into a harder class.
RouterRefuse ¶
Bases: ValueError
The envelope forbids the requested procedure.
dispatch ¶
dispatch(
sg: Subgoal, *, limits: Limits = DEFAULT_LIMITS
) -> RouterResult
Route one subgoal to its handler, or refuse it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sg
|
Subgoal
|
The subgoal: a registered name, its envelope, and its payload. |
required |
limits
|
Limits
|
Size caps to enforce. Pass the same |
DEFAULT_LIMITS
|
Returns:
| Type | Description |
|---|---|
RouterResult
|
The handler's result, or a refusal ( |
RouterResult
|
|
RouterResult
|
so an |
RouterResult
|
by a handler with a different envelope. |
Raises:
| Type | Description |
|---|---|
RouterRefuse
|
The subgoal name is not registered. |
Source code in src/grounded_decision/router/dispatch.py
ugc ¶
Approximations the router is allowed to run (family 102).
Max-Cut: split by the sign of the top Laplacian eigenvector, then local search; always cuts at least half the edges. It is a stand-in for the Goemans–Williamson SDP, whose ratio (about 0.878) is the best any polynomial algorithm can promise if the Unique Games Conjecture holds. Vertex Cover: maximal-matching 2-approximation (factor 2 is optimal for general graphs under the same conjecture). The router records these targets and never searches for a better worst-case factor.
ApproxResultDict ¶
Bases: TypedDict
Serialized form of :class:ApproxResult.
vertex_cover_matching ¶
2-approx: take both endpoints of a maximal matching.
Source code in src/grounded_decision/router/ugc.py
wl ¶
Color refinement (1-WL) and a 2-WL pairwise variant.
Family 133 (Lean): variable-k identification is EXPTIME-complete and k-WL is n^{Ω(k)}. The router refuses k > 2.
color_refinement ¶
1-WL. Returns a stable color of each vertex in sorted vertex order.
Source code in src/grounded_decision/router/wl.py
wl2_hash ¶
Pair colors: a practical 2-WL stand-in on ordered pairs.