Generated on Tue May 22 09:39:38 2018 for Gecode by doxygen 1.6.3

donald.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 #include <gecode/int.hh>
00036 #include <gecode/minimodel.hh>
00037 
00038 using namespace Gecode;
00039 
00048 class Donald : public Script {
00049 private:
00051   static const int nl = 10;
00053   IntVarArray le;
00054 public:
00056   enum {
00057     MODEL_SINGLE, 
00058     MODEL_CARRY   
00059   };
00061   Donald(const Options& opt)
00062     : Script(opt), le(*this,nl,0,9) {
00063     IntVar
00064       d(le[0]), o(le[1]), n(le[2]), a(le[3]), l(le[4]),
00065       g(le[5]), e(le[6]), r(le[7]), b(le[8]), t(le[9]);
00066     rel(*this, d, IRT_NQ, 0);
00067     rel(*this, g, IRT_NQ, 0);
00068     rel(*this, r, IRT_NQ, 0);
00069 
00070     distinct(*this, le, opt.ipl());
00071 
00072     switch (opt.model()) {
00073     case MODEL_SINGLE:
00074       rel(*this,    100000*d+10000*o+1000*n+100*a+10*l+d
00075                   + 100000*g+10000*e+1000*r+100*a+10*l+d
00076                  == 100000*r+10000*o+1000*b+100*e+10*r+t,
00077            opt.ipl());
00078       break;
00079     case MODEL_CARRY:
00080       {
00081         IntVar c0(*this,0,1), c1(*this,0,1), c2(*this,0,1),
00082           c3(*this,0,1), c4(*this,0,1);
00083         rel(*this,    d+d == t+10*c0, opt.ipl());
00084         rel(*this, c0+l+l == r+10*c1, opt.ipl());
00085         rel(*this, c1+a+a == e+10*c2, opt.ipl());
00086         rel(*this, c2+n+r == b+10*c3, opt.ipl());
00087         rel(*this, c3+o+e == o+10*c4, opt.ipl());
00088         rel(*this, c4+d+g == r,       opt.ipl());
00089       }
00090       break;
00091     default: GECODE_NEVER;
00092     }
00093 
00094     branch(*this, le, INT_VAR_SIZE_MIN(), INT_VAL_MAX());
00095   }
00097   Donald(Donald& s) : Script(s) {
00098     le.update(*this, s.le);
00099   }
00101   virtual Space*
00102   copy(void) {
00103     return new Donald(*this);
00104   }
00106   virtual void
00107   print(std::ostream& os) const {
00108     os << "\t" << le << std::endl;;
00109   }
00110 
00111 };
00112 
00113 
00117 int
00118 main(int argc, char* argv[]) {
00119   Options opt("Donald+Gerald=Robert");
00120   opt.model(Donald::MODEL_SINGLE);
00121   opt.model(Donald::MODEL_SINGLE, "single", "use single linear equation");
00122   opt.model(Donald::MODEL_CARRY, "carry", "use carry");
00123   opt.solutions(0);
00124   opt.iterations(1500);
00125   opt.parse(argc,argv);
00126   Script::run<Donald,DFS,Options>(opt);
00127   return 0;
00128 }
00129 
00130 // STATISTICS: example-any
00131