backtrex v0.1.1 Backtrex behaviour

A backtracking behaviour for solving discrete computational problems.

Summary

Types

Potential value assignment for some unknown

An assignment with a list of values left to try

Next value to try

A puzzle with a set of unknowns, possible assignments for each, and an invariant property

Unique identifier for an unknown in a problem

Value that could be assigned to an unknown

Types

assignment()
assignment() :: {unknown, value}

Potential value assignment for some unknown.

assignment_search()
assignment_search() :: {assignment, [value]}

An assignment with a list of values left to try.

maybe_value()
maybe_value() :: {:ok, value} | :none

Next value to try.

problem()
problem() :: any

A puzzle with a set of unknowns, possible assignments for each, and an invariant property.

Each type of problem must have ways to:

  1. enumerate its unknowns (see c:unknowns),
  2. enumerate values that could be assigned to any particular unknown in a solution (see c:values).
  3. incorporate proposed assignments (see c:with_assignments), and
  4. check whether the invariant holds (see c:valid?).
result()
result() :: {:ok, :solution, problem} | {:ok, :no_solution}
unknown()
unknown() :: any

Unique identifier for an unknown in a problem.

value()
value() :: any

Value that could be assigned to an unknown.

Callbacks

unknowns(problem)
unknowns(problem) :: [unknown]
valid?(problem)
valid?(problem) :: boolean
values(problem, unknown)
values(problem, unknown) :: Enum.t
with_assignments(problem, list)
with_assignments(problem, [assignment]) :: problem