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