Documentation ¶
Index ¶
- Variables
- func RunWithContext[T any](ctx context.Context, f func() T) (*T, error)
- type BackTrackingCSPSolver
- type CSPState
- type Constraint
- func Equals[T comparable](var1 VariableName, var2 VariableName) Constraint[T]
- func GreaterThan[T constraints.Integer | constraints.Float](var1 VariableName, var2 VariableName) Constraint[T]
- func GreaterThanOrEqualTo[T constraints.Integer | constraints.Float](var1 VariableName, var2 VariableName) Constraint[T]
- func LessThan[T constraints.Integer | constraints.Float](var1 VariableName, var2 VariableName) Constraint[T]
- func LessThanOrEqualTo[T constraints.Integer | constraints.Float](var1 VariableName, var2 VariableName) Constraint[T]
- func NotEquals[T comparable](var1 VariableName, var2 VariableName) Constraint[T]
- func UnaryEquals[T comparable](var1 VariableName, value interface{}) Constraint[T]
- func UnaryNotEquals[T comparable](var1 VariableName, value interface{}) Constraint[T]
- type Constraints
- type Domain
- func FloatRange(start float64, end float64) Domain[float64]
- func FloatRangeStep(start float64, end float64, step float64) Domain[float64]
- func Generator[T comparable](inputDomain Domain[T], fx func(T) T) Domain[T]
- func IntRange(start int, end int) Domain[int]
- func IntRangeStep(start int, end int, step int) Domain[int]
- func TimeRange(start time.Time, end time.Time) Domain[time.Time]
- func TimeRangeStep(start time.Time, end time.Time, step time.Duration) Domain[time.Time]
- type DomainRemoval
- type DomainRemovals
- type Propagation
- type PropagationFunction
- type Propagations
- type Variable
- type VariableAssignment
- type VariableName
- type VariableNames
- type Variables
- func (variables *Variables[T]) Complete() bool
- func (variables *Variables[T]) Contains(name VariableName) bool
- func (variables *Variables[T]) EvaluateDomainRemovals(domainRemovals DomainRemovals[T])
- func (variables *Variables[T]) Find(name VariableName) *Variable[T]
- func (variables *Variables[T]) ResetDomainRemovalEvaluation(domainRemovals DomainRemovals[T])
- func (variables *Variables[T]) SetDomain(name VariableName, domain Domain[T])
- func (variables *Variables[T]) SetValue(name VariableName, value T)
- func (variables *Variables[T]) Unassigned() int
- func (variables *Variables[T]) Unset(name VariableName)
- type VariablesConstraintFunction
Constants ¶
This section is empty.
Variables ¶
var (
ErrExecutionCanceled error = errors.New("execution canceled")
)
Functions ¶
func RunWithContext ¶ added in v1.0.1
RunWithContext accepts a context and a function that produces T The function will be run, and so long as the context is not done, its result will be returned. Otherwise an error will be returned.
Types ¶
type BackTrackingCSPSolver ¶
type BackTrackingCSPSolver[T comparable] struct { State CSPState[T] }
BackTrackingCSPSolver struct for holding solver state
func NewBackTrackingCSPSolver ¶
func NewBackTrackingCSPSolver[T comparable](vars Variables[T], constraints Constraints[T]) BackTrackingCSPSolver[T]
NewBackTrackingCSPSolver create a solver
func NewBackTrackingCSPSolverWithPropagation ¶
func NewBackTrackingCSPSolverWithPropagation[T comparable](vars Variables[T], constraints Constraints[T], propagations Propagations[T]) BackTrackingCSPSolver[T]
NewBackTrackingCSPSolverWithPropagation create a solver
type CSPState ¶
type CSPState[T comparable] struct { Vars Variables[T] Constraints Constraints[T] Propagations[T] }
CSPState state object for CSP Solver
func (*CSPState[T]) MakeArcConsistent ¶
MakeArcConsistent algorithm based off of AC-3 used to make the given CSP fully arc consistent. https://en.wikipedia.org/wiki/AC-3_algorithm
func (*CSPState[T]) SimplifyPreAssignment ¶
SimplifyPreAssignment basic constraint propagation algorithm used to simplify variable domains before solving based on variables already assigned to. Condition: if a variable has been assigned to with a given value, remove that value from the domain of all variables mutually exclusive to it, i.e. if A != B and B = 2, remove 2 from the domain of A. Use of this algorith is not recommended. Enforce arc consistency instead.
type Constraint ¶
type Constraint[T comparable] struct { Vars VariableNames ConstraintFunction VariablesConstraintFunction[T] }
Constraint CSP constraint considering integer variables
func Equals ¶
func Equals[T comparable](var1 VariableName, var2 VariableName) Constraint[T]
Equals Constraint generator that checks if two vars are equal
func GreaterThan ¶
func GreaterThan[T constraints.Integer | constraints.Float](var1 VariableName, var2 VariableName) Constraint[T]
GreaterThan Constraint generator that checks if first variable is less than second variable
func GreaterThanOrEqualTo ¶
func GreaterThanOrEqualTo[T constraints.Integer | constraints.Float](var1 VariableName, var2 VariableName) Constraint[T]
GreaterThanOrEqualTo Constraint generator that checks if first variable is less than or equal to second variable
func LessThan ¶
func LessThan[T constraints.Integer | constraints.Float](var1 VariableName, var2 VariableName) Constraint[T]
LessThan Constraint generator that checks if first variable is less than second variable
func LessThanOrEqualTo ¶
func LessThanOrEqualTo[T constraints.Integer | constraints.Float](var1 VariableName, var2 VariableName) Constraint[T]
LessThanOrEqualTo Constraint generator that checks if first variable is less than or equal to second variable
func NotEquals ¶
func NotEquals[T comparable](var1 VariableName, var2 VariableName) Constraint[T]
NotEquals Constraint generator that checks if two vars are not equal
func UnaryEquals ¶
func UnaryEquals[T comparable](var1 VariableName, value interface{}) Constraint[T]
UnaryEquals Unary constraint that checks if var1 equals some constant
func UnaryNotEquals ¶
func UnaryNotEquals[T comparable](var1 VariableName, value interface{}) Constraint[T]
UnaryNotEquals Unary constraint that checks if var1 is not equal to some constant
func (*Constraint[T]) Satisfied ¶
func (constraint *Constraint[T]) Satisfied(variables *Variables[T]) bool
Satisfied checks to see if the given Constraint is satisfied by the variables presented
type Constraints ¶
type Constraints[T comparable] []Constraint[T]
Constraints collection type for Constraint
func AllEquals ¶
func AllEquals[T comparable](varnames ...VariableName) Constraints[T]
AllEquals Constraint generator that checks that all given variables are equal
func AllUnique ¶
func AllUnique[T comparable](varnames ...VariableName) Constraints[T]
AllUnique Constraint generator to check if all variable values are unique
func (*Constraints[T]) AllSatisfied ¶
func (constraints *Constraints[T]) AllSatisfied(variables *Variables[T]) bool
AllSatisfied check if a collection of Constraints are satisfied
func (*Constraints[T]) FilterByName ¶
func (constraints *Constraints[T]) FilterByName(name VariableName) Constraints[T]
FilterByName return all constraints related to a particular variable name
func (*Constraints[T]) FilterByOrder ¶
func (constraints *Constraints[T]) FilterByOrder(order int) Constraints[T]
FilterByOrder return all constraints with the given order (number of related variables)
type Domain ¶
type Domain[T comparable] []T
Domain domain object
func FloatRange ¶
FloatRange returns a slice of integers in the desired range with a step of 1
func FloatRangeStep ¶
FloatRangeStep returns a slice of integers in the desired range with the given step
func Generator ¶
func Generator[T comparable](inputDomain Domain[T], fx func(T) T) Domain[T]
Generator generates a Domain from another input domain and a function f(x). For example:
func IntRangeStep ¶
IntRangeStep returns a slice of integers in the desired range with the given step
func TimeRangeStep ¶
TimeRangeStep get the range of time between start to end with step as a Duration (in nanoseconds).
type DomainRemoval ¶
type DomainRemoval[T comparable] struct { // VariableName the variable whose domain we are pruning VariableName // Value the value to prune from its domain Value T }
DomainRemoval a struct indicating removing an item from a domain
type DomainRemovals ¶
type DomainRemovals[T comparable] []DomainRemoval[T]
DomainRemovals list type for DomainRemoval
type Propagation ¶
type Propagation[T comparable] struct { Vars VariableNames PropagationFunction[T] }
Propagation type representing a domain propagation
func (*Propagation[T]) Execute ¶
func (propagation *Propagation[T]) Execute(assignment VariableAssignment[T], variables *Variables[T]) []DomainRemoval[T]
Execute this Propagation
type PropagationFunction ¶
type PropagationFunction[T comparable] func(assignment VariableAssignment[T], variables *Variables[T]) []DomainRemoval[T]
PropagationFunction used to determine domain pruning
type Propagations ¶
type Propagations[T comparable] []Propagation[T]
Propagations list type for Propagation
func (*Propagations[T]) Execute ¶
func (propagations *Propagations[T]) Execute(assignment VariableAssignment[T], variables *Variables[T]) []DomainRemoval[T]
Execute all propagations in the list
type Variable ¶
type Variable[T comparable] struct { Name VariableName Value T Domain Domain[T] Empty bool }
Variable indicates a CSP variable of interface{} type
func NewVariable ¶
func NewVariable[T comparable](name VariableName, domain Domain[T]) Variable[T]
NewVariable constructor for Variable type
type VariableAssignment ¶
type VariableAssignment[T comparable] struct { // VariableName the variable that was assigned to VariableName // Value the value being assigned Value T }
VariableAssignment a struct indicating assigning a value to a variable
type VariableNames ¶
type VariableNames []VariableName
VariableNames collection type for VariableName
func (*VariableNames) Contains ¶
func (varnames *VariableNames) Contains(varname VariableName) bool
Contains slice contains method for VariableNames
type Variables ¶
type Variables[T comparable] []Variable[T]
Variables collection type for interface{} type variables
func (*Variables[T]) Contains ¶
func (variables *Variables[T]) Contains(name VariableName) bool
Contains slice contains method for Variables
func (*Variables[T]) EvaluateDomainRemovals ¶
func (variables *Variables[T]) EvaluateDomainRemovals(domainRemovals DomainRemovals[T])
EvaluateDomainRemovals remove values from domain based on DomainRemovals in propagation
func (*Variables[T]) Find ¶
func (variables *Variables[T]) Find(name VariableName) *Variable[T]
Find find an Variable by name in an Variables collection
func (*Variables[T]) ResetDomainRemovalEvaluation ¶
func (variables *Variables[T]) ResetDomainRemovalEvaluation(domainRemovals DomainRemovals[T])
ResetDomainRemovalEvaluation undo pruning on a variable's domain
func (*Variables[T]) SetDomain ¶
func (variables *Variables[T]) SetDomain(name VariableName, domain Domain[T])
SetDomain set the domain of the given variable by name
func (*Variables[T]) SetValue ¶
func (variables *Variables[T]) SetValue(name VariableName, value T)
SetValue setter for Variables collection
func (*Variables[T]) Unassigned ¶
Unassigned return the number of unassigned variables
func (*Variables[T]) Unset ¶
func (variables *Variables[T]) Unset(name VariableName)
Unset unset a variable with the given name
type VariablesConstraintFunction ¶
type VariablesConstraintFunction[T comparable] func(variables *Variables[T]) bool
VariablesConstraintFunction function used to determine validity of Variables