-
Notifications
You must be signed in to change notification settings - Fork 65
/
DBUnaryConstraint.class.st
103 lines (81 loc) · 2.36 KB
/
DBUnaryConstraint.class.st
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"
I am an abstract superclass for constraints having a single possible output variable.
Instance variables:
output possible output variable <Variable>
satisfied true if I am currently satisfied <Boolean>
"
Class {
#name : #DBUnaryConstraint,
#superclass : #DBAbstractConstraint,
#instVars : [
'output',
'satisfied'
],
#category : #'CogBenchmarks-DeltaBlue'
}
{ #category : #'instance creation' }
DBUnaryConstraint class >> var: aVariable strength: strengthSymbol [
"Install an edit constraint with the given strength on the given
variable."
^(self new) var: aVariable strength: strengthSymbol
]
{ #category : #adding }
DBUnaryConstraint >> addToGraph [
"Add myself to the constraint graph."
output addConstraint: self.
satisfied := false.
]
{ #category : #planning }
DBUnaryConstraint >> chooseMethod: mark [
"Decide if I can be satisfied and record that decision."
satisfied :=
output mark ~= mark and:
[strength stronger: output walkStrength].
]
{ #category : #planning }
DBUnaryConstraint >> execute [
"Enforce this constraint. Assume that it is satisfied."
self subclassResponsibility
]
{ #category : #planning }
DBUnaryConstraint >> inputsDo: aBlock [
"I have no input variables."
]
{ #category : #testing }
DBUnaryConstraint >> isSatisfied [
"Answer true if this constraint is satisfied in the current solution."
^satisfied
]
{ #category : #planning }
DBUnaryConstraint >> markUnsatisfied [
"Record the fact that I am unsatisfied."
satisfied := false.
]
{ #category : #planning }
DBUnaryConstraint >> output [
"Answer my current output variable."
^ output
]
{ #category : #planning }
DBUnaryConstraint >> recalculate [
"Calculate the walkabout strength, the stay flag, and, if it is 'stay',
the value for the current output of this constraint. Assume this
constraint is satisfied."
output walkStrength: strength.
output stay: self isInput not.
output stay ifTrue: [self execute]. "stay optimization"
]
{ #category : #adding }
DBUnaryConstraint >> removeFromGraph [
"Remove myself from the constraint graph."
output ifNotNil: [ :out | out removeConstraint: self].
satisfied := false.
]
{ #category : #initialize }
DBUnaryConstraint >> var: aVariable strength: strengthSymbol [
"Initialize myself with the given variable and strength."
strength := DBStrength of: strengthSymbol.
output := aVariable.
satisfied := false.
self addConstraint.
]