Originally posted by: SystemAdmin
Hello,
I am using a cut callback to generate cuts in my code. I just tested my code via PurifyPlus and it found memory leak in my code. I know that the memory leak comes from my callback because when I remove it I don't have memory leak anymore. I read my code several times and I am confused, because I only define one IloExpr, cut, and one dynamic array, R[], and I end both of them before leaving the callback. The rest of the variables have been defined as the parameters of the callback. I don't know what causes the memory leak!
I appreciate if you can let me know what you think.
I copy my callback code here:
ILOCUTCALLBACK7(makecut, IloNumVarArray, U, BoolVarMatrix, Y, BoolVarMatrix3D, X, BoolVarMatrix, u, double*, probability, int*, orig, int**, A){
IloEnv env = getEnv();
bool integrality = true;
for (int p=0; p<orig
M+1; p++){
if (integrality == false)
break;
for (int i=0; i<U.getSize(); i++){
if (getValue(Y[p][i]) > 0.0001 && getValue(Y[p][i]) < 0.9999){
integrality = false;
break;
}
}
}
for (int i=0; i<U.getSize(); i++){
if (integrality == false)
break;
for (int j=0; j<U.getSize(); j++){
if (integrality == false)
break;
if (A[i][j] == 1){
//orig
M+3 = K
for (int k=0; k<orig
M+3; k++){
if (getValue(X[i][j][k]) > 0.0001 && getValue(X[i][j][k]) < 0.9999){
integrality = false;
break;
}
}
}
}
}
for (int i=0; i<U.getSize(); i++){
if (integrality == false)
break;
//orig
M+4 = G
for (int g=0; g<orig
M+4; g++){
if (getValue(u[i][g]) > 0.0001 && getValue(u[i][g]) < 0.9999){
integrality = false;
break;
}
}
}
if(integrality){
double origin, prob;
double *R;
R = new double
http://U.getSize();
for (int k = 0; k < orig
M+3; k++){
origin = 0;
for (int i = 0; i < U.getSize(); i++){
R[i] = 1 - (1.0 * getValue(U[i]) * getValue(U[i])) / (1.0 * orig[M] * orig[M]);
origin += (R[i] * getValue(Y[orig
k][i]));
}
prob = log(origin);
for (int i = 0; i < U.getSize(); i++)
for(int j = 0; j < U.getSize(); j++)
if(A[i][j] == 1)
prob += (getValue(X[i][j][k]) * log(R[j]));
if (prob < log(probability[k])){
IloExpr cut(env, 0);
for (int j = 0; j < U.getSize(); j++){
for (int i = 0; i < U.getSize(); i++){
if ((A[i][j] > 0.999 && getValue(X[i][j][k]) > 0.999) || getValue(Y[orig
k][j]) > 0.999){
for (int l=0; l<orig
M+3; l++){
if (getValue(Y[orig
l][j]) > 0.999){
cut += (1-Y[orig
l][j]);
}
else{
for (int ii=0; ii<U.getSize(); ii++){
if (A
ii[j] > 0.999 && getValue(X
ii[j][l]) > 0.999){
cut += (1-X
ii[j][l]);
break;
}
}
}
}
break;
}
}
}
cout << cut << endl;
add (cut >= 1);
orig
M+6++;
cut.end();
}
}
delete[] R;
}
}
#CPLEXOptimizers#DecisionOptimization