Skip to content

Commit 97b2120

Browse files
author
Christian Schulte
committed
BranchingDesc -> Choice
git-svn-id: file:///Users/tack/GecodeGitMigration/gecode-svn-mirror/gecode/trunk@9628 e85b7adc-8362-4630-8c63-7469d557c915
1 parent fa0b360 commit 97b2120

31 files changed

+541
-541
lines changed

changelog.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ Date: ?
7272
[DESCRIPTION]
7373
The next release.
7474

75+
[ENTRY]
76+
Module: kernel
77+
What: change
78+
Rank: major
79+
[DESCRIPTION]
80+
A branching is now a brancher and a branching description is now a choice.
81+
[MORE]
82+
Classes and member functions have been renamed accordingly. The
83+
change is necessary due to proper explanation in the forthcoming
84+
"Programming with Gecode".
85+
7586
[ENTRY]
7687
Module: search
7788
What: bug

doxygen/doxygen.hh.in

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,16 +524,14 @@ class Gecode::Branching. A common abstraction for defining
524524
branchings based on view and value selection is provided by the
525525
class Gecode::ViewValBranching.
526526

527-
\section GlossaryBranchingDesc Branching description
527+
\section GlossaryChoice Choice
528528

529-
A branching description speeds up recomputation by providing
530-
batch recomputation. It is created by a branching (\ref
529+
A choice speeds up recomputation by providing
530+
path recomputation. It is created by a branching (\ref
531531
GlossaryBranching) and allows to replay the effect of that
532532
branching without the need to first perform constraint
533-
propagation. The base-class for branching descriptions is
534-
Gecode::BranchingDesc. An example for a branching description
535-
that works together with branchings based on view and value
536-
selection is Gecode::PosValDesc.
533+
propagation. The base-class for choices is
534+
Gecode::Choice.
537535

538536
\section GlossarySpace Computation space
539537

examples/black-hole.cpp

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,21 @@ class BlackHoleBranch : Branching {
101101
ViewArray<Int::IntView> x;
102102
/// Cache of last computed decision
103103
mutable int pos, val;
104-
/// Branching description
105-
class Description : public BranchingDesc {
104+
/// Choice
105+
class Choice : public Gecode::Choice {
106106
public:
107107
/// Position of variable
108108
int pos;
109109
/// Value of variable
110110
int val;
111-
/** Initialize description for branching \a b, number of
112-
* alternatives \a a, position \a pos0, and value \a val0.
111+
/** Initialize description for branching \a b, position \a pos0,
112+
* and value \a val0.
113113
*/
114-
Description(const Branching& b, unsigned int a, int pos0, int val0)
115-
: BranchingDesc(b,a), pos(pos0), val(val0) {}
114+
Choice(const Branching& b, int pos0, int val0)
115+
: Gecode::Choice(b,2), pos(pos0), val(val0) {}
116116
/// Report size occupied
117117
virtual size_t size(void) const {
118-
return sizeof(Description);
118+
return sizeof(Choice);
119119
}
120120
};
121121

@@ -131,38 +131,33 @@ class BlackHoleBranch : Branching {
131131
public:
132132
/// Check status of branching, return true if alternatives left.
133133
virtual bool status(const Space&) const {
134-
for (pos = 0; pos < x.size(); ++pos) {
134+
for (pos = 0; pos < x.size(); ++pos)
135135
if (!x[pos].assigned()) {
136136
int w = 4;
137-
for (Int::ViewValues<Int::IntView> vals(x[pos]); vals(); ++vals) {
137+
for (Int::ViewValues<Int::IntView> vals(x[pos]); vals(); ++vals)
138138
if (layer[vals.val()] < w) {
139139
val = vals.val();
140140
if ((w = layer[vals.val()]) == 0) break;
141141
}
142-
}
143142
return true;
144143
}
145-
}
146144
// No non-assigned variables left
147145
return false;
148146
}
149-
/// Return branching description
150-
virtual BranchingDesc* description(Space&) {
147+
/// Return choice
148+
virtual Choice* choice(Space&) {
151149
assert(pos >= 0 && pos < x.size() && val >= 1 && val < 52);
152-
return new Description(*this, 2, pos, val);
150+
return new Choice(*this, pos, val);
153151
}
154-
/// Perform commit for branching description \a d and alternative \a a.
155-
virtual ExecStatus commit(Space& home, const BranchingDesc& d,
152+
/// Perform commit for choice \a _c and alternative \a a.
153+
virtual ExecStatus commit(Space& home, const Gecode::Choice& _c,
156154
unsigned int a) {
157-
const Description& desc =
158-
static_cast<const Description&>(d);
155+
const Choice& c = static_cast<const Choice&>(_c);
159156
pos = val = -1;
160157
if (a)
161-
return me_failed(x[desc.pos].nq(home, desc.val))
162-
? ES_FAILED : ES_OK;
158+
return me_failed(x[c.pos].nq(home, c.val)) ? ES_FAILED : ES_OK;
163159
else
164-
return me_failed(x[desc.pos].eq(home, desc.val))
165-
? ES_FAILED : ES_OK;
160+
return me_failed(x[c.pos].eq(home, c.val)) ? ES_FAILED : ES_OK;
166161
}
167162
/// Copy branching
168163
virtual Actor* copy(Space& home, bool share) {

examples/knights.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@ class Warnsdorff : public Branching {
5959
ViewArray<Int::IntView> x;
6060
/// Next variable to branch on
6161
mutable int start;
62-
/// Branching description
63-
class Description : public BranchingDesc {
62+
/// Choice
63+
class Choice : public Gecode::Choice {
6464
public:
6565
/// Position of variable
6666
int pos;
6767
/// Value of variable
6868
int val;
69-
/** Initialize description for branching \a b, number of
70-
* alternatives \a a, position \a pos0, and value \a val0.
69+
/** Initialize choice for branching \a b, position \a pos0,
70+
* and value \a val0.
7171
*/
72-
Description(const Branching& b, unsigned int a, int pos0, int val0)
73-
: BranchingDesc(b,a), pos(pos0), val(val0) {}
72+
Choice(const Branching& b, int pos0, int val0)
73+
: Gecode::Choice(b,2), pos(pos0), val(val0) {}
7474
/// Report size occupied
7575
virtual size_t size(void) const {
76-
return sizeof(Description);
76+
return sizeof(Choice);
7777
}
7878
};
7979

@@ -97,8 +97,8 @@ class Warnsdorff : public Branching {
9797
return false;
9898
}
9999
}
100-
/// Return branching description
101-
virtual BranchingDesc* description(Space&) {
100+
/// Return choice
101+
virtual Gecode::Choice* choice(Space&) {
102102
Int::ViewValues<Int::IntView> iv(x[start]);
103103
int n = iv.val();
104104
unsigned int min = x[n].size();
@@ -111,18 +111,16 @@ class Warnsdorff : public Branching {
111111
}
112112
++iv;
113113
}
114-
return new Description(*this, 2, start, n);
114+
return new Choice(*this, start, n);
115115
}
116-
/// Perform commit for branching description \a d and alternative \a a
117-
virtual ExecStatus commit(Space& home, const BranchingDesc& d,
116+
/// Perform commit for choice \a _c and alternative \a a
117+
virtual ExecStatus commit(Space& home, const Gecode::Choice& _c,
118118
unsigned int a) {
119-
const Description& desc = static_cast<const Description&>(d);
119+
const Choice& c = static_cast<const Choice&>(_c);
120120
if (a == 0)
121-
return me_failed(x[desc.pos].eq(home, desc.val))
122-
? ES_FAILED : ES_OK;
121+
return me_failed(x[c.pos].eq(home, c.val)) ? ES_FAILED : ES_OK;
123122
else
124-
return me_failed(x[desc.pos].nq(home, desc.val))
125-
? ES_FAILED : ES_OK;
123+
return me_failed(x[c.pos].nq(home, c.val)) ? ES_FAILED : ES_OK;
126124
}
127125
/// Copy branching
128126
virtual Actor* copy(Space& home, bool share) {

examples/queen-armies.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class QueenArmies : public MaximizeScript {
158158
os << "Number of white queens: " << q << std::endl << std::endl;
159159
}
160160

161-
/** \brief Custom branching for Peacaeble queens.
161+
/** \brief Custom branching for Peacable queens
162162
*
163163
* Custom branching that tries to place white queens so that they
164164
* maximise the amount of un-attacked squares that become attacked.
@@ -169,21 +169,21 @@ class QueenArmies : public MaximizeScript {
169169
private:
170170
/// Cache of last computed decision
171171
mutable int pos;
172-
/// Branching description
173-
class Description : public BranchingDesc {
172+
/// Choice
173+
class Choice : public Gecode::Choice {
174174
public:
175175
/// Position of variable
176176
int pos;
177177
/// Value of variable
178178
bool val;
179-
/** Initialize description for branching \a b, number of
180-
* alternatives \a a, position \a pos0, and value \a val0.
179+
/** Initialize choice for branching \a b, position \a pos0,
180+
* and value \a val0.
181181
*/
182-
Description(const Branching& b, unsigned int a, int pos0, bool val0)
183-
: BranchingDesc(b,a), pos(pos0), val(val0) {}
182+
Choice(const Branching& b, int pos0, bool val0)
183+
: Gecode::Choice(b,2), pos(pos0), val(val0) {}
184184
/// Report size occupied
185185
virtual size_t size(void) const {
186-
return sizeof(Description);
186+
return sizeof(Choice);
187187
}
188188
};
189189

@@ -215,20 +215,20 @@ class QueenArmies : public MaximizeScript {
215215
if (pos == -1) return false;
216216
return true;
217217
}
218-
/// Return branching description
219-
virtual BranchingDesc* description(Space&) {
218+
/// Return choice
219+
virtual Gecode::Choice* choice(Space&) {
220220
assert(pos != -1);
221-
return new Description(*this, 2, pos, true);
221+
return new Choice(*this, pos, true);
222222
}
223-
/** \brief Perform commit for branching description \a d and
223+
/** \brief Perform commit for choice \a _c and
224224
* alternative \a a.
225225
*/
226-
virtual ExecStatus commit(Space& home, const BranchingDesc& d,
226+
virtual ExecStatus commit(Space& home, const Gecode::Choice& _c,
227227
unsigned int a) {
228228
QueenArmies& q = static_cast<QueenArmies&>(home);
229-
const Description& pvd = static_cast<const Description&>(d);
230-
bool val = a == 0 ? pvd.val : !pvd.val;
231-
return me_failed(Int::BoolView(q.w[pvd.pos]).eq(q, val))
229+
const Choice& c = static_cast<const Choice&>(_c);
230+
bool val = (a == 0) ? c.val : !c.val;
231+
return me_failed(Int::BoolView(q.w[c.pos]).eq(q, val))
232232
? ES_FAILED
233233
: ES_OK;
234234
}

examples/radiotherapy.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,17 @@ class Radiotherapy : public MinimizeScript {
217217
};
218218
/// Weighted ordering of rows
219219
SharedArray<Idx> index;
220-
/// Description that only signals failure or success
221-
class Description : public BranchingDesc {
220+
/// Choice that only signals failure or success
221+
class Choice : public Gecode::Choice {
222222
public:
223223
/// Whether branching should fail
224224
bool fail;
225-
/// Initialize description for branching \a b
226-
Description(const Branching& b, bool fail0)
227-
: BranchingDesc(b,1), fail(fail0) {}
225+
/// Initialize choice for branching \a b
226+
Choice(const Branching& b, bool fail0)
227+
: Gecode::Choice(b,1), fail(fail0) {}
228228
/// Report size occupied
229229
virtual size_t size(void) const {
230-
return sizeof(Description);
230+
return sizeof(Choice);
231231
}
232232
};
233233
/// Construct branching
@@ -270,7 +270,7 @@ class Radiotherapy : public MinimizeScript {
270270
return ri;
271271
}
272272

273-
virtual BranchingDesc* description(Space& home) {
273+
virtual Gecode::Choice* choice(Space& home) {
274274
done = true;
275275
Radiotherapy& rt = static_cast<Radiotherapy&>(home);
276276

@@ -300,10 +300,10 @@ class Radiotherapy : public MinimizeScript {
300300
}
301301
}
302302

303-
return new Description(*this, fail);
303+
return new Choice(*this, fail);
304304
}
305-
virtual ExecStatus commit(Space&, const BranchingDesc& d, unsigned int) {
306-
return static_cast<const Description&>(d).fail ? ES_FAILED : ES_OK;
305+
virtual ExecStatus commit(Space&, const Gecode::Choice& _c, unsigned int) {
306+
return static_cast<const Choice&>(_c).fail ? ES_FAILED : ES_OK;
307307
}
308308
/// Copy branching
309309
virtual Actor* copy(Space& home, bool share) {

examples/steel-mill.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -320,21 +320,21 @@ class SteelMill : public MinimizeScript {
320320
protected:
321321
/// Cache of first unassigned value
322322
mutable int start;
323-
/// Branching description
324-
class Description : public BranchingDesc {
323+
/// Choice
324+
class Choice : public Gecode::Choice {
325325
public:
326326
/// Position of variable
327327
int pos;
328328
/// Value of variable
329329
int val;
330-
/** Initialize description for branching \a b, number of
330+
/** Initialize choice for branching \a b, number of
331331
* alternatives \a a, position \a pos0, and value \a val0.
332332
*/
333-
Description(const Branching& b, unsigned int a, int pos0, int val0)
334-
: BranchingDesc(b,a), pos(pos0), val(val0) {}
333+
Choice(const Branching& b, unsigned int a, int pos0, int val0)
334+
: Gecode::Choice(b,a), pos(pos0), val(val0) {}
335335
/// Report size occupied
336336
virtual size_t size(void) const {
337-
return sizeof(Description);
337+
return sizeof(Choice);
338338
}
339339
};
340340

@@ -358,8 +358,8 @@ class SteelMill : public MinimizeScript {
358358
// No non-assigned orders left
359359
return false;
360360
}
361-
/// Return branching description
362-
virtual BranchingDesc* description(Space& home) {
361+
/// Return choice
362+
virtual Gecode::Choice* choice(Space& home) {
363363
SteelMill& sm = static_cast<SteelMill&>(home);
364364
assert(!sm.slab[start].assigned());
365365
// Find order with a) minimum size, b) largest weight
@@ -386,19 +386,18 @@ class SteelMill : public MinimizeScript {
386386
++firstzero;
387387
assert(pos < sm.nslabs &&
388388
val < sm.norders);
389-
return new Description(*this, val<firstzero ? 2 : 1, pos, val);
389+
return new Choice(*this, (val<firstzero) ? 2 : 1, pos, val);
390390
}
391-
/// Perform commit for branching description \a d and alternative \a a.
392-
virtual ExecStatus commit(Space& home, const BranchingDesc& d,
391+
/// Perform commit for choice \a _c and alternative \a a
392+
virtual ExecStatus commit(Space& home, const Gecode::Choice& _c,
393393
unsigned int a) {
394394
SteelMill& sm = static_cast<SteelMill&>(home);
395-
const Description& desc =
396-
static_cast<const Description&>(d);
395+
const Choice& c = static_cast<const Choice&>(_c);
397396
if (a)
398-
return me_failed(Int::IntView(sm.slab[desc.pos]).nq(home, desc.val))
397+
return me_failed(Int::IntView(sm.slab[c.pos]).nq(home, c.val))
399398
? ES_FAILED : ES_OK;
400399
else
401-
return me_failed(Int::IntView(sm.slab[desc.pos]).eq(home, desc.val))
400+
return me_failed(Int::IntView(sm.slab[c.pos]).eq(home, c.val))
402401
? ES_FAILED : ES_OK;
403402
}
404403
/// Copy branching

0 commit comments

Comments
 (0)