Generated on Thu Apr 11 13:58:51 2019 for Gecode by doxygen 1.6.3

alpha.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2001
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <gecode/driver.hh>
00035 
00036 #include <gecode/int.hh>
00037 #include <gecode/minimodel.hh>
00038 
00039 using namespace Gecode;
00040 
00049 class Alpha : public Script {
00050 protected:
00052   static const int n = 26;
00054   IntVarArray le;
00055 public:
00057   enum {
00058     BRANCH_NONE,    
00059     BRANCH_INVERSE, 
00060     BRANCH_SIZE     
00061   };
00063   Alpha(const Options& opt)
00064     : Script(opt), le(*this,n,1,n) {
00065     IntVar
00066       a(le[ 0]), b(le[ 1]), c(le[ 2]), e(le[ 4]), f(le[ 5]),
00067       g(le[ 6]), h(le[ 7]), i(le[ 8]), j(le[ 9]), k(le[10]),
00068       l(le[11]), m(le[12]), n(le[13]), o(le[14]), p(le[15]),
00069       q(le[16]), r(le[17]), s(le[18]), t(le[19]), u(le[20]),
00070       v(le[21]), w(le[22]), x(le[23]), y(le[24]), z(le[25]);
00071 
00072     rel(*this, b+a+l+l+e+t       == 45,  opt.ipl());
00073     rel(*this, c+e+l+l+o         == 43,  opt.ipl());
00074     rel(*this, c+o+n+c+e+r+t     == 74,  opt.ipl());
00075     rel(*this, f+l+u+t+e         == 30,  opt.ipl());
00076     rel(*this, f+u+g+u+e         == 50,  opt.ipl());
00077     rel(*this, g+l+e+e           == 66,  opt.ipl());
00078     rel(*this, j+a+z+z           == 58,  opt.ipl());
00079     rel(*this, l+y+r+e           == 47,  opt.ipl());
00080     rel(*this, o+b+o+e           == 53,  opt.ipl());
00081     rel(*this, o+p+e+r+a         == 65,  opt.ipl());
00082     rel(*this, p+o+l+k+a         == 59,  opt.ipl());
00083     rel(*this, q+u+a+r+t+e+t     == 50,  opt.ipl());
00084     rel(*this, s+a+x+o+p+h+o+n+e == 134, opt.ipl());
00085     rel(*this, s+c+a+l+e         == 51,  opt.ipl());
00086     rel(*this, s+o+l+o           == 37,  opt.ipl());
00087     rel(*this, s+o+n+g           == 61,  opt.ipl());
00088     rel(*this, s+o+p+r+a+n+o     == 82,  opt.ipl());
00089     rel(*this, t+h+e+m+e         == 72,  opt.ipl());
00090     rel(*this, v+i+o+l+i+n       == 100, opt.ipl());
00091     rel(*this, w+a+l+t+z         == 34,  opt.ipl());
00092 
00093     distinct(*this, le, opt.ipl());
00094 
00095     switch (opt.branching()) {
00096     case BRANCH_NONE:
00097       branch(*this, le, INT_VAR_NONE(), INT_VAL_MIN());
00098       break;
00099     case BRANCH_INVERSE:
00100       branch(*this, le.slice(le.size()-1,-1), INT_VAR_NONE(), INT_VAL_MIN());
00101       break;
00102     case BRANCH_SIZE:
00103       branch(*this, le, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
00104       break;
00105     }
00106   }
00107 
00109   Alpha(Alpha& s) : Script(s) {
00110     le.update(*this, s.le);
00111   }
00113   virtual Space*
00114   copy(void) {
00115     return new Alpha(*this);
00116   }
00118   virtual void
00119   print(std::ostream& os) const {
00120     os << "\t";
00121     for (int i = 0; i < n; i++) {
00122       os << ((char) (i+'a')) << '=' << le[i] << ((i<n-1)?", ":"\n");
00123       if ((i+1) % 8 == 0)
00124         os << std::endl << "\t";
00125     }
00126     os << std::endl;
00127   }
00128 };
00129 
00133 int
00134 main(int argc, char* argv[]) {
00135   Options opt("Alpha");
00136   opt.solutions(0);
00137   opt.iterations(10);
00138   opt.branching(Alpha::BRANCH_NONE);
00139   opt.branching(Alpha::BRANCH_NONE, "none");
00140   opt.branching(Alpha::BRANCH_INVERSE, "inverse");
00141   opt.branching(Alpha::BRANCH_SIZE, "size");
00142   opt.parse(argc,argv);
00143   Script::run<Alpha,DFS,Options>(opt);
00144   return 0;
00145 }
00146 
00147 // STATISTICS: example-any
00148