[gecode-users] First contact with gecode

Frederic C frederic.ant.c at gmail.com
Fri Oct 3 19:33:32 CEST 2014


Hi,

I am new to gecode and I have a simple question.

I am trying to find one possible solution for the following system:

1A + 1B >  0
1A + 0B >  0
1A + 1B >  0
0A + 0B <= 0

Obviously, there are many solutions. For instance, A=1 and B=1.

My code is the following:

class SolverSpace : public Gecode::Space
{
   IntVarArray s;

public:
   SolverSpace() :
     s(*this, 2, -1000000, 1000000) // lots of possible values, to be on 
the safe side
   {
     { // 1A + 1B >  0
       IntArgs coeffs(2); coeffs[0] = 1;  coeffs[1] = 1;
       linear(*this, coeffs, s, IRT_GT, int(0));
     }
     { // 1A + 0B >  0
       IntArgs coeffs(2); coeffs[0] = 1;  coeffs[1] = 0;
       linear(*this, coeffs, s, IRT_GT, int(0));
     }
     { // 1A + 1B >  0
       IntArgs coeffs(2); coeffs[0] = 0;  coeffs[1] = 1;
       linear(*this, coeffs, s, IRT_GT, int(0));
     }
     { // 0A + 0B <= 0
       IntArgs coeffs(2); coeffs[0] = 0;  coeffs[1] = 0;
       linear(*this, coeffs, s, IRT_LE, int(0));
     }

     branch(*this, s, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
   }

   SolverSpace(bool share, SolverSpace& e) :
     Gecode::Space(share, e)
   {
     s.update(*this, share, e.s);
   }

   virtual Space *copy(bool share)
   {
     return new SolverSpace(share, *this);
   }

   void print()
   {
     for (int i = 0; i < 2; i++)
       std::cout << s[i] << ", ";
     std::cout << std::endl;
   }
}

Calling code:

SolverSpace*m = new SolverSpace();
DFS<SolverSpace> e(m);
delete m;
if (SolverSpace *s = e.next()) {
   s->print(); delete s;
}

To my surprise, no solution is found. What am I doing wrong?

Thank you,

Fred




More information about the users mailing list