Generated on Sat Feb 7 2015 02:01:10 for Gecode by doxygen 1.8.9.1
alpha.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: 2013-07-08 14:22:40 +0200 (Mon, 08 Jul 2013) $ by $Author: schulte $
11  * $Revision: 13820 $
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 
40 #include <gecode/int.hh>
41 #include <gecode/minimodel.hh>
42 
43 using namespace Gecode;
44 
53 class Alpha : public Script {
54 protected:
56  static const int n = 26;
59 public:
61  enum {
64  BRANCH_SIZE
65  };
67  Alpha(const Options& opt) : le(*this,n,1,n) {
68  IntVar
69  a(le[ 0]), b(le[ 1]), c(le[ 2]), e(le[ 4]), f(le[ 5]),
70  g(le[ 6]), h(le[ 7]), i(le[ 8]), j(le[ 9]), k(le[10]),
71  l(le[11]), m(le[12]), n(le[13]), o(le[14]), p(le[15]),
72  q(le[16]), r(le[17]), s(le[18]), t(le[19]), u(le[20]),
73  v(le[21]), w(le[22]), x(le[23]), y(le[24]), z(le[25]);
74 
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());
95 
96  distinct(*this, le, opt.icl());
97 
98  switch (opt.branching()) {
99  case BRANCH_NONE:
100  branch(*this, le, INT_VAR_NONE(), INT_VAL_MIN());
101  break;
102  case BRANCH_INVERSE:
103  branch(*this, le.slice(le.size()-1,-1), INT_VAR_NONE(), INT_VAL_MIN());
104  break;
105  case BRANCH_SIZE:
106  branch(*this, le, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
107  break;
108  }
109  }
110 
112  Alpha(bool share, Alpha& s) : Script(share,s) {
113  le.update(*this, share, s.le);
114  }
116  virtual Space*
117  copy(bool share) {
118  return new Alpha(share,*this);
119  }
121  virtual void
122  print(std::ostream& os) const {
123  os << "\t";
124  for (int i = 0; i < n; i++) {
125  os << ((char) (i+'a')) << '=' << le[i] << ((i<n-1)?", ":"\n");
126  if ((i+1) % 8 == 0)
127  os << std::endl << "\t";
128  }
129  os << std::endl;
130  }
131 };
132 
136 int
137 main(int argc, char* argv[]) {
138  Options opt("Alpha");
139  opt.solutions(0);
140  opt.iterations(10);
142  opt.branching(Alpha::BRANCH_NONE, "none");
143  opt.branching(Alpha::BRANCH_INVERSE, "inverse");
144  opt.branching(Alpha::BRANCH_SIZE, "size");
145  opt.parse(argc,argv);
146  Script::run<Alpha,DFS,Options>(opt);
147  return 0;
148 }
149 
150 // STATISTICS: example-any
151 
Example: Alpha puzzle
Definition: alpha.cpp:53
NodeType t
Type of node.
Definition: bool-expr.cpp:234
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:108
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
Choose variable right to left.
Definition: alpha.cpp:63
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
Definition: var.hpp:212
Integer variable array.
Definition: int.hh:741
IntVarArray le
Array for letters.
Definition: alpha.cpp:58
Computation spaces.
Definition: core.hpp:1362
Parametric base-class for scripts.
Definition: driver.hh:622
void iterations(unsigned int i)
Set default number of iterations.
Definition: options.hpp:385
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
Definition: array.hpp:1072
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Options opt
The options.
Definition: test.cpp:101
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
Choose variable left to right.
Definition: alpha.cpp:62
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition: val.hpp:68
Choose variable with smallest size.
Definition: alpha.cpp:64
void branching(int v)
Set default branching value.
Definition: options.hpp:203
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Definition: array.hpp:1005
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Definition: options.cpp:331
union Gecode::@518::NNF::@57 u
Union depending on nodetype t.
const int v[7]
Definition: distinct.cpp:207
Alpha(bool share, Alpha &s)
Constructor for cloning s.
Definition: alpha.cpp:112
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Integer variables.
Definition: int.hh:350
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
void distinct(Home home, const IntVarArgs &x, IntConLevel icl)
Post propagator for for all .
Definition: distinct.cpp:47
void solutions(unsigned int n)
Set default number of solutions to search for.
Definition: options.hpp:243
virtual Space * copy(bool share)
Copy during cloning.
Definition: alpha.cpp:117
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
BrancherHandle branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Branch over x with variable selection vars and value selection vals.
Definition: branch.cpp:43
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:985
Options for scripts
Definition: driver.hh:326
virtual void print(std::ostream &os) const
Print solution.
Definition: alpha.cpp:122
void icl(IntConLevel i)
Set default integer consistency level.
Definition: options.hpp:194
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
Alpha(const Options &opt)
Actual model.
Definition: alpha.cpp:67
int main(int argc, char *argv[])
Main-function.
Definition: alpha.cpp:137