[gecode-users] Clockwise constraint
Malcolm Ryan
malcolmr at cse.unsw.edu.au
Mon Jun 2 08:10:10 CEST 2008
I want to make a constraint which represents the order of three values
around a ring.
Eg: if we have a,b,c \in {1,2,3,4} then I want to represent the
constraint:
clockwise(a,b,c) == (a < b < c) or (b < c < a) or (c < a < b)
I can construct this directly using BExprs, but the use of 'or' means
that it doesn't propagate very well. Eg:
BExpr beLessAB = new BExpr(a, IntRelType.IRT_LE, b);
BExpr beLessBC = new BExpr(b, IntRelType.IRT_LE, c);
BExpr beLessCA = new BExpr(c, IntRelType.IRT_LE, a);
BExpr beABC = new BExpr(beLessAB).and(beLessBC);
BExpr beBCA = new BExpr(beLessBC).and(beLessCA);
BExpr beCAB = new BExpr(beLessCA).and(beLessAB);
BExpr clockwise = beABC.or(beBCA).or(beCAB);
Gecode.post(test, clockwise);
Gecode.rel(test, test.a, IntRelType.IRT_NE, 2);
Gecode.rel(test, test.a, IntRelType.IRT_NE, 3);
Gecode.rel(test, test.b, IntRelType.IRT_NE, 1);
Gecode.rel(test, test.b, IntRelType.IRT_NE, 4);
Gecode.rel(test, test.c, IntRelType.IRT_NE, 1);
Gecode.rel(test, test.c, IntRelType.IRT_NE, 4);
Will give a = {1,4}, b = [2..3], c = [2..3] when it should be able to
deduce that b = 2, c = 3. Is there any other way to represent this so
that the propagation works better?
Malcolm
More information about the gecode-users
mailing list