private static Propagator createProp(IntVar var1, Operator op1, IntVar var2, Operator op2, int cste) {
if(op1==null)throw new UnsupportedOperationException();
if(op2==null)throw new UnsupportedOperationException();
if (isOperation(op1) == isOperation(op2)) {
throw new SolverException("Incorrect formula; operators must be different!");
}
IntVar[] vars = new IntVar[]{var1,var2};
if (op1 == Operator.PL) {
switch (op2) {
case EQ: // X+Y = C
return new PropEqualXY_C(vars, cste);
case NQ: // X+Y != C
return new PropNotEqualXY_C(vars, cste);
case GE: // X+Y >= C
return new PropGreaterOrEqualXY_C(vars, cste);
case GT: // X+Y > C --> X+Y >= C+1
return new PropGreaterOrEqualXY_C(vars, cste + 1);
case LE: // X+Y <= C
return new PropLessOrEqualXY_C(vars, cste);
case LT: // X+Y < C --> X+Y <= C-1
return new PropLessOrEqualXY_C(vars, cste - 1);
default:
throw new SolverException("Incorrect formula; operator should be one of those:{=, !=, >=, >, <=, <}");
}
} else if (op1 == Operator.MN) {
switch (op2) {
case EQ: // X-Y = C --> X = Y+C
return new PropEqualX_YC(vars, cste);
case NQ: // X-Y != C --> X != Y+C
return new PropNotEqualX_YC(vars, cste);
case GE: // X-Y >= C --> X >= Y+C
return new PropGreaterOrEqualX_YC(vars, cste);
case GT: // X-Y > C --> X >= Y+C+1
return new PropGreaterOrEqualX_YC(vars, cste + 1);
case LE:// X-Y <= C --> Y >= X-C
return new PropGreaterOrEqualX_YC(new IntVar[]{var2, var1}, -cste);
case LT:// X-Y < C --> Y >= X-C+1
return new PropGreaterOrEqualX_YC(new IntVar[]{var2, var1}, -cste + 1);
default:
throw new SolverException("Incorrect formula; operator should be one of those:{=, !=, >=, >, <=, <}");
}
} else {
int _cste = cste * (op2 == Operator.PL ? 1 : -1);
switch (op1) {
case EQ:// X = Y + C
return new PropEqualX_YC(vars, _cste);
case NQ:// X =/= Y + C
return new PropNotEqualX_YC(vars, _cste);
case GE:// X >= Y + C
return new PropGreaterOrEqualX_YC(vars, _cste);
case GT:// X > Y + C --> X >= Y + C + 1
return new PropGreaterOrEqualX_YC(vars, _cste + 1);
case LE:// X <= Y + C --> Y >= X - C
return new PropGreaterOrEqualX_YC(new IntVar[]{var2, var1}, -_cste);
case LT:// X < Y + C --> Y > X - C + 1
return new PropGreaterOrEqualX_YC(new IntVar[]{var2, var1}, -_cste + 1);
default:
throw new SolverException("Incorrect formula; operator should be one of those:{=, !=, >=, >, <=, <}");
}
}
}