main page
modules
namespaces
classes
files
Gecode home
Generated on Thu Mar 13 2014 04:39:27 for Gecode by
doxygen
1.8.1.2
examples
donald.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christian Schulte <schulte@gecode.org>
5
*
6
* Copyright:
7
* Christian Schulte, 2001
8
*
9
* Last modified:
10
* $Date: 2010-10-07 20:52:01 +1100 (Thu, 07 Oct 2010) $ by $Author: schulte $
11
* $Revision: 11473 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
#include <
gecode/driver.hh
>
39
#include <
gecode/int.hh
>
40
#include <
gecode/minimodel.hh
>
41
42
using namespace
Gecode;
43
52
class
Donald
:
public
Script
{
53
private
:
55
static
const
int
nl = 10;
57
IntVarArray
le;
58
public
:
60
enum
{
61
MODEL_SINGLE
,
62
MODEL_CARRY
63
};
65
Donald
(
const
Options
&
opt
) :
66
le(*this,nl,0,9) {
67
IntVar
68
d
(le[0]), o(le[1]), n(le[2]),
a
(le[3]), l(le[4]),
69
g(le[5]), e(le[6]),
r
(le[7]),
b
(le[8]), t(le[9]);
70
rel
(*
this
,
d
,
IRT_NQ
, 0);
71
rel
(*
this
, g,
IRT_NQ
, 0);
72
rel
(*
this
,
r
,
IRT_NQ
, 0);
73
74
distinct
(*
this
, le, opt.
icl
());
75
76
switch
(opt.
model
()) {
77
case
MODEL_SINGLE:
78
rel
(*
this
, 100000*
d
+10000*o+1000*n+100*
a
+10*l+
d
79
+ 100000*g+10000*e+1000*
r
+100*
a
+10*l+
d
80
== 100000*
r
+10000*o+1000*
b
+100*e+10*
r
+t,
81
opt.
icl
());
82
break
;
83
case
MODEL_CARRY:
84
{
85
IntVar
c0(*
this
,0,1), c1(*
this
,0,1), c2(*
this
,0,1),
86
c3(*
this
,0,1), c4(*
this
,0,1);
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
());
93
}
94
break
;
95
default
:
GECODE_NEVER
;
96
}
97
98
branch
(*
this
, le,
INT_VAR_SIZE_MIN
,
INT_VAL_MAX
);
99
}
101
Donald
(
bool
share,
Donald
& s) :
Script
(share,s) {
102
le.update(*
this
, share, s.le);
103
}
105
virtual
Space
*
106
copy
(
bool
share) {
107
return
new
Donald
(share,*
this
);
108
}
110
virtual
void
111
print
(std::ostream& os)
const
{
112
os <<
"\t"
<< le << std::endl;;
113
}
114
115
};
116
117
121
int
122
main
(
int
argc,
char
* argv[]) {
123
Options
opt
(
"Donald+Gerald=Robert"
);
124
opt.
model
(
Donald::MODEL_SINGLE
);
125
opt.
model
(
Donald::MODEL_SINGLE
,
"single"
,
"use single linear equation"
);
126
opt.
model
(
Donald::MODEL_CARRY
,
"carry"
,
"use carry"
);
127
opt.
solutions
(0);
128
opt.
iterations
(1500);
129
opt.
parse
(argc,argv);
130
Script::run<Donald,DFS,Options>(
opt
);
131
return
0;
132
}
133
134
// STATISTICS: example-any
135