I'm creating a CPLEX LP (C++) and am creating constraints using IloExpr in the usual way. eg.
IloExpr cons(m_env);
for (auto& pID : values) {
if (pID != -1) {
cons += variables[pID];
}
}
m_model.add(IloRange(m_env, 0.0, cons, 1.0));
At the end of the loop, cons may not have any variables if all values are -1. I'd like to check this to avoid adding an empty constraint to the model.
How can I do this?
Thanks.