Great. Thanks very much, Philippe. My code is working now. I appreciate your time.
Original Message:
Sent: Wed April 23, 2025 12:05 PM
From: PhR
Subject: IloCP to IloCPEngine in IlcConstraintI (CP Optimizer 12.22)
I think the problem comes from this code :
//Definition of new variables IloIntVarArray Number_of_Used_ORs_On_Day(*env, Number_Days); for (int d = 0; d < Number_Days; d++) { Number_of_Used_ORs_On_Day[d] = IloIntVar(*env, 0, RoomMatrix[d]); All_Regular_Int_Variables.add(Number_of_Used_ORs_On_Day); //Number_of_Used_ORs_On_Day[d] = IloIntVar(env, 0, 300); }
I should probably be
All_Regular_Int_Variables.add(Number_of_Used_ORs_On_Day[d]);
In the original code the whole array is added and it contains indexes that have not been set. Since this array appears in your custom constraints, use(x) will be called on null pointer elements and crash.
Original Message:
Sent: Tue April 22, 2025 04:35 PM
From: Hossein H
Subject: IloCP to IloCPEngine in IlcConstraintI (CP Optimizer 12.22)
Dear Philippe,
Thanks very much for your reply. I have attached my code as a zip file. I would be very thankful if you could run it and tell me what the problem is. In the attached zip file, in line 95 of file "cplex part.cpp", you need to change ARG1 to the address of the folder in your PC where you put the attached data file "Naple_Instance_Week_55.data".
Thanks again for your time.
------------------------------
Hossein H
Original Message:
Sent: Thu April 17, 2025 08:59 AM
From: PhR
Subject: IloCP to IloCPEngine in IlcConstraintI (CP Optimizer 12.22)
I assume your new release is CP Optimizer 22.1.2. Using this release, there is no problem when running this code. This is how I used it :
IloEnv env; IloModel model(env); IloIntVarArray x(env, 5, -10, 10); IloNumVar z(env, -20, 20); IloIntVar zi(env, -200, 200); model.add(zi == z * 10); model.add(IloCheckWhenBound(env, x, 3, z)); IloCP cp(model); cp.solve(); env.end();
and I replaced _z.setMax(64000000);
by _z.setMax(0);
Can you post a (small) code that one can run and that shows the problem ?
Thanks.
Philippe
Original Message:
Sent: Tue April 15, 2025 06:44 PM
From: Hossein H
Subject: IloCP to IloCPEngine in IlcConstraintI (CP Optimizer 12.22)
Hi,
I am running a code in CP Optimizer 12.22 that requires using IlcConstraint and ILOCPCONSTRAINTWRAPPER3 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) {
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.
------------------------------
Hossein H
------------------------------