hi,

Do you agree that 

-7 mod 12 == 5

?

I'm asking because I know mod arithmetic can be tricky. Python says that this 
is true, but gecode is failing on this constraint.

I'm not a gecode expert so probably I'm doing something wrong. I'm attaching a 
small test case.

Thanks!
Marco

-- 
Marco Correia <[email protected]>
#include <gecode/int.hh>
#include <gecode/search.hh>

using namespace Gecode;

class ModTest : public Space {
protected:
  IntVarArray l;
public:
  ModTest(void) : l(*this, 3) {

    l[0] = IntVar(*this,-7,-7);
    l[1] = IntVar(*this,12,12);
    l[2] = IntVar(*this,5,5);
    
    mod(*this,l[0],l[1],l[2]);
    // post branching
    branch(*this, l, INT_VAR_SIZE_MIN, INT_VAL_MIN);
  }
  // search support
  ModTest(bool share, ModTest& s) : Space(share, s) {
    l.update(*this, share, s.l);
  }
  virtual Space* copy(bool share) {
    return new ModTest(share,*this);
  }
  // print solution
  void print(void) const {
    std::cout << l << std::endl;
  }
};

// main function
int main(int argc, char* argv[]) {
  // create model and search engine
  ModTest* m = new ModTest;
  DFS<ModTest> e(m);
  delete m;
  assert(e.next()!=NULL);
  return 0;
}
_______________________________________________
Gecode users mailing list
[email protected]
https://www.gecode.org/mailman/listinfo/gecode-users

Reply via email to