Skip to content

Commit 223123f

Browse files
committed
Split minimodel post into rel and expr. Get rid of ~, tt and ff.
git-svn-id: file:///Users/tack/GecodeGitMigration/gecode-svn-mirror/gecode/trunk@10906 e85b7adc-8362-4630-8c63-7469d557c915
1 parent fb2d6e5 commit 223123f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+255
-282
lines changed

changelog.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ Date: soon
7272
[DESCRIPTION]
7373
More fixes for more bugs.
7474

75+
[ENTRY]
76+
Module: minimodel
77+
What: change
78+
Rank: major
79+
[DESCRIPTION]
80+
The minimodel post functions have been split into two functions, rel
81+
and expr. While rel posts a constraint, expr returns a new variable
82+
constrained to the given expression. This change makes it possible to
83+
get rid of the reification operator (~) as well as the tt and ff
84+
functions, which were previously needed to distinguish between
85+
relations and expressions.
86+
7587
[ENTRY]
7688
Module: minimodel
7789
What: new

examples/alpha.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,26 @@ class Alpha : public Script {
7272
q(le[16]), r(le[17]), s(le[18]), t(le[19]), u(le[20]),
7373
v(le[21]), w(le[22]), x(le[23]), y(le[24]), z(le[25]);
7474

75-
post(*this, b+a+l+l+e+t == 45, opt.icl());
76-
post(*this, c+e+l+l+o == 43, opt.icl());
77-
post(*this, c+o+n+c+e+r+t == 74, opt.icl());
78-
post(*this, f+l+u+t+e == 30, opt.icl());
79-
post(*this, f+u+g+u+e == 50, opt.icl());
80-
post(*this, g+l+e+e == 66, opt.icl());
81-
post(*this, j+a+z+z == 58, opt.icl());
82-
post(*this, l+y+r+e == 47, opt.icl());
83-
post(*this, o+b+o+e == 53, opt.icl());
84-
post(*this, o+p+e+r+a == 65, opt.icl());
85-
post(*this, p+o+l+k+a == 59, opt.icl());
86-
post(*this, q+u+a+r+t+e+t == 50, opt.icl());
87-
post(*this, s+a+x+o+p+h+o+n+e == 134, opt.icl());
88-
post(*this, s+c+a+l+e == 51, opt.icl());
89-
post(*this, s+o+l+o == 37, opt.icl());
90-
post(*this, s+o+n+g == 61, opt.icl());
91-
post(*this, s+o+p+r+a+n+o == 82, opt.icl());
92-
post(*this, t+h+e+m+e == 72, opt.icl());
93-
post(*this, v+i+o+l+i+n == 100, opt.icl());
94-
post(*this, w+a+l+t+z == 34, opt.icl());
75+
rel(*this, b+a+l+l+e+t == 45, opt.icl());
76+
rel(*this, c+e+l+l+o == 43, opt.icl());
77+
rel(*this, c+o+n+c+e+r+t == 74, opt.icl());
78+
rel(*this, f+l+u+t+e == 30, opt.icl());
79+
rel(*this, f+u+g+u+e == 50, opt.icl());
80+
rel(*this, g+l+e+e == 66, opt.icl());
81+
rel(*this, j+a+z+z == 58, opt.icl());
82+
rel(*this, l+y+r+e == 47, opt.icl());
83+
rel(*this, o+b+o+e == 53, opt.icl());
84+
rel(*this, o+p+e+r+a == 65, opt.icl());
85+
rel(*this, p+o+l+k+a == 59, opt.icl());
86+
rel(*this, q+u+a+r+t+e+t == 50, opt.icl());
87+
rel(*this, s+a+x+o+p+h+o+n+e == 134, opt.icl());
88+
rel(*this, s+c+a+l+e == 51, opt.icl());
89+
rel(*this, s+o+l+o == 37, opt.icl());
90+
rel(*this, s+o+n+g == 61, opt.icl());
91+
rel(*this, s+o+p+r+a+n+o == 82, opt.icl());
92+
rel(*this, t+h+e+m+e == 72, opt.icl());
93+
rel(*this, v+i+o+l+i+n == 100, opt.icl());
94+
rel(*this, w+a+l+t+z == 34, opt.icl());
9595

9696
distinct(*this, le, opt.icl());
9797

examples/bacp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class BACP : public MinimizeScript {
144144
BoolVarArgs xij(*this, numberOfCourses, 0, 1);
145145
IntArgs t(numberOfCourses);
146146
for (int i=0; i<numberOfCourses; i++) {
147-
post(*this, tt(eqv(~(x[i]==j), xij[i])));
147+
rel(*this, eqv((x[i]==j), xij[i]));
148148
t[i] = curr.courses[i].credit;
149149
}
150150
// sum over all t*(xi==j) is load of period i
@@ -155,7 +155,7 @@ class BACP : public MinimizeScript {
155155

156156
// Precedence
157157
for (const char** prereq = curr.prereqs; *prereq != 0; prereq+=2) {
158-
post(*this, x[courseMap[*prereq]] < x[courseMap[*(prereq+1)]]);
158+
rel(*this, x[courseMap[*prereq]] < x[courseMap[*(prereq+1)]]);
159159
}
160160

161161
// Optimization criterion: minimize u

examples/bibd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class BIBD : public Script {
118118
for (int i2=i1+1; i2<opt.v; i2++) {
119119
BoolVarArgs row(opt.b);
120120
for (int j=0; j<opt.b; j++)
121-
row[j] = post(*this, p(j,i1) && p(j,i2));
121+
row[j] = expr(*this, p(j,i1) && p(j,i2));
122122
linear(*this, row, IRT_EQ, opt.lambda);
123123
}
124124

examples/black-hole.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ class BlackHole : public Script {
243243
element(*this, modtable, x[i+1], x2);
244244
const int dr[2] = {1, 12};
245245
IntVar diff(*this, IntSet(dr, 2));
246-
post(*this, abs(*this, minus(*this, x1, x2, ICL_DOM), ICL_DOM)
247-
== diff, ICL_DOM);
246+
rel(*this, abs(*this, minus(*this, x1, x2, ICL_DOM), ICL_DOM)
247+
== diff, ICL_DOM);
248248
}
249249
} else if (opt.propagation() == PROPAGATION_DFA) {
250250
// Build table for allowed tuples
@@ -284,7 +284,7 @@ class BlackHole : public Script {
284284
// A card must be played before the one under it.
285285
for (int i = 17; i--; )
286286
for (int j = 2; j--; )
287-
post(*this, y[layout[i][j]] < y[layout[i][j+1]]);
287+
rel(*this, y[layout[i][j]] < y[layout[i][j+1]]);
288288

289289
// Compute and break the conditional symmetries that are dependent
290290
// on the current layout.
@@ -311,21 +311,21 @@ class BlackHole : public Script {
311311
BoolVarArgs ba;
312312
// Both cards played after the ones on top of them
313313
for (int i = 0; i < layer[o1]; ++i)
314-
ba << post(*this, ~(y[layout[pile[o1]][i]] < y[o2]));
314+
ba << expr(*this, (y[layout[pile[o1]][i]] < y[o2]));
315315
for (int i = 0; i < layer[o2]; ++i)
316-
ba << post(*this, ~(y[layout[pile[o2]][i]] < y[o1]));
316+
ba << expr(*this, (y[layout[pile[o2]][i]] < y[o1]));
317317
// Both cards played before the ones under them
318318
for (int i = layer[o1]+1; i < 3; ++i)
319-
ba << post(*this, ~(y[o2] < y[layout[pile[o1]][i]]));
319+
ba << expr(*this, (y[o2] < y[layout[pile[o1]][i]]));
320320
for (int i = layer[o2]+1; i < 3; ++i)
321-
ba << post(*this, ~(y[o1] < y[layout[pile[o2]][i]]));
321+
ba << expr(*this, (y[o1] < y[layout[pile[o2]][i]]));
322322
// Cond holds when all the above holds
323323
BoolVar cond(*this, 0, 1);
324324
rel(*this, BOT_AND, ba, cond);
325325

326326
// If cond is fulfilled, then we can order the cards
327327
// cond -> (y[o1] < y[o2])
328-
post(*this, tt(!cond || ~(y[o1] < y[o2])));
328+
rel(*this, !cond || (y[o1] < y[o2]));
329329
}
330330
}
331331
}

examples/car-sequencing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class CarSequencing : public Script {
308308
// Count number of end and stallss
309309
count(*this, s, stallval, IRT_EQ, nstall);
310310
count(*this, s, endval, IRT_EQ, nend);
311-
post(*this, nstall+nend == maxstall);
311+
rel(*this, nstall+nend == maxstall);
312312

313313
// Make sure nothing is overloaded
314314
IntSet one(1, 1);
@@ -335,7 +335,7 @@ class CarSequencing : public Script {
335335
REG r = *REG(notend) + REG(notstallend) + *REG(endval);
336336
extensional(*this, s, r);
337337
for (int pos = s.size()-1, i = 0; i < maxstall; ++i, --pos) {
338-
post(*this, imp(~(nend > i), ~(s[pos]==endval)));
338+
rel(*this, imp((nend > i), (s[pos]==endval)));
339339
}
340340
} break;
341341
case PROP_CUSTOM: {

examples/crew.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,27 @@ class Crew : public Script {
108108

109109
for (int i=0; i<noOfFlights; i++) {
110110
// The flight has staff as required by the specification
111-
post(*this, cardinality(*this, flight[i]) == requiredCrew[i].staff);
111+
rel(*this, cardinality(*this, flight[i]) == requiredCrew[i].staff);
112112

113113
// Enough members of different categories are on board
114-
post(*this, cardinality(*this,flight[i] & stewardsDS) >=
115-
requiredCrew[i].stewards);
116-
post(*this, cardinality(*this,flight[i] & hostessesDS) >=
117-
requiredCrew[i].hostesses);
118-
post(*this, cardinality(*this,flight[i] & spanishDS) >=
119-
requiredCrew[i].spanish);
120-
post(*this, cardinality(*this,flight[i] & frenchDS) >=
121-
requiredCrew[i].french);
122-
post(*this, cardinality(*this,flight[i] & germanDS) >=
123-
requiredCrew[i].german);
114+
rel(*this, cardinality(*this,flight[i] & stewardsDS) >=
115+
requiredCrew[i].stewards);
116+
rel(*this, cardinality(*this,flight[i] & hostessesDS) >=
117+
requiredCrew[i].hostesses);
118+
rel(*this, cardinality(*this,flight[i] & spanishDS) >=
119+
requiredCrew[i].spanish);
120+
rel(*this, cardinality(*this,flight[i] & frenchDS) >=
121+
requiredCrew[i].french);
122+
rel(*this, cardinality(*this,flight[i] & germanDS) >=
123+
requiredCrew[i].german);
124124
}
125125

126126
// No crew member of flight i works on flights i+1 and i+2
127127
for (int i=0; i<noOfFlights-2; i++) {
128-
post(*this, flight[i] || flight[i+1]);
129-
post(*this, flight[i] || flight[i+2]);
128+
rel(*this, flight[i] || flight[i+1]);
129+
rel(*this, flight[i] || flight[i+2]);
130130
}
131-
post(*this, flight[noOfFlights-2] || flight[noOfFlights-1]);
131+
rel(*this, flight[noOfFlights-2] || flight[noOfFlights-1]);
132132

133133
branch(*this, flight, SET_VAR_NONE, SET_VAL_MIN_INC);
134134
}

examples/crowded-chess.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,14 @@ class CrowdedChess : public Script {
307307
if (opt.propagation() == PROP_TUPLE_SET) {
308308
IntVarArgs b(s.size());
309309
for (int i = s.size(); i--; )
310-
b[i] = channel(*this, post(*this, ~(s[i] == B)));
310+
b[i] = channel(*this, expr(*this, (s[i] == B)));
311311
extensional(*this, b, bishops, EPK_DEF, opt.icl());
312312
}
313313

314314
// Handle knigths
315315
// Connect knigths to board
316316
for(int i = n*n; i--; )
317-
knights[i] = post(*this, ~(s[i] == K));
317+
knights[i] = expr(*this, (s[i] == K));
318318
knight_constraints();
319319

320320

examples/domino.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Domino : public Script {
104104
// Initialize the separator column in the board
105105
for (int i=0; i<height; i++) {
106106
board[i*(width+1)+8] = -1;
107-
post(*this, x[i*(width+1)+8]==28);
107+
rel(*this, x[i*(width+1)+8]==28);
108108
}
109109

110110
// Variables representing the coordinates of the first

examples/donald.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Donald : public Script {
7575

7676
switch (opt.model()) {
7777
case MODEL_SINGLE:
78-
post(*this, 100000*d+10000*o+1000*n+100*a+10*l+d
78+
rel(*this, 100000*d+10000*o+1000*n+100*a+10*l+d
7979
+ 100000*g+10000*e+1000*r+100*a+10*l+d
8080
== 100000*r+10000*o+1000*b+100*e+10*r+t,
8181
opt.icl());
@@ -84,12 +84,12 @@ class Donald : public Script {
8484
{
8585
IntVar c0(*this,0,1), c1(*this,0,1), c2(*this,0,1),
8686
c3(*this,0,1), c4(*this,0,1);
87-
post(*this, d+d == t+10*c0, opt.icl());
88-
post(*this, c0+l+l == r+10*c1, opt.icl());
89-
post(*this, c1+a+a == e+10*c2, opt.icl());
90-
post(*this, c2+n+r == b+10*c3, opt.icl());
91-
post(*this, c3+o+e == o+10*c4, opt.icl());
92-
post(*this, c4+d+g == r, opt.icl());
87+
rel(*this, d+d == t+10*c0, opt.icl());
88+
rel(*this, c0+l+l == r+10*c1, opt.icl());
89+
rel(*this, c1+a+a == e+10*c2, opt.icl());
90+
rel(*this, c2+n+r == b+10*c3, opt.icl());
91+
rel(*this, c3+o+e == o+10*c4, opt.icl());
92+
rel(*this, c4+d+g == r, opt.icl());
9393
}
9494
break;
9595
default: GECODE_NEVER;

0 commit comments

Comments
 (0)