I am using CPLEX concert technology in C++. As you can see in the code, when I want to employ "while" with the expression "LP-LB <=0", I face with the error of "expression must have bool type". What's the problem? If you need the whole parts of the code, I can share them here.
//***********************************************************
//***********************************************************
//**************** Lagragian Dual ***************************
//***********************************************************
// Define Lagragian Relaxation Model
IloModel LRDual(env);
// **** Parameter setting
IloArray< IloNumArray > Lambda(env, k);
for (int b = 0; b < k; b++)
{
Lambda[b] = IloNumArray(env, m, 0, IloIntMax);
}
for (int b = 0; b < k; b++)
{
for (int o = 0; o < m; o++)
{
Lambda[b][o] = 0;
}
}
// **** End Parameter Setting
//***** Define LR Objective Function *********
//********************************************
IloNumVar Makespan_Dual(env, 0, IloInfinity);
IloNumVar Z_LR1(env, 0, IloInfinity);
LRDual.add(IloMinimize(env, Z_LR1));
//************ Lagrangian Relaxation Constraint *************
//***********************************************************
IloExpr S_D_RCon(env);
IloExpr S_D_LaMa(env);
for (int b = 0; b < k; b++)
{
for (int o = 0; o < m; o++)
{
for (int j = 0; j < n; j++)
{
S_D_RCon += s[j] * x[j][b][o];
}
S_D_LaMa += Lambda[b][o] * (B[o] - S_D_RCon);
S_D_RCon.end();
S_D_RCon = IloExpr(env);
}
}
LRDual.add(Z_LR1 == Makespan_Dual - S_D_LaMa);
//**************************************************
//**************** End LR Constraint ***************
// Constraint Set 2
IloExpr S_D1(env);
for (int j = 0; j < n; j++)
{
for (int b = 0; b < k; b++)
{
for (int M1 = 0; M1 < m; M1++)
{
S_D1 += x[j][b][M1];
}
}
LRDual.add(S_D1 == 1);
S_D1.end();
S_D1 = IloExpr(env);
}
//End Constraint Set 2
// Constraint Set 4
for (int j = 0; j < n; j++)
{
for (int b = 0; b < k; b++)
{
for (int M = 0; M < m; M++)
{
LRDual.add(P[b][M] >= (p[j] * x[j][b][M]));
}
}
}
//End Constraint Set 4
// Constraint Set 5
IloExpr S_D3(env);
for (int M = 0; M < m; M++)
{
for (int b = 0; b < k; b++)
S_D3 += P[b][M];
LRDual.add(Makespan_Dual >= S_D3);
S_D3.end();
S_D3 = IloExpr(env);
}
//End Constraint Set 5
//*******************************************************
//*************** END CONSTRAINT DEFINITION**************
// *******************************************************
//********************************************************
//************* LR Algorithm *****************************
//********************************************************
cplex.extract(LRDual);
// Parameters
IloInt N_repeat = 15;
IloInt intercount = 0;
IloInt Sigma = 2;
IloNumVar LB(env, 0, IloInfinity);
IloNumVar LP(env, 0, IloInfinity);
LB = Z_LR1;
LP = Makespan;
IloInt UB = 0;
int total = 0;
for (int i = 0; i < n; i++)
{
total += p[i];
}
UB = total;
while (LP-LB <=0)
{
}
I would be thankful if you help me to get rid of this error.
It is because LP is of type IloNumVar. It doesn't have any specific value until after CPLEX has solved the problem, and even then you will need to ask CPLEX for the selected value of that variable. You cannot use these CPLEX modelling variables as if they have a value like normal C++ variables. The same is true in the other APIs (C#, Java etc).