eef94371
Vasco Pedro
Update to PaCCS v...
|
1
|
/* X = Y - Z */
|
965dadaa
Salvador Abreu
initial commit fr...
|
2
3
4
5
6
7
8
9
10
11
12
|
static int fd_var_eq_minus_filter(fd_constraint this)
{
fd_int x, y, z;
int xmin, xmax, ymin, ymax, zmin, zmax;
int changed_x, changed_y, changed_z;
x = VAR(this, 0);
y = VAR(this, 1);
z = VAR(this, 2);
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
13
|
// XXX: just do bounds consistency, for now
|
965dadaa
Salvador Abreu
initial commit fr...
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
xmin = _fd_var_min(x);
xmax = _fd_var_max(x);
zmin = _fd_var_min(z);
zmax = _fd_var_max(z);
changed_y = _fd_var_del_lt(xmin + zmin, y) | _fd_var_del_gt(xmax + zmax, y);
if (changed_y)
{
if (fd_domain_empty(y))
return FD_NOSOLUTION;
_fd_revise_connected(NULL, y);
}
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
31
32
33
34
35
36
37
38
39
|
ymin = _fd_var_min(y);
ymax = _fd_var_max(y);
changed_z = _fd_var_del_lt(ymin - xmax, z) | _fd_var_del_gt(ymax - xmin, z);
if (changed_z)
{
if (fd_domain_empty(z))
return FD_NOSOLUTION;
|
965dadaa
Salvador Abreu
initial commit fr...
|
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
|
_fd_revise_connected(NULL, z);
zmin = _fd_var_min(z);
zmax = _fd_var_max(z);
}
changed_x = _fd_var_del_lt(ymin - zmax, x) | _fd_var_del_gt(ymax - zmin, x);
if (changed_x)
{
if (fd_domain_empty(x))
return FD_NOSOLUTION;
_fd_revise_connected(NULL, x);
}
#if CONSTRAINT_TEMPS > 3
if (fd_var_single(x, 0) && fd_var_single(y, 0) && fd_var_single(z, 0))
fd__constraint_set_entailed(this);
#endif
return FD_OK;
}
int fd_var_eq_minus_propagate2(fd_constraint this, fd_int culprit)
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
66
67
|
{
fd_int x, y, z;
|
965dadaa
Salvador Abreu
initial commit fr...
|
68
69
70
71
72
73
|
int changed_x = 0, changed_y = 0, changed_z = 0;
x = VAR(this, 0);
y = VAR(this, 1);
z = VAR(this, 2);
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
74
|
// XXX: just do bounds consistency, for now
|
965dadaa
Salvador Abreu
initial commit fr...
|
75
76
|
if (culprit == x)
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
77
|
{
|
965dadaa
Salvador Abreu
initial commit fr...
|
78
79
80
81
82
83
|
changed_y =
_fd_var_del_lt(_fd_var_min(x) + _fd_var_min(z), y);
changed_y |=
_fd_var_del_gt(_fd_var_max(x) + _fd_var_max(z), y);
if (changed_y && fd_domain_empty(y))
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
84
|
return FD_NOSOLUTION;
|
965dadaa
Salvador Abreu
initial commit fr...
|
85
86
87
|
changed_z =
_fd_var_del_lt(_fd_var_min(y) - _fd_var_max(x), z);
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
88
89
|
changed_z |=
_fd_var_del_gt(_fd_var_max(y) - _fd_var_min(x), z);
|
965dadaa
Salvador Abreu
initial commit fr...
|
90
|
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
91
92
93
94
95
96
97
98
99
100
101
102
103
|
if (changed_z && fd_domain_empty(z))
return FD_NOSOLUTION;
}
else if (culprit == y)
{
changed_x =
_fd_var_del_lt(_fd_var_min(y) - _fd_var_max(z), x);
changed_x |=
_fd_var_del_gt(_fd_var_max(y) - _fd_var_min(z), x);
if (changed_x && fd_domain_empty(x))
return FD_NOSOLUTION;
|
965dadaa
Salvador Abreu
initial commit fr...
|
104
105
|
changed_z =
_fd_var_del_lt(_fd_var_min(y) - _fd_var_max(x), z);
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
106
|
changed_z |=
|
965dadaa
Salvador Abreu
initial commit fr...
|
107
|
_fd_var_del_gt(_fd_var_max(y) - _fd_var_min(x), z);
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
108
109
110
111
112
113
114
|
if (changed_z && fd_domain_empty(z))
return FD_NOSOLUTION;
}
else // culprit == z
{
changed_x =
|
965dadaa
Salvador Abreu
initial commit fr...
|
115
116
117
|
_fd_var_del_lt(_fd_var_min(y) - _fd_var_max(z), x);
changed_x |=
_fd_var_del_gt(_fd_var_max(y) - _fd_var_min(z), x);
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
118
119
|
if (changed_x && fd_domain_empty(x))
|
965dadaa
Salvador Abreu
initial commit fr...
|
120
|
return FD_NOSOLUTION;
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
121
122
123
124
125
126
127
128
129
130
131
132
133
|
changed_y =
_fd_var_del_lt(_fd_var_min(x) + _fd_var_min(z), y);
changed_y |=
_fd_var_del_gt(_fd_var_max(x) + _fd_var_max(z), y);
if (changed_y && fd_domain_empty(y))
return FD_NOSOLUTION;
}
if (changed_x)
_fd_revise_connected(NULL, x); // XXX: NULL or this?
|
965dadaa
Salvador Abreu
initial commit fr...
|
134
135
|
if (changed_y)
_fd_revise_connected(NULL, y); // XXX: NULL or this?
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
136
|
|
965dadaa
Salvador Abreu
initial commit fr...
|
137
|
if (changed_z)
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
138
139
140
141
142
143
144
|
_fd_revise_connected(NULL, z); // XXX: NULL or this?
#if CONSTRAINT_TEMPS > 3
if (fd_var_single(x, 0) && fd_var_single(y, 0) && fd_var_single(z, 0))
fd__constraint_set_entailed(this);
#endif
|
965dadaa
Salvador Abreu
initial commit fr...
|
145
146
147
|
return FD_OK;
}
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
148
149
|
int fd_var_eq_minus_propagate(fd_constraint this, fd_int revise)
{
|
965dadaa
Salvador Abreu
initial commit fr...
|
150
|
fd_int x, y, z;
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
151
152
|
int changed;
|
965dadaa
Salvador Abreu
initial commit fr...
|
153
|
x = VAR(this, 0);
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
154
155
156
157
|
y = VAR(this, 1);
z = VAR(this, 2);
// XXX: just do bounds consistency, for now
|
965dadaa
Salvador Abreu
initial commit fr...
|
158
|
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
159
160
|
if (revise == x)
{
|
965dadaa
Salvador Abreu
initial commit fr...
|
161
|
changed =
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
162
163
|
_fd_var_del_lt(_fd_var_min(y) - _fd_var_max(z), revise);
changed |=
|
965dadaa
Salvador Abreu
initial commit fr...
|
164
|
_fd_var_del_gt(_fd_var_max(y) - _fd_var_min(z), revise);
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
165
166
|
}
else if (revise == y)
|
965dadaa
Salvador Abreu
initial commit fr...
|
167
|
{
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
168
169
170
171
|
changed =
_fd_var_del_lt(_fd_var_min(x) + _fd_var_min(z), revise);
changed |=
_fd_var_del_gt(_fd_var_max(x) + _fd_var_max(z), revise);
|
965dadaa
Salvador Abreu
initial commit fr...
|
172
|
}
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
173
174
175
176
177
178
179
180
181
|
else // revise == z
{
changed =
_fd_var_del_lt(_fd_var_min(y) - _fd_var_max(x), revise);
changed |=
_fd_var_del_gt(_fd_var_max(y) - _fd_var_min(x), revise);
}
if (changed && fd_domain_empty(revise))
|
965dadaa
Salvador Abreu
initial commit fr...
|
182
183
184
185
186
187
|
return FD_NOSOLUTION;
// XXX: enqueue further updates here?
if (changed)
_fd_revise_connected(this, revise);
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
188
|
return FD_OK;
|
965dadaa
Salvador Abreu
initial commit fr...
|
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
}
fd_constraint fd_var_eq_minus(fd_int x, fd_int y, fd_int z)
{
fd_constraint c = _fd_constraint_new(3, 0);
if (c)
{
c->variables[0] = FD_INT2C_VAR(x);
c->variables[1] = FD_INT2C_VAR(y);
c->variables[2] = FD_INT2C_VAR(z);
#ifdef CONSTRAINT_CLASS
c->kind = FD_CONSTR_VAR_EQ_MINUS;
#else /* CONSTRAINT_CLASS */
c->propagator2 = fd_var_eq_minus_propagate2;
c->propagator = fd_var_eq_minus_propagate;
#endif /* CONSTRAINT_CLASS */
_fd_var_add_constraint(x, c);
_fd_var_add_constraint(y, c);
_fd_var_add_constraint(z, c);
_fd_add_constraint(c);
}
return c;
}
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
|
|
965dadaa
Salvador Abreu
initial commit fr...
|
|
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
|
|
965dadaa
Salvador Abreu
initial commit fr...
|
|
|
965dadaa
Salvador Abreu
initial commit fr...
|
|
|