Documentation ¶
Overview ¶
Package solver implements a general-purpose solver for boolean constraint satisfiability problems.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrIncomplete = errors.New("cancelled before a solution could be found")
Functions ¶
This section is empty.
Types ¶
type AppliedConstraint ¶
type AppliedConstraint struct { Variable Variable Constraint Constraint }
AppliedConstraint values compose a single Constraint with the Variable it applies to.
func (AppliedConstraint) String ¶
func (a AppliedConstraint) String() string
String implements fmt.Stringer and returns a human-readable message representing the receiver.
type Constraint ¶
type Constraint interface { String(subject Identifier) string // contains filtered or unexported methods }
Constraint implementations limit the circumstances under which a particular Variable can appear in a solution.
func AtMost ¶
func AtMost(n int, ids ...Identifier) Constraint
AtMost returns a Constraint that forbids solutions that contain more than n of the Variables identified by the given Identifiers.
func Conflict ¶
func Conflict(id Identifier) Constraint
Conflict returns a Constraint that will permit solutions containing either the constrained Variable, the Variable identified by the given Identifier, or neither, but not both.
func Dependency ¶
func Dependency(ids ...Identifier) Constraint
Dependency returns a Constraint that will only permit solutions containing a given Variable on the condition that at least one of the Variables identified by the given Identifiers also appears in the solution. Identifiers appearing earlier in the argument list have higher preference than those appearing later.
func Mandatory ¶
func Mandatory() Constraint
Mandatory returns a Constraint that will permit only solutions that contain a particular Variable.
func Prohibited ¶
func Prohibited() Constraint
Prohibited returns a Constraint that will reject any solution that contains a particular Variable. Callers may also decide to omit an Variable from input to Solve rather than apply such a Constraint.
type DefaultTracer ¶
type DefaultTracer struct{}
func (DefaultTracer) Trace ¶
func (DefaultTracer) Trace(_ SearchPosition)
type DuplicateIdentifier ¶
type DuplicateIdentifier Identifier
func (DuplicateIdentifier) Error ¶
func (e DuplicateIdentifier) Error() string
type Identifier ¶
type Identifier string
Identifier values uniquely identify particular Variables within the input to a single call to Solve.
func IdentifierFromString ¶ added in v0.18.0
func IdentifierFromString(s string) Identifier
IdentifierFromString returns an Identifier based on a provided string.
func (Identifier) String ¶
func (id Identifier) String() string
type LoggingTracer ¶
func (LoggingTracer) Trace ¶
func (t LoggingTracer) Trace(p SearchPosition)
type NotSatisfiable ¶
type NotSatisfiable []AppliedConstraint
NotSatisfiable is an error composed of a minimal set of applied constraints that is sufficient to make a solution impossible.
func (NotSatisfiable) Error ¶
func (e NotSatisfiable) Error() string
type SearchPosition ¶
type SearchPosition interface { Variables() []Variable Conflicts() []AppliedConstraint }
type Tracer ¶
type Tracer interface {
Trace(p SearchPosition)
}
type Variable ¶ added in v0.21.0
type Variable interface { // Identifier returns the Identifier that uniquely identifies // this Variable among all other Variables in a given // problem. Identifier() Identifier // Constraints returns the set of constraints that apply to // this Variable. Constraints() []Constraint }
Variable values are the basic unit of problems and solutions understood by this package.