Skip to main content

Module search

Module search 

Source
Expand description

Unified monomorphized search kernel.

Tests: tests/solver.rs (general solve correctness), tests/solution_set_invariance.rs (solution-set property test).

One tree-search skeleton — [search] — parameterized by a zero-sized [SearchPolicy]. The policy decides the four things that actually differ between the crate’s search modes:

axis[Feasibility][BranchBound]
leaf actionrecord, stop at maxscore, keep best, never stop
node prunenoneoptimistic-bound cutoff
value orderraw domain ordercost-sorted

Every hook is #[inline] and every implementor is (near) zero-sized, so monomorphization inlines the whole policy — no dispatch cost, the same devirtualization the crate already applies to ConstraintEnum.

This kernel replaces the three near-verbatim recursive DFS functions that preceded it (backtrack_recurse, backjump_recurse, bb_recurse) whose propagate match, validity-check loop, and restore sweep were byte-identical. Undo now runs off the shared [Trail] (touched-variable list) rather than an O(num_vars) per-node sweep, and read-only state (weights, var_cids, adjacency) is borrowed rather than deep-cloned per solve.

Structs§

SearchParams
Shared, immutable search parameters. Collapses the three former per-mode config structs (BacktrackConfig / BackjumpConfig / OptimizeConfig), which differed only in a maximize bool and each carried its own cloned copy of constraint_weights + var_constraint_ids. Those read-only vectors are now borrowed by the kernel, so they live nowhere in this struct.

Constants§

PERMANENT_DEPTH
Depth reserved for permanent pre-search propagation (root AC-3, given-cell propagation). Search recursion begins at [SEARCH_ROOT_DEPTH] so its depth-keyed undo can never target these permanent reductions — fixing the depth-0 seam where the first failed root candidate un-pruned the initial AC-3 via restore(0).

Functions§

branch_and_bound
Run branch-and-bound optimization. Returns up to max_solutions solutions, sorted best-first per the optimization direction.
feasibility_search
Run feasibility (satisfaction) search. given pre-seeds an assignment and filters the branch stack; None searches all variables from scratch.