Generated on Thu Mar 22 10:39:31 2012 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  *  Last modified:
00010  *     $Date: 2010-10-07 11:52:01 +0200 (Thu, 07 Oct 2010) $ by $Author: schulte $
00011  *     $Revision: 11473 $
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 #include <gecode/int.hh>
00040 #include <gecode/minimodel.hh>
00041 
00042 using namespace Gecode;
00043 
00052 class Donald : public Script {
00053 private:
00055   static const int nl = 10;
00057   IntVarArray le;
00058 public:
00060   enum {
00061     MODEL_SINGLE, 
00062     MODEL_CARRY   
00063   };
00065   Donald(const Options& opt) :
00066     le(*this,nl,0,9) {
00067     IntVar
00068       d(le[0]), o(le[1]), n(le[2]), a(le[3]), l(le[4]),
00069       g(le[5]), e(le[6]), r(le[7]), b(le[8]), t(le[9]);
00070     rel(*this, d, IRT_NQ, 0);
00071     rel(*this, g, IRT_NQ, 0);
00072     rel(*this, r, IRT_NQ, 0);
00073 
00074     distinct(*this, le, opt.icl());
00075 
00076     switch (opt.model()) {
00077     case MODEL_SINGLE:
00078       rel(*this,    100000*d+10000*o+1000*n+100*a+10*l+d
00079                   + 100000*g+10000*e+1000*r+100*a+10*l+d
00080                  == 100000*r+10000*o+1000*b+100*e+10*r+t,
00081            opt.icl());
00082       break;
00083     case MODEL_CARRY:
00084       {
00085         IntVar c0(*this,0,1), c1(*this,0,1), c2(*this,0,1),
00086           c3(*this,0,1), c4(*this,0,1);
00087         rel(*this,    d+d == t+10*c0, opt.icl());
00088         rel(*this, c0+l+l == r+10*c1, opt.icl());
00089         rel(*this, c1+a+a == e+10*c2, opt.icl());
00090         rel(*this, c2+n+r == b+10*c3, opt.icl());
00091         rel(*this, c3+o+e == o+10*c4, opt.icl());
00092         rel(*this, c4+d+g == r,       opt.icl());
00093       }
00094       break;
00095     default: GECODE_NEVER;
00096     }
00097 
00098     branch(*this, le, INT_VAR_SIZE_MIN, INT_VAL_MAX);
00099   }
00101   Donald(bool share, Donald& s) : Script(share,s) {
00102     le.update(*this, share, s.le);
00103   }
00105   virtual Space*
00106   copy(bool share) {
00107     return new Donald(share,*this);
00108   }
00110   virtual void
00111   print(std::ostream& os) const {
00112     os << "\t" << le << std::endl;;
00113   }
00114 
00115 };
00116 
00117 
00121 int
00122 main(int argc, char* argv[]) {
00123   Options opt("Donald+Gerald=Robert");
00124   opt.model(Donald::MODEL_SINGLE);
00125   opt.model(Donald::MODEL_SINGLE, "single", "use single linear equation");
00126   opt.model(Donald::MODEL_CARRY, "carry", "use carry");
00127   opt.solutions(0);
00128   opt.iterations(1500);
00129   opt.parse(argc,argv);
00130   Script::run<Donald,DFS,Options>(opt);
00131   return 0;
00132 }
00133 
00134 // STATISTICS: example-any
00135