/
DBVariable.class.st
169 lines (138 loc) · 3.76 KB
/
DBVariable.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
"
I represent a constrained variable. In addition to my value, I maintain the structure of the constraint graph, the current dataflow graph, and various parameters of interest to the DeltaBlue incremental constraint solver.
Instance variables:
value my value; changed by constraints, read by client <Object>
constraints normal constraints that reference me <Array of Constraint>
determinedBy the constraint that currently determines
my value (or nil if there isn''t one) <Constraint>
walkStrength my walkabout strength <Strength>
stay true if I am a planning-time constant <Boolean>
mark used by the planner to mark constraints <Number>
"
Class {
#name : #DBVariable,
#superclass : #Object,
#instVars : [
'constraints',
'determinedBy',
'mark',
'stay',
'value',
'walkStrength'
],
#category : #'CogBenchmarks-DeltaBlue'
}
{ #category : #'instance creation' }
DBVariable class >> value: aValue [
^self new value: aValue
]
{ #category : #accessing }
DBVariable >> addConstraint: aConstraint [
"Add the given constraint to the set of all constraints that refer
to me."
constraints add: aConstraint.
]
{ #category : #accessing }
DBVariable >> constraints [
^ constraints
]
{ #category : #accessing }
DBVariable >> determinedBy [
^ determinedBy
]
{ #category : #accessing }
DBVariable >> determinedBy: anObject [
determinedBy := anObject
]
{ #category : #initialize }
DBVariable >> initialize [
super initialize.
value := 0.
constraints := OrderedCollection new: 2.
determinedBy := nil.
walkStrength := DBStrength absoluteWeakest.
stay := true.
mark := 0.
]
{ #category : #printing }
DBVariable >> longPrintOn: aStream [
self shortPrintOn: aStream.
aStream nextPutAll: ' Constraints: '.
(constraints isEmpty)
ifTrue: [aStream cr; tab; nextPutAll: 'none']
ifFalse:
[constraints do:
[: c | aStream cr; tab. c shortPrintOn: aStream]].
(determinedBy isNil) ifFalse:
[aStream cr; nextPutAll: ' Determined by: '.
aStream cr; tab. determinedBy shortPrintOn: aStream].
aStream cr.
]
{ #category : #accessing }
DBVariable >> mark [
^ mark
]
{ #category : #accessing }
DBVariable >> mark: anObject [
mark := anObject
]
{ #category : #printing }
DBVariable >> printOn: aStream [
self shortPrintOn: aStream
]
{ #category : #accessing }
DBVariable >> removeConstraint: c [
"Remove all traces of c from this variable."
constraints remove: c ifAbsent: [].
determinedBy == c ifTrue: [determinedBy := nil].
]
{ #category : #update }
DBVariable >> setValue: aValue [
"Attempt to assign the given value to me using a strength of
#preferred."
self setValue: aValue strength: #preferred.
]
{ #category : #update }
DBVariable >> setValue: aValue strength: strengthSymbol [
"Attempt to assign the given value to me using the given strength."
| editConstraint |
editConstraint := DBEditConstraint var: self strength: strengthSymbol.
(editConstraint isSatisfied) ifTrue:
[self value: aValue.
DBPlanner propagateFrom: self].
editConstraint destroyConstraint.
]
{ #category : #printing }
DBVariable >> shortPrintOn: aStream [
aStream nextPutAll: 'V(', self printString, ', '.
aStream nextPutAll: walkStrength printString, ', '.
(stay isNil) ifFalse:
[aStream nextPutAll: (stay ifTrue: ['stay, '] ifFalse: ['changing, '])].
aStream nextPutAll: value printString.
aStream nextPutAll: ')'.
aStream cr.
]
{ #category : #accessing }
DBVariable >> stay [
^ stay
]
{ #category : #accessing }
DBVariable >> stay: anObject [
stay := anObject
]
{ #category : #accessing }
DBVariable >> value [
^ value
]
{ #category : #accessing }
DBVariable >> value: anObject [
value := anObject
]
{ #category : #accessing }
DBVariable >> walkStrength [
^ walkStrength
]
{ #category : #accessing }
DBVariable >> walkStrength: anObject [
walkStrength := anObject
]