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
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "examples/support.hh"
00039 #include "gecode/minimodel.hh"
00040
00050 class Money : public Example {
00051 protected:
00053 static const int nl = 8;
00055 IntVarArray le;
00056 public:
00058 Money(const Options& opt) : le(this,nl,0,9) {
00059 IntVar
00060 s(le[0]), e(le[1]), n(le[2]), d(le[3]),
00061 m(le[4]), o(le[5]), r(le[6]), y(le[7]);
00062
00063 rel(this, s, IRT_NQ, 0);
00064 rel(this, m, IRT_NQ, 0);
00065
00066 post(this, 1000*s+100*e+10*n+d
00067 + 1000*m+100*o+10*r+e
00068 == 10000*m+1000*o+100*n+10*e+y,
00069 opt.icl());
00070
00071 distinct(this, le, opt.icl());
00072 branch(this, le, INT_VAR_SIZE_MIN, INT_VAL_MIN);
00073 }
00075 virtual void
00076 print(std::ostream& os) {
00077 os << "\t" << le << std::endl;
00078 }
00079
00081 Money(bool share, Money& s) : Example(share,s) {
00082 le.update(this, share, s.le);
00083 }
00085 virtual Space*
00086 copy(bool share) {
00087 return new Money(share,*this);
00088 }
00089 };
00090
00094 int
00095 main(int argc, char* argv[]) {
00096 Options opt("SEND+MORE=MONEY");
00097 opt.solutions(0);
00098 opt.iterations(20000);
00099 opt.parse(argc,argv);
00100 Example::run<Money,DFS,Options>(opt);
00101 return 0;
00102 }
00103
00104
00105