0

I have a set of constraints like:

x1 >= x2 + x3 + x4; x2>= x3 + x4 + x7; x3 >= x4 + x5; and so on.

For each variable, there is an array that stores the list of variables that will be used in the constraint RHS. That is, for variable 1, the array includes array[1] = {2, 3, 4}. To implement this in c++, I used IloNumExpr, but it did not work:

IloNumExpr Constraint(env);
for (int i = 0; i < 3; i++){
     for(int j = 0; j < array_size[i]; j++)
        {
            Constraint += x[array[i][j]];
        }
        model.add(x[i] >= Constraint);
} 

What is the mistake that I am doing here?

Thanks

user2147241
  • 53
  • 1
  • 9

1 Answers1

0

When you say it didn't work, what are you getting? I can guess that your problem is that you are just accumulating more and more stuff into the one IloNumExpr. Probably you should have put the IloNumExpr declaration inside your outer loop?

I always find that dumping your model out as an LP file using cplex.exportModel() is very useful for seeing what model you actually built.

TimChippingtonDerrick
  • 2,042
  • 1
  • 12
  • 13