eef94371
Vasco Pedro
Update to PaCCS v...
|
1
|
/* x < y */
|
965dadaa
Salvador Abreu
initial commit fr...
|
2
|
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
3
|
static int fd_lt_filter(fd_constraint this)
|
965dadaa
Salvador Abreu
initial commit fr...
|
4
5
6
7
8
9
10
11
|
{
fd_int x, y;
x = VAR(this, 0);
y = VAR(this, 1);
#ifndef DISABLE_ENTAILED
if (_fd_var_max(x) < _fd_var_min(y))
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
12
13
14
15
16
|
{
fd__constraint_set_entailed(this);
return FD_OK;
}
|
965dadaa
Salvador Abreu
initial commit fr...
|
17
18
19
20
21
22
23
|
#endif
if (_fd_var_del_le(_fd_var_min(x), y))
{
if (fd_domain_empty(y))
return FD_NOSOLUTION;
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
24
|
_fd_revise_connected(this, y);
|
965dadaa
Salvador Abreu
initial commit fr...
|
25
26
27
28
29
30
31
|
}
if (_fd_var_del_ge(_fd_var_max(y), x))
{
if (fd_domain_empty(x))
return FD_NOSOLUTION;
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
32
|
_fd_revise_connected(this, x);
|
965dadaa
Salvador Abreu
initial commit fr...
|
33
34
|
}
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
35
36
37
38
39
|
#ifndef DISABLE_ENTAILED
if (_fd_var_max(x) < _fd_var_min(y))
fd__constraint_set_entailed(this);
#endif
|
965dadaa
Salvador Abreu
initial commit fr...
|
40
41
42
|
return FD_OK;
}
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
43
|
static int fd_lt_propagate2(fd_constraint this, fd_int culprit)
|
965dadaa
Salvador Abreu
initial commit fr...
|
44
|
{
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
45
46
|
fd_int x, y;
int vmax, vmin;
|
965dadaa
Salvador Abreu
initial commit fr...
|
47
48
49
|
fd_int revise;
int changed = 0;
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
50
51
52
53
54
55
56
57
|
x = VAR(this, 0);
y = VAR(this, 1);
#ifndef DISABLE_ENTAILED
vmax = _fd_var_max(x);
vmin = _fd_var_min(y);
if (vmax < vmin)
|
965dadaa
Salvador Abreu
initial commit fr...
|
58
59
60
61
62
63
64
|
{
fd__constraint_set_entailed(this);
return FD_OK;
}
#endif
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
65
|
if (culprit == x)
|
965dadaa
Salvador Abreu
initial commit fr...
|
66
|
{
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
67
|
revise = y;
|
965dadaa
Salvador Abreu
initial commit fr...
|
68
|
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
69
70
71
|
vmin = _fd_var_min(x);
changed = _fd_var_del_le(vmin, y);
|
965dadaa
Salvador Abreu
initial commit fr...
|
72
73
74
|
}
else
{
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
75
|
revise = x;
|
965dadaa
Salvador Abreu
initial commit fr...
|
76
|
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
77
|
vmax = _fd_var_max(y);
|
965dadaa
Salvador Abreu
initial commit fr...
|
78
|
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
79
80
|
changed = _fd_var_del_ge(vmax, x);
}
|
965dadaa
Salvador Abreu
initial commit fr...
|
81
82
|
if (changed)
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
83
84
85
86
87
88
89
90
91
92
93
94
|
{
if (fd_domain_empty(revise))
return FD_NOSOLUTION;
_fd_revise_connected(this, revise);
#ifndef DISABLE_ENTAILED
// see if the culprit's domain is a singleton
if (vmin == vmax)
fd__constraint_set_entailed(this);
#endif
}
|
965dadaa
Salvador Abreu
initial commit fr...
|
95
96
97
98
|
return FD_OK;
}
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
99
|
static int fd_lt_propagate(fd_constraint this, fd_int revise)
|
965dadaa
Salvador Abreu
initial commit fr...
|
100
101
102
103
104
105
106
107
108
109
110
111
112
|
{
int changed = 0;
if (revise == VAR(this, 0))
changed = _fd_var_del_ge(_fd_var_max(VAR(this, 1)), revise);
else
changed = _fd_var_del_le(_fd_var_min(VAR(this, 0)), revise);
if (changed && fd_domain_empty(revise))
return FD_NOSOLUTION;
#ifdef USE_ENTAILED
if (_fd_var_max(VAR(this, 0)) < _fd_var_min(VAR(this, 1)))
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
113
|
fd__constraint_set_entailed(this);
|
965dadaa
Salvador Abreu
initial commit fr...
|
114
115
116
117
118
119
120
121
122
123
124
|
#endif
// XXX: enqueue further updates here?
if (changed)
_fd_revise_connected(this, revise);
return FD_OK;
}
fd_constraint fd_lt(fd_int x, fd_int y)
{
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
125
|
fd_constraint c = fd__constraint_new(2, 0);
|
965dadaa
Salvador Abreu
initial commit fr...
|
126
127
128
129
|
if (c)
{
c->variables[0] = FD_INT2C_VAR(x); c->variables[1] = FD_INT2C_VAR(y);
|
eef94371
Vasco Pedro
Update to PaCCS v...
|
130
|
|
965dadaa
Salvador Abreu
initial commit fr...
|
131
|
c->kind = FD_CONSTR_LT;
|
965dadaa
Salvador Abreu
initial commit fr...
|
132
133
134
135
136
137
138
139
140
|
_fd_var_add_constraint(x, c);
_fd_var_add_constraint(y, c);
_fd_add_constraint(c);
}
return c;
}
|