Planning & Search in Rust
Esc

Loading…

↑↓ move ↵ open Esc close
Colour theme
All algorithms

Cost-ordered inference rules

Also known as Human-style solving, Naked and hidden subsets, Locked candidates

constraint constraint-search

Inference rules solve a puzzle the way a person does: each rule is one named technique with a cost, such as two cells that share the only two values left. Each step applies the cheapest rule that removes a value and records what it removed, and a solve repeats steps until no rule fires. The steps serve as hints, the most expensive rule a solve needed grades the puzzle, and why_removed names the step that took a value away. The rules shipped have generic names: VariableSubset, ValueSubset (only in groups that must use every value), GroupIntersection, SumDifference (one sum subtracted from a sum that contains it) and PropagatorRule (any propagator, such as Linear or Line, as a rule); with_name gives a rule a domain's own term, such as Sudoku's naked and hidden subsets or locked candidates. Use them to explain and grade; use propagators and search to solve fast.

Pseudocode

algorithm Rules-Solve(R, D, unique)input: rules R sorted by cost, cheapest first, domains D, whether to assume one solutionoutput: the steps applied, and whether every variable has one value leftSTEPS ← ⟨⟩repeats ← step(R, D, unique)if s ≠ nil thenappend(STEPS, s)until s = nilreturn STEPS, solved(D)function step(R, D, unique)for each rule ρ in R do                      ▷ from the cheapest on every stepif not assumes-unique(ρ) or unique then    ▷ unique: the caller asserts one solutionmark ← length(TRAIL)apply(ρ, D)                              ▷ failure if a domain would emptyif length(TRAIL) > mark thenreturn ⟨ρ, cost(ρ), the values removed since mark⟩return nilfunction why-removed(STEPS, x, v)for each s in STEPS doif v ∈ removed(s, x) thenreturn sreturn nilprocedure ValueSubset(k, GROUPS, D)for each group g in GROUPS doif |⋃ D(x) over x ∈ g| = |g| then          ▷ only groups that must use every valuefor each set W of k values, each held by 1 to k variables of g, one of them unfixed doH ← the variables of g that hold a value of Wif |H| = k thenD(x) ← D(x) ∩ W for each x ∈ H       ▷ a hidden subset

In the crates

Lineage

Led to

Nothing on this site.