Skip to content

Commit 7a6b298

Browse files
committed
Added
1 parent c5c1df3 commit 7a6b298

File tree

86 files changed

+23711
-0
lines changed

Some content is hidden

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

86 files changed

+23711
-0
lines changed

doc/6.2.0/MPG.7z

121 KB
Binary file not shown.

doc/6.2.0/MPG.bib

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@InCollection{MPG:M:6.2.0,
2+
Author = "Christian Schulte and Guido Tack and Mikael Z. Lagerkvist",
3+
Title = "Modeling",
4+
Editor = "Christian Schulte and Guido Tack and Mikael Z. Lagerkvist",
5+
Booktitle = "Modeling and Programming with Gecode",
6+
Year = 2019,
7+
Note = "Corresponds to Gecode 6.2.0",
8+
}
9+
@InCollection{MPG:C:6.2.0,
10+
Author = "Christian Schulte and Guido Tack and Mikael Z. Lagerkvist",
11+
Title = "Case studies",
12+
Editor = "Christian Schulte and Guido Tack and Mikael Z. Lagerkvist",
13+
Booktitle = "Modeling and Programming with Gecode",
14+
Year = 2019,
15+
Note = "Corresponds to Gecode 6.2.0",
16+
}
17+
@InCollection{MPG:P:6.2.0,
18+
Author = "Christian Schulte and Guido Tack",
19+
Title = "Programming propagators",
20+
Editor = "Christian Schulte and Guido Tack and Mikael Z. Lagerkvist",
21+
Booktitle = "Modeling and Programming with Gecode",
22+
Year = 2019,
23+
Note = "Corresponds to Gecode 6.2.0",
24+
}
25+
@InCollection{MPG:B:6.2.0,
26+
Author = "Christian Schulte",
27+
Title = "Programming branchers",
28+
Editor = "Christian Schulte and Guido Tack and Mikael Z. Lagerkvist",
29+
Booktitle = "Modeling and Programming with Gecode",
30+
Year = 2019,
31+
Note = "Corresponds to Gecode 6.2.0",
32+
}
33+
@InCollection{MPG:V:6.2.0,
34+
Author = "Christian Schulte",
35+
Title = "Programming variables",
36+
Editor = "Christian Schulte and Guido Tack and Mikael Z. Lagerkvist",
37+
Booktitle = "Modeling and Programming with Gecode",
38+
Year = 2019,
39+
Note = "Corresponds to Gecode 6.2.0",
40+
}
41+
@InCollection{MPG:S:6.2.0,
42+
Author = "Christian Schulte",
43+
Title = "Programming search engines",
44+
Editor = "Christian Schulte and Guido Tack and Mikael Z. Lagerkvist",
45+
Booktitle = "Modeling and Programming with Gecode",
46+
Year = 2019,
47+
Note = "Corresponds to Gecode 6.2.0",
48+
}

doc/6.2.0/MPG.pdf

2.16 MB
Binary file not shown.

doc/6.2.0/MPG.tar.gz

307 KB
Binary file not shown.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Authors:
3+
* Christian Schulte <[email protected]>
4+
*
5+
* Copyright:
6+
* Christian Schulte, 2008-2019
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining
9+
* a copy of this software, to deal in the software without restriction,
10+
* including without limitation the rights to use, copy, modify, merge,
11+
* publish, distribute, sublicense, and/or sell copies of the software,
12+
* and to permit persons to whom the software is furnished to do so, subject
13+
* to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be
16+
* included in all copies or substantial portions of the software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25+
*
26+
*/
27+
28+
class BoolDomExpr : public BoolExpr::Misc {
29+
protected:
30+
IntVar x; int l, u;
31+
public:
32+
BoolDomExpr(IntVar x0, int l0, int u0)
33+
: x(x0), l(l0), u(u0) {}
34+
// post member function
35+
virtual void post(Home home, BoolVar b, bool neg,
36+
IntPropLevel ipl) {
37+
if (neg) {
38+
const int nlu[2][2] = { { Int::Limits::min, l-1 },
39+
{ u+1, Int::Limits::max } };
40+
dom(home, x, IntSet(nlu,2), b);
41+
} else {
42+
dom(home, x, l, u, b);
43+
}
44+
}
45+
virtual ~ReDomExpr(void) {}
46+
};
47+
// create Boolean domain expression
48+
BoolExpr dom(IntVar x, int l, int u) {
49+
return BoolExpr(new BoolDomExpr(x,l,u));
50+
}

doc/6.2.0/MPG/assign-min.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Authors:
3+
* Christian Schulte <[email protected]>
4+
*
5+
* Copyright:
6+
* Christian Schulte, 2008-2019
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining
9+
* a copy of this software, to deal in the software without restriction,
10+
* including without limitation the rights to use, copy, modify, merge,
11+
* publish, distribute, sublicense, and/or sell copies of the software,
12+
* and to permit persons to whom the software is furnished to do so, subject
13+
* to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be
16+
* included in all copies or substantial portions of the software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25+
*
26+
*/
27+
28+
#include <gecode/int.hh>
29+
30+
using namespace Gecode;
31+
32+
class AssignMin : public Brancher {
33+
protected:
34+
ViewArray<Int::IntView> x;
35+
mutable int start;
36+
class PosVal : public Choice {
37+
public:
38+
int pos; int val;
39+
PosVal(const AssignMin& b, int p, int v)
40+
: Choice(b,1), pos(p), val(v) {}
41+
virtual void archive(Archive& e) const {
42+
Choice::archive(e);
43+
e << pos << val;
44+
}
45+
};
46+
public:
47+
AssignMin(Home home, ViewArray<Int::IntView>& x0)
48+
: Brancher(home), x(x0), start(0) {}
49+
static void post(Home home, ViewArray<Int::IntView>& x) {
50+
(void) new (home) AssignMin(home,x);
51+
}
52+
virtual size_t dispose(Space& home) {
53+
(void) Brancher::dispose(home);
54+
return sizeof(*this);
55+
}
56+
AssignMin(Space& home, AssignMin& b)
57+
: Brancher(home,b), start(b.start) {
58+
x.update(home,b.x);
59+
}
60+
virtual Brancher* copy(Space& home) {
61+
return new (home) AssignMin(home,*this);
62+
}
63+
virtual bool status(const Space& home) const {
64+
for (int i=start; i<x.size(); i++)
65+
if (!x[i].assigned()) {
66+
start = i; return true;
67+
}
68+
return false;
69+
}
70+
virtual Choice* choice(Space& home) {
71+
return new PosVal(*this,start,x[start].min());
72+
}
73+
virtual Choice* choice(const Space&, Archive& e) {
74+
int pos, val;
75+
e >> pos >> val;
76+
return new PosVal(*this, pos, val);
77+
}
78+
virtual ExecStatus commit(Space& home,
79+
const Choice& c,
80+
unsigned int a) {
81+
const PosVal& pv = static_cast<const PosVal&>(c);
82+
int pos=pv.pos, val=pv.val;
83+
return me_failed(x[pos].eq(home,val)) ? ES_FAILED : ES_OK;
84+
}
85+
virtual void print(const Space& home, const Choice& c,
86+
unsigned int a,
87+
std::ostream& o) const {
88+
const PosVal& pv = static_cast<const PosVal&>(c);
89+
int pos=pv.pos, val=pv.val;
90+
o << "x[" << pos << "] = " << val;
91+
}
92+
};
93+
94+
void assignmin(Home home, const IntVarArgs& x) {
95+
if (home.failed()) return;
96+
ViewArray<Int::IntView> y(home,x);
97+
AssignMin::post(home,y);
98+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Authors:
3+
* Christian Schulte <[email protected]>
4+
*
5+
* Copyright:
6+
* Christian Schulte, 2008-2019
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining
9+
* a copy of this software, to deal in the software without restriction,
10+
* including without limitation the rights to use, copy, modify, merge,
11+
* publish, distribute, sublicense, and/or sell copies of the software,
12+
* and to permit persons to whom the software is furnished to do so, subject
13+
* to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be
16+
* included in all copies or substantial portions of the software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25+
*
26+
*/
27+
28+
#include <gecode/kernel.hh>
29+
30+
using namespace Gecode;
31+
32+
class Edge {
33+
protected:
34+
Edge* p;
35+
const Choice* ch;
36+
unsigned int a;
37+
public:
38+
Edge(Space* s, Edge* e)
39+
: p(e), ch(s->choice()), a(0) {}
40+
void next(void) {
41+
a++;
42+
}
43+
Space* commit(Space* s) const {
44+
s->commit(*ch,a); return s;
45+
}
46+
Space* recompute(Space* r) const {
47+
return commit((p == NULL) ? r->clone() : p->recompute(r));
48+
}
49+
~Edge(void) {
50+
delete ch;
51+
}
52+
};
53+
54+
void bab(Space* s, Space*& r, Space*& b, Edge* p) {
55+
switch (s->status()) {
56+
case SS_FAILED:
57+
delete s; break;
58+
case SS_SOLVED:
59+
// solved
60+
delete b;
61+
(void) s->choice(); b = s->clone(); delete s;
62+
r->constrain(*b);
63+
if (r->status() == SS_FAILED) {
64+
delete r; r = NULL;
65+
} else {
66+
Space* c = r->clone(); delete r; r = c;
67+
}
68+
break;
69+
case SS_BRANCH:
70+
{
71+
Edge e(s,p);
72+
bab(e.commit(s),r,b,&e);
73+
e.next();
74+
// explore second alternative
75+
if (r != NULL)
76+
bab(e.recompute(r),r,b,&e);
77+
}
78+
}
79+
}
80+
81+
Space* bab(Space* s) {
82+
if (s->status() == SS_FAILED) {
83+
delete s; return NULL;
84+
}
85+
Space* r = s->clone();
86+
Space* b = NULL;
87+
bab(s,r,b,NULL);
88+
(void) b->choice();
89+
delete r;
90+
return b;
91+
}

doc/6.2.0/MPG/bab.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Authors:
3+
* Christian Schulte <[email protected]>
4+
*
5+
* Copyright:
6+
* Christian Schulte, 2008-2019
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining
9+
* a copy of this software, to deal in the software without restriction,
10+
* including without limitation the rights to use, copy, modify, merge,
11+
* publish, distribute, sublicense, and/or sell copies of the software,
12+
* and to permit persons to whom the software is furnished to do so, subject
13+
* to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be
16+
* included in all copies or substantial portions of the software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25+
*
26+
*/
27+
28+
#include <gecode/kernel.hh>
29+
30+
using namespace Gecode;
31+
32+
void bab(Space* s, unsigned int& n, Space*& b) {
33+
switch (s->status()) {
34+
case SS_FAILED:
35+
delete s;
36+
break;
37+
case SS_SOLVED:
38+
// solved
39+
n++;
40+
delete b;
41+
(void) s->choice(); b = s->clone(); delete s;
42+
break;
43+
case SS_BRANCH:
44+
{
45+
const Choice* ch = s->choice();
46+
Space* c = s->clone();
47+
// remember number of solutions
48+
unsigned int m=n;
49+
// explore first alternative
50+
s->commit(*ch,0);
51+
bab(s,n,b);
52+
// constrain clone
53+
if (n > m)
54+
c->constrain(*b);
55+
// explore second alternative
56+
c->commit(*ch,1);
57+
bab(c,n,b);
58+
delete ch;
59+
}
60+
break;
61+
}
62+
}
63+
64+
Space* bab(Space* s) {
65+
unsigned int n = 0; Space* b = NULL;
66+
bab(s,n,b);
67+
return b;
68+
}

0 commit comments

Comments
 (0)