-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpropagation.go
49 lines (41 loc) · 1.63 KB
/
propagation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package centipede
// DomainRemoval a struct indicating removing an item from a domain
type DomainRemoval[T comparable] struct {
// VariableName the variable whose domain we are pruning
VariableName
// Value the value to prune from its domain
Value T
}
// DomainRemovals list type for DomainRemoval
type DomainRemovals[T comparable] []DomainRemoval[T]
// VariableAssignment a struct indicating assigning a value to a variable
type VariableAssignment[T comparable] struct {
// VariableName the variable that was assigned to
VariableName
// Value the value being assigned
Value T
}
// Propagation type representing a domain propagation
type Propagation[T comparable] struct {
Vars VariableNames
PropagationFunction[T]
}
// Propagations list type for Propagation
type Propagations[T comparable] []Propagation[T]
// PropagationFunction used to determine domain pruning
type PropagationFunction[T comparable] func(assignment VariableAssignment[T], variables *Variables[T]) []DomainRemoval[T]
// Execute this Propagation
func (propagation *Propagation[T]) Execute(assignment VariableAssignment[T], variables *Variables[T]) []DomainRemoval[T] {
return propagation.PropagationFunction(assignment, variables)
}
// Execute all propagations in the list
func (propagations *Propagations[T]) Execute(assignment VariableAssignment[T], variables *Variables[T]) []DomainRemoval[T] {
removals := make(DomainRemovals[T], 0)
for _, propagation := range *propagations {
// if this assignment is relevant to us
if propagation.Vars.Contains(assignment.VariableName) {
removals = append(removals, propagation.Execute(assignment, variables)...)
}
}
return removals
}