money.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00092