spot/buddy/examples/money/money.cxx
Alexandre Duret-Lutz ad8d24222a buddy: rename libbdd to libbddx
* buddy/src/bdd.h, buddy/src/bvec.h, buddy/src/fdd.h: Rename as...
* buddy/src/bddx.h, buddy/src/bvecx.h, buddy/src/fddx.h: ... these.
* buddy/src/Makefile.am: Build libbddx.la instead of libbdd.la.
* buddy/examples/Makefile.def: Use it.
* Makefile.am, buddy/src/bddtest.cxx, buddy/src/bvec.c,
buddy/src/cppext.cxx, buddy/src/fdd.c, buddy/src/imatrix.h,
buddy/src/kernel.h, buddy/examples/adder/adder.cxx,
buddy/examples/bddcalc/parser_.h, buddy/examples/bddtest/bddtest.cxx,
buddy/examples/cmilner/cmilner.c, buddy/examples/fdd/fdd.cxx,
buddy/examples/milner/milner.cxx, buddy/examples/money/money.cxx,
buddy/examples/queen/queen.cxx, buddy/examples/solitare/solitare.cxx,
m4/buddy.m4, src/ltlvisit/apcollect.hh, src/ltlvisit/simplify.hh,
src/misc/bddlt.hh, src/misc/bddop.hh, src/misc/minato.hh,
src/priv/acccompl.hh, src/priv/accconv.hh, src/priv/accmap.hh,
src/priv/bddalloc.cc, src/tgba/bdddict.hh, src/tgba/bddprint.hh,
src/tgba/tgbamask.hh, src/tgba/tgbasafracomplement.cc,
src/tgbaalgos/emptiness.hh, src/tgbaalgos/gtec/sccstack.hh,
src/tgbaalgos/neverclaim.cc, src/tgbaalgos/powerset.cc,
src/tgbaalgos/sccfilter.hh, src/tgbaalgos/sccinfo.hh,
src/tgbaalgos/weight.hh, wrap/python/buddy.i: Adjust.
* NEWS, README: Document it.
2014-10-30 20:58:10 +01:00

76 lines
2.3 KiB
C++

#include "bvecx.h"
#include <iostream>
using namespace std;
/* Find a solution to the send-more-money example
* The problem is to assign values for the digits s,e,n,d,m,o,r,y
* in such a way that the following equation is true:
*
* s e n d +
* m o r e =
* m o n e y
*
* with the additional constraints that all digits must have different values
* and s>0 and m>0.
*/
int main(void)
{
using namespace std ;
// Allocate 11 domains with room for up to 3*10
static int dom[11] = {30,30,30,30,30,30,30,30,30,30,30};
bdd_init(10000,10000);
fdd_extdomain(dom,11);
// Assign binary vectors (expressions) to the digits
bvec s = bvec_varfdd(0); // The 's' digit
bvec e = bvec_varfdd(1); // The 'e' digit
bvec n = bvec_varfdd(2); // ...
bvec d = bvec_varfdd(3);
bvec m = bvec_varfdd(4);
bvec o = bvec_varfdd(5);
bvec r = bvec_varfdd(6);
bvec y = bvec_varfdd(7);
bvec m1 = bvec_varfdd(8); // Carry out 1
bvec m2 = bvec_varfdd(9); // Carry out 2
bvec m3 = bvec_varfdd(10); // Carry out 3
// Create a few constants of the right bit number (5)
bvec c10 = bvec_con(5,10);
bvec c2 = bvec_con(5,2);
bvec c0 = bvec_con(5,0);
// Create constraints
// Constraint 1: addition of the last digits and constraints on
// the max. value of the involved variables and carry-out
bdd t1 = (d + e == y + m1*10) & d<c10 & e<c10 & y<c10 & m1<c2;
// The use of "m1*10" instead of "m1*c10" avoids a bitnum mismatch since
// "m1*10" results in 5 bits but "m1*c10" results in 10 bits!
// And so on ...
bdd t2 = (n + r + m1 == e + m2*10) & n<c10 & r<c10 & m2<c2;
bdd t3 = (e + o + m2 == n + m3*10) & o<c10 & m3<c2;
bdd t4 = (s + m + m3 == o + m*10) & s<c10 & m<c2;
bdd t5 = (m > c0 & s > c0);
// Make sure all digits are different
bdd t6 = (s!=e & s!=n & s!=d & s!=m & s!=o & s!=r & s!=y);
bdd t7 = (e!=n & e!=d & e!=m & e!=o & e!=r & e!=y);
bdd t8 = (n!=d & n!=m & n!=o & n!=r & n!=y);
bdd t9 = (d!=m & d!=o & d!=r & d!=y);
bdd t10 = (m!=o & m!=r & m!=y);
bdd t11 = (o!=r & o!=y);
bdd t12 = (r!=y);
// Join all constraints
bdd t = t1 & t2 & t3 & t4 & t5 & t6 & t7 & t8 & t9 & t10 & t11 & t12;
// Print result
cout << fddset << t << endl;
return 0;
}