MCPcopy Create free account
hub / github.com/Gecode/gecode / Money

Method Money

examples/money.cpp:62–107  ·  view source on GitHub ↗

Actual model

Source from the content-addressed store, hash-verified

60 };
61 /// Actual model
62 Money(const Options& opt) : Script(opt), le(*this,nl,0,9) {
63 IntVar
64 s(le[0]), e(le[1]), n(le[2]), d(le[3]),
65 m(le[4]), o(le[5]), r(le[6]), y(le[7]);
66
67 if (opt.trace()) {
68 trace(*this, le, opt.trace());
69 trace(*this, opt.trace());
70 }
71
72 rel(*this, s, IRT_NQ, 0);
73 rel(*this, m, IRT_NQ, 0);
74
75 distinct(*this, le, opt.ipl());
76
77 switch (opt.model()) {
78 case MODEL_SINGLE:
79 rel(*this, 1000*s+100*e+10*n+d
80 + 1000*m+100*o+10*r+e
81 == 10000*m+1000*o+100*n+10*e+y,
82 opt.ipl());
83 break;
84 case MODEL_CARRY:
85 {
86 IntVar c0(*this,0,1), c1(*this,0,1), c2(*this,0,1), c3(*this,0,1);
87 rel(*this, d+e == y+10*c0, opt.ipl());
88 rel(*this, c0+n+r == e+10*c1, opt.ipl());
89 rel(*this, c1+e+o == n+10*c2, opt.ipl());
90 rel(*this, c2+s+m == o+10*c3, opt.ipl());
91 rel(*this, c3 == m, opt.ipl());
92 }
93 break;
94 default: GECODE_NEVER;
95 }
96
97 branch(*this, le, INT_VAR_SIZE_MIN(), INT_VAL_MIN(), nullptr,
98 [](const Space&, const Brancher&, unsigned int a,
99 IntVar, int i, const int& n,
100 std::ostream& o) {
101 static char name[8] = {'s','e','n','d',
102 'm','o','r','y'};
103 o << name[i]
104 << ((a == 0) ? " = " : " != ")
105 << n;
106 });
107 }
108 /// Print solution
109 virtual void
110 print(std::ostream& os) const {

Callers

nothing calls this directly

Calls 10

distinctFunction · 0.85
INT_VAR_SIZE_MINFunction · 0.85
INT_VAL_MINFunction · 0.85
traceMethod · 0.80
modelMethod · 0.80
traceFunction · 0.50
relFunction · 0.50
branchFunction · 0.50
iplMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected