Changes of my Gecode models for version 3.4.0
See Gecode version 3.4 released for a description of things that was changed in Gecode version 3.4.0.
One major change was replacement of
For example, in alldifferent_except_0.cpp (decomposition of the global constraint
Another example is from who_killed_agatha2.cpp. This older code segment:
A comment: I will very soon also blog about a couple (about 100) new Gecode models that also - as much as possible - use the new syntax.
One major change was replacement of
tt, imp, eqv, ~
for logical implication, equivalence, and reification to a neater syntax, as well as post
has been replaced with rel
and expr
.
For example, in alldifferent_except_0.cpp (decomposition of the global constraint
all different except 0
), this code segment
post(space, tt(imp(x[i] != c && x[j] != c, // => x[i] != x[j])), icl );is now written
rel(space, (x[i] != c && x[j] != c) >> (x[i] != x[j]), icl );This is a more direct syntax which I like very much. Since I'm a lazy person, I love this kind of syntactic sugar.
Another example is from who_killed_agatha2.cpp. This older code segment:
post(*this, tt( imp(hates_m2(i, agatha) == 1, hates_m2(i, butler) == 1)), opt.icl() );is now written
rel(*this, (hates_m2(i, agatha) == 1) >> (hates_m2(i, butler) == 1), opt.icl());Here are all the changed models, which are available at my Gecode page. Many of them required just a simple change of
post()
to rel()
; then there is no special comment below.
A comment: I will very soon also blog about a couple (about 100) new Gecode models that also - as much as possible - use the new syntax.
- alldifferent_except_0.cpp. See above.
- assignment.cpp
- building_a_house.cpp
- bus_schedule.cpp
- calculs_d_enfer.cpp
- circuit_orbit.cpp
- clique.cpp
Replacedpost(*this, tt(imp( x_bool[i] == 1 && x_bool[j] == 1, // -> b)),
withrel(*this, (x_bool[i] == 1 && x_bool[j] == 1) >> b
- coins3.cpp
- coins_grid.cpp
- crossword.cpp I remove this model since it's using the obsolete matrix element trick, and is replaced with crossword2.cpp
- crossword2.cpp
- donald_gerald_robert.cpp
- furniture_moving.cpp
- global_contiguity.cpp
Replaced:post(*this, tt( eqv( y[i] == 1, // <=> x[i] == 1)))
withrel(*this, (y[i] == 1) == (x[i] == 1))
- hidato.cpp
- house2.cpp
- least_diff.cpp
- map.cpp
- nadel.cpp
- organize_day.cpp
- send_more_money_any_base.cpp
- seseman.cpp
- set_covering_deployment.cpp
- sonet.cpp
- stable_marriage.cpp
Replaced reifications.BoolVar b1 = post(*this, ~(rankMen[m*n+w] < rankMen_res)); BoolVar b2 = post(*this, ~(rankWomen_res < rankWomen[w*n+m])); post(*this, tt(imp(b1, b2)), opt.icl());
withBoolVar b1 = expr(*this, (rankMen[m*n+w] < rankMen_res)); BoolVar b2 = expr(*this, (rankWomen_res < rankWomen[w*n+m])); rel(*this, b1 >> b2, opt.icl());
Note thatpost
is here replaced withexpr
: - traffic_lights.cpp
- who_killed_agatha.cpp
- who_killed_agatha2.cpp See above.
Another change is the use of the expressionelement
instead of the constraintelement
- I.e. instead ofelement(*this, hates_m2, the_victim, the_killer , IntVar(*this,1,1), opt.icl());
we userel(*this, element(hates,the_killer*n+the_victim) == 1, opt.icl());
- word_square.cpp has been removed since it used some obsolete construct and i replaced with a better model: word_square2.cpp
- young_tableaux.cpp
Remodelled the constraints that the rows and columns should be increasing:for(int i = 0; i < n; i++) { rel(*this, m.row(i),IRT_LQ); rel(*this, m.col(i),IRT_LQ); }
- zebra.cpp
Replacedpost(space, abs(space, minus(space, x, y, icl), icl) == 1, icl);
withrel(space, abs(x-y) == 1, icl);