Generated on Wed Nov 1 15:04:27 2006 for Gecode by doxygen 1.4.5

money.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2001
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-08-04 16:06:52 +0200 (Fri, 04 Aug 2006) $ by $Author: schulte $
00010  *     $Revision: 3517 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 #include "examples/support.hh"
00023 #include "gecode/minimodel.hh"
00024 
00034 class Money : public Example {
00035 protected:
00037   static const int nl = 8;
00039   IntVarArray le;
00040 public:
00042   Money(const Options& opt) : le(this,nl,0,9) {
00043     IntVar
00044       s(le[0]), e(le[1]), n(le[2]), d(le[3]),
00045       m(le[4]), o(le[5]), r(le[6]), y(le[7]);
00046 
00047     rel(this, s, IRT_NQ, 0);
00048     rel(this, m, IRT_NQ, 0);
00049 
00050     post(this,            1000*s+100*e+10*n+d
00051                 +         1000*m+100*o+10*r+e
00052                == 10000*m+1000*o+100*n+10*e+y,
00053          opt.icl);
00054 
00055     distinct(this, le, opt.icl);
00056     branch(this, le, BVAR_SIZE_MIN, BVAL_MIN);
00057   }
00059   virtual void
00060   print(void) {
00061     std::cout << "\t";
00062     for (int i = 0; i < nl; i++)
00063       std::cout << le[i] << " ";
00064     std::cout << std::endl;
00065   }
00066 
00068   Money(bool share, Money& s) : Example(share,s) {
00069     le.update(this, share, s.le);
00070   }
00072   virtual Space*
00073   copy(bool share) {
00074     return new Money(share,*this);
00075   }
00076 };
00077 
00081 int
00082 main(int argc, char** argv) {
00083   Options opt("SEND+MORE=MONEY");
00084   opt.solutions  = 0;
00085   opt.iterations = 20000;
00086   opt.parse(argc,argv);
00087   Example::run<Money,DFS>(opt);
00088   return 0;
00089 }
00090 
00091 // STATISTICS: example-any
00092