Dear Shouwei,
The expression :
y[i][j][m] <= q[j][m]
cannot be used in an if statement since it is of type IloConstraint. The reason for that is that y[i][j][m] is a model object for which the <= operator has been overloaded, and so returns an IloConstraint.
You shouldn't declare y (nor q) as to contain model objects but as plain C++ 3d (or 2d for q) matrices.
I hope this helps,
Cheers,
------------------------------
Renaud Dumeur
------------------------------
Original Message:
Sent: Tue January 25, 2022 03:05 PM
From: Shouwei Li
Subject: Cplex with C++
Hi there,
I am new to cplex and come across a question.
Could you please show me how to solve this error?
Thanks a lot!
/* cplex code range C = 1..N; range Y = 1..10; range C_D = 1..(N+1); dvar int+ q[C_D][Y]; int d[C] = ...; dvar boolean y[C_D][C_D][Y] forall(j in C, m in Y) d[j]*sum(i in C_D) y[i][j][m] <= q[j][m];*///I translate this constraint to C++ as following: for (int j = 0; j < C; ++j) for (int m = 0; m < Y; ++m) { IloExpr expr {env}; for (int i = 0; i < V; ++i) if (y[i][j][m] <= q[j][m]) // error: Cannot convert "IloConstraint" to bool expr += (y[i][j][m] <= q[j][m]); model.add(d[j] * expr); }
------------------------------
Shouwei Li
------------------------------
#DecisionOptimization