Originally posted by: Chris McNeil
I'm using CPOptimizer using the Java interface (not OPL) to build the model. I inherited this model where a list of Situations (by integer ID) are built as constraints using a set of other constraints. For example, I have a question that should exist conditionally based on Situation 545 being TRUE. Under the covers Situation 545 "means" that question MajorLineOfBusiness = "Car" AND StateOfIssue = "IL" AND Market = "CHICAGO". Running this model today this conditional constraint is built as (for display purposes only):
cp.add(cp.IfThenElse(cp.and(cp.eq("MLOB", "Cars", cp.and(cp.eq(STATE, "IL"), cp.eq(MARKET, "CHICAGO"))), trueConstraint, falseConstraint));
Clearly, if I could understand exactly how the element() indexing scheme worked, I could reduce these constraints down to something like:
cp.add(cp.IfThenElse(cp.eq(SituationDomain contains 545), trueConstraint, falseConstraint)
I believe it would execute much faster (we're talking several thousand logical constraints tied to many Situations) and the code would be much cleaner.
I can see that I need a compatibility table between Situations and MLOB, State, and Market thereby reducing the Situations domain properly, and I don't expect that Situations will ever become fixed (it isn't my intention to solve for Situations). But I do need to know (by Situation ID) if the actual ID still exists in the CURRENT domain of dvar Situations.
When I try something like:
IloIntVar x = cp.intVar(0, 3);
int[] xVals = new int[]{0, 1, 2, 3};
IloIntVar[] mySet = cp.intVarArray(4, 0, 1);
IloIntVar indexOfX = cp.intVar(0, 3);
cp.add(cp.eq(x, cp.element(xVals, indexOfX)));
cp.add(cp.eq(cp.element(mySet, indexOfX), 1));
if ( cp.propagate() ) {
System.out.println(" Domains reduced: ");
displayDomain(cp, "x", x); // Convenience method
displayDomain(cp, "mySet[0]", mySet[0]);
displayDomain(cp, "mySet[1]", mySet[1]);
displayDomain(cp, "mySet[2]", mySet[2]);
displayDomain(cp, "mySet[3]", mySet[3]);
The active domains for each mySet[] dvar are always [0,1]
Does this mean that element expressions of this type are never fixed? I need to be able to create individual constraint for a single ID value, not necessarily for all ID values at once.
Any light shed on this reification would be greatly appreciated. Oh, I'm using CPOptimizer 12.6 (64-bit) on Windows 2012 with 64-bit JVM.
Thanks!
#CPOptimizer#DecisionOptimization