how to make complex constraints in 4.10?

32 views
Skip to first unread message

Calgach mapBrude

unread,
Sep 21, 2022, 8:05:04 AM9/21/22
to choco-solver
 Hi,
I am trying to figure out how to do something like this in 4.10: 
import choco.Choco.implies; 
ArrayList<Constraint> myclist = new ArrayList<Constraint>(); where setX and setZ are IntVar arrays and elX and elZ are just IntVars and nameAh and honest are just IntVars. All intVars are declared as enums, for example: 
  IntVar nameAh = m.intVar("nameAh", 0, 0, false); and so I need to create the constraints and store them in a collection for later use like so: 
myclist.add(implies(and(eq(nameAh, honest), eq(setX[i], elX)), eq(setZ[i], elZ)));

How can I build a constraint like "implies(and(eq(nameAh, honest), eq(setX[i], elX)), eq(setZ[i], elZ))" ?  I had this working a long while ago in Choco version 2 but of course the PAIs are very different now.

Thanks 

cpru...@gmail.com

unread,
Sep 22, 2022, 3:20:41 AM9/22/22
to choco-solver
I think you can do it like this, using expressions:

// implies(and(eq(nameAh, honest), eq(setX[i], elX)), eq(setZ[i], elZ))
IntVar nameAh, honest, elX, elZ;
IntVar[] setX, setZ;
ReExpression exp = nameAh.eq(honest).and(setX[i].eq(elX)).imp(setZ[i].eq(elZ));
exp.post(); // equiv. to exp.decompose().post();
// alternative, as table cstr
//exp.extension() 

Best regards


Reply all
Reply to author
Forward
0 new messages