Generated on Mon Jul 27 2020 00:00:00 for Gecode by doxygen 1.8.18
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  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 #include <gecode/driver.hh>
35 
36 #include <gecode/int.hh>
37 #include <gecode/minimodel.hh>
38 
39 using namespace Gecode;
40 
49 class Alpha : public Script {
50 protected:
52  static const int n = 26;
55 public:
57  enum {
60  BRANCH_SIZE
61  };
63  Alpha(const Options& opt)
64  : Script(opt), le(*this,n,1,n) {
65  IntVar
66  a(le[ 0]), b(le[ 1]), c(le[ 2]), e(le[ 4]), f(le[ 5]),
67  g(le[ 6]), h(le[ 7]), i(le[ 8]), j(le[ 9]), k(le[10]),
68  l(le[11]), m(le[12]), n(le[13]), o(le[14]), p(le[15]),
69  q(le[16]), r(le[17]), s(le[18]), t(le[19]), u(le[20]),
70  v(le[21]), w(le[22]), x(le[23]), y(le[24]), z(le[25]);
71 
72  rel(*this, b+a+l+l+e+t == 45, opt.ipl());
73  rel(*this, c+e+l+l+o == 43, opt.ipl());
74  rel(*this, c+o+n+c+e+r+t == 74, opt.ipl());
75  rel(*this, f+l+u+t+e == 30, opt.ipl());
76  rel(*this, f+u+g+u+e == 50, opt.ipl());
77  rel(*this, g+l+e+e == 66, opt.ipl());
78  rel(*this, j+a+z+z == 58, opt.ipl());
79  rel(*this, l+y+r+e == 47, opt.ipl());
80  rel(*this, o+b+o+e == 53, opt.ipl());
81  rel(*this, o+p+e+r+a == 65, opt.ipl());
82  rel(*this, p+o+l+k+a == 59, opt.ipl());
83  rel(*this, q+u+a+r+t+e+t == 50, opt.ipl());
84  rel(*this, s+a+x+o+p+h+o+n+e == 134, opt.ipl());
85  rel(*this, s+c+a+l+e == 51, opt.ipl());
86  rel(*this, s+o+l+o == 37, opt.ipl());
87  rel(*this, s+o+n+g == 61, opt.ipl());
88  rel(*this, s+o+p+r+a+n+o == 82, opt.ipl());
89  rel(*this, t+h+e+m+e == 72, opt.ipl());
90  rel(*this, v+i+o+l+i+n == 100, opt.ipl());
91  rel(*this, w+a+l+t+z == 34, opt.ipl());
92 
93  distinct(*this, le, opt.ipl());
94 
95  switch (opt.branching()) {
96  case BRANCH_NONE:
97  branch(*this, le, INT_VAR_NONE(), INT_VAL_MIN());
98  break;
99  case BRANCH_INVERSE:
100  branch(*this, le.slice(le.size()-1,-1), INT_VAR_NONE(), INT_VAL_MIN());
101  break;
102  case BRANCH_SIZE:
103  branch(*this, le, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
104  break;
105  }
106  }
107 
109  Alpha(Alpha& s) : Script(s) {
110  le.update(*this, s.le);
111  }
113  virtual Space*
114  copy(void) {
115  return new Alpha(*this);
116  }
118  virtual void
119  print(std::ostream& os) const {
120  os << "\t";
121  for (int i = 0; i < n; i++) {
122  os << ((char) (i+'a')) << '=' << le[i] << ((i<n-1)?", ":"\n");
123  if ((i+1) % 8 == 0)
124  os << std::endl << "\t";
125  }
126  os << std::endl;
127  }
128 };
129 
133 int
134 main(int argc, char* argv[]) {
135  Options opt("Alpha");
136  opt.solutions(0);
137  opt.iterations(10);
140  opt.branching(Alpha::BRANCH_INVERSE, "inverse");
142  opt.parse(argc,argv);
143  Script::run<Alpha,DFS,Options>(opt);
144  return 0;
145 }
146 
147 // STATISTICS: example-any
148 
Post propagator for SetVar x
Definition: set.hh:767
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:96
IntVarArray le
Array for letters.
Definition: alpha.cpp:54
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:767
NodeType t
Type of node.
Definition: bool-expr.cpp:230
Computation spaces.
Definition: core.hpp:1742
void 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:39
void iterations(unsigned int i)
Set default number of iterations.
Definition: options.hpp:461
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition: val.hpp:55
Integer variable array.
Definition: int.hh:763
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:926
virtual void print(std::ostream &os) const
Print solution.
Definition: alpha.cpp:119
Gecode toplevel namespace
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
Options opt
The options.
Definition: test.cpp:97
Options for scripts
Definition: driver.hh:366
Parametric base-class for scripts.
Definition: driver.hh:729
void branching(int v)
Set default branching value.
Definition: options.hpp:225
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Definition: options.cpp:548
Example: Alpha puzzle
Definition: alpha.cpp:49
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Integer variables.
Definition: int.hh:371
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
Definition: var.hpp:206
const int v[7]
Definition: distinct.cpp:259
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:43
NNF * l
Left subtree.
Definition: bool-expr.cpp:240
@ BRANCH_NONE
Choose variable left to right.
Definition: alpha.cpp:58
virtual Space * copy(void)
Copy during cloning.
Definition: alpha.cpp:114
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Definition: array.hpp:946
Alpha(const Options &opt)
Actual model.
Definition: alpha.cpp:63
@ BRANCH_SIZE
Choose variable with smallest size.
Definition: alpha.cpp:60
void distinct(Home home, const IntVarArgs &x, IntPropLevel ipl)
Post propagator for for all .
Definition: distinct.cpp:46
void solutions(unsigned int n)
Set default number of solutions to search for.
Definition: options.hpp:283
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
Gecode::FloatVal c(-8, 8)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
int main(int argc, char *argv[])
Main-function.
Definition: alpha.cpp:134
Alpha(Alpha &s)
Constructor for cloning s.
Definition: alpha.cpp:109
Gecode::IntArgs i({1, 2, 3, 4})
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
@ BRANCH_INVERSE
Choose variable right to left.
Definition: alpha.cpp:59
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
Definition: array.hpp:1013