I am running a code in CP Optimizer 12.22 that requires using IlcConstraint and ILOCPCONSTRAINTWRAPPER3 as follows:
protected:
IlcIntVarArray _x;
IlcInt _a;
IlcFloatVar _z;
public:
IlcCheckWhenBoundI(IloCPEngine s, IlcIntVarArray x, IlcInt a, IlcFloatVar z): IlcConstraintI(s), _x(x), _a(a), _z(z) {}
~IlcCheckWhenBoundI() {}
virtual void post();
virtual void propagate() {}
void varDemon(IlcIntVar v);
};
ILCCTDEMON1(RealizeVarBound, IlcCheckWhenBoundI, varDemon, IlcIntVar, v);
void IlcCheckWhenBoundI::post () {
_x[_a].whenValue(RealizeVarBound(getCPEngine(), this, _x[_a]));
}
void IlcCheckWhenBoundI::varDemon (IlcIntVar v) {
if (_x[_a].isFixed()==1){
_z.setMax(64000000);
}
}
IlcConstraint IlcCheckWhenBound(IloCPEngine s, IlcIntVarArray x, IlcInt a, IlcFloatVar z) {
return new (s.getHeap()) IlcCheckWhenBoundI(s, x, a, z);
}
ILOCPCONSTRAINTWRAPPER3(IloCheckWhenBound, cp, IloIntVarArray, _v, IlcInt, _a, IloNumVar, _z) {
cout << "here" << endl;
use(cp, _v);
use(cp, _z);
return IlcCheckWhenBound(cp, cp.getIntVarArray(_v), _a, cp.getFloatVar(_z));
}
This code was working well for CP Optimizer 12.6 but it does not work in CP Optimizer 12.22, as it requires replacing IloCP with IloCPEngine and some other modifications. I revised the above code as follows:
class IlcCheckWhenBoundI : public IlcConstraintI {
protected:
IlcIntVarArray _x;
IlcInt _a;
IlcFloatVar _z;
public:
IlcCheckWhenBoundI(IloCPEngine s, IlcIntVarArray x, IlcInt a, IlcFloatVar z): IlcConstraintI(s), _x(x), _a(a), _z(z) {}
~IlcCheckWhenBoundI() {}
virtual void post();
virtual void propagate() {}
void varDemon(IlcIntVar v);
};
ILCCTDEMON1(RealizeVarBound, IlcCheckWhenBoundI, varDemon, IlcIntVar, v);
void IlcCheckWhenBoundI::post () {
_x[_a].whenValue(RealizeVarBound(getCPEngine(), this, _x[_a]));
}
void IlcCheckWhenBoundI::varDemon (IlcIntVar v) {
if (_x[_a].isFixed()==1){
_z.setMax(64000000);
}
}
IlcConstraint IlcCheckWhenBound(IloCPEngine s, IlcIntVarArray x, IlcInt a, IlcFloatVar z) {
return new (s.getHeap()) IlcCheckWhenBoundI(s, x, a, z);
}
ILOCPCONSTRAINTWRAPPER3(IloCheckWhenBound, cp, IloIntVarArray, _v, IlcInt, _a, IloNumVar, _z) {
use(cp, _v);
use(cp, _z);
return IlcCheckWhenBound(cp, cp.getIntVarArray(_v), _a, cp.getFloatVar(_z));
}
This code debugs but unfortunately runs into an exception error (Exception thrown at 0x00007FF65AE7187C in CP Project1.exe: 0xC0000005: Access violation reading location 0x0000000000000010.) in line "use(cp, _v);". Would you please tell me how to fix the original code or the last code to make it work with CP Optimizer 12.22? I have attached .h files of the original and the revised codes in the case you feel more comfortable checking them. Thanks.