Originally posted by: Charles.Yu.Wang
Dear Folks,
I meet this problem " Using empty IloNumVar handle" and cannot solve it. Basically, I think it is because I call something which is not declared, however, I cannot understand it. The following is my code.
IloModel patternGenModel(env);
IloObjective ReducedCost = IloAdd(patternGenModel, IloMinimize(env, 1));
IloRangeArray halfDuplexConstraints(env);
IloRangeArray coexistConstraints(env);
IloNumVarArray activeLink(env, nodeNumber*nodeNumber, 0.0, 1.0, ILOINT);
// (24) sum(v_ij) + sum(v_ji) <= 1: half-duplex constraint, whether a node is concurrently engaged in two active links
for (i=0;i<nodeNumber;i++)
{
IloExpr duplexExpr(env);//for each of the i, there will be an expression, thus a new expression should be created.
for (j=0;j<nodeNumber;j++)
{
if(i==j)
{
cout << " step 1 " << activeLink.getSize() <<endl;
activeLink[nodeNumber*i+j]=0;
continue;
}
duplexExpr += activeLink[nodeNumber*i+j];
duplexExpr += activeLink[nodeNumber*j+i];
}
halfDuplexConstraints.add(duplexExpr <= 1);
duplexExpr.end();//when the expression is added to the constraints, we should end the expression.
}
patternGenModel.add(halfDuplexConstraints);
// (25) v_ij+v_uw <= 1 + F[ij, uw]: physical constraint, whether two links can coexist
IloExpr coexistExpr(env);
for (i=0;i<nodeNumber;i++)
{
for (j=0;j<nodeNumber;j++)
{
if(i==j) continue;
for(u=0;u<nodeNumber;u++)
{
for(v=0;v<nodeNumber;v++)
{
if(v==u || (u==i&&v==j)) continue;
coexistExpr = activeLink[nodeNumber*i+j]+activeLink[nodeNumber*u+v];
coexistConstraints.add(coexistExpr <= 1+conservativeCoexistanceTest(linkMatrix[i][j], linkMatrix[u][v]));
}
}
}
}
patternGenModel.add(coexistConstraints);
/* Variables for column generation method */
IloNumArray dualValue(env, nodeNumber*nodeNumber);//pi_ij
IloNumArray newPattern(env, nodeNumber*nodeNumber);//v_ij
IloCplex subProblemSolver(patternGenModel); // The solver of sub problem
int count = 0;
for(;;)//loop until the best result generate
{
caseINonCoopSolver.solve();
for(i=0;i<nodeNumber;i++)
{
for(j=0;j<nodeNumber;j++)
{
ReducedCost.setLinearCoef(activeLink[i*nodeNumber+j], -linkMatrix[i][j].getRate() * caseINonCoopSolver.getDual(capacityConstraints[i*nodeNumber+j]));
}
}
subProblemSolver.solve();
cout << " step 4: " << " reduceCost " << subProblemSolver.getValue(ReducedCost) <<endl;
if(subProblemSolver.getValue(ReducedCost) > -1.0e-6) break;//the reduced value is positive, then, the loop should end.
cout << " step 5 " << activeLink.getSize() <<endl;
for (int ii = 0; ii<nodeNumber*nodeNumber; ii++)
{
cout << " step 6 " <<endl;
newPattern[ii] = subProblemSolver.getValue(activeLink[ii]);
cout << " *********** i " << ii << " patt " << subProblemSolver.getValue(activeLink[ii]) << " " << newPattern[ii] <<endl;
}
After step 6, it stops and say that ERROR. However, with step 5, it is clear that activeLink.getSize() = 16. Why I cannot even get the value of activeLink[0]? Actually, it is set in my program as 0 after step 1.
I cannot figure out where does this problem come out... Can anyone help me about this?
#CPLEXOptimizers#DecisionOptimization