Question

I'm writing a column generation algorithm for a large problem and after 5 iterations the algorithm starts to violate the constraints ensuring that the sum over i of m(i,j)*x(i)=1 for all j. I have never used Cplex java Api before so I was wondering if this might be a common problem, that is that the constraints do not hold? Here is the constraint:

for( j=1; j <=K; j++) {
  IloLinearNumExpr lhs = cplex.linearNumExpr();
  for(i=1; i <= C; i++) {
      lhs.addTerm(m[i][j], x[i]); 
  }   
  con[j] = cplex.addEq(lhs, 1);
  con[j].setName("yourConstraintName(" + j + ")");      
}
Was it helpful?

Solution

It is far more likely to be a flaw in your code's logic. The code snippet you give us looks OK to me - I can't see where the problem would be without more context, knowing what the values are in the m matrix etc.

First, try outputting your model just before you solve it in each iteration to an LP file using cplex.exportModel("name.lp"). You probably need to create a new name for each iteration, e.g. including the iteration number in the name so they don't keep overwriting the same file each time. Then you can check to see whether the constraints you expect are in the file and have the correct terms in them.

Secondly, try adding some old-school logging in your code so you can see in more detail exactly what your code is doing.

Also, you might want to check that the value of the coefficient is non-zero in each term that you add to the expression. It doesn't do any harm having those zero terms in the expression, but usually there are only non-zero values for a small proportion of the possible terms, and having all of them there makes the expression much bigger and harder to check in the LP file.

CPLEX is tested in enormous detail before each new version is released, and it is widely used and depended on by thousands of companies and academics around the word, and that could not happen if it was a common problem that the answers CPLEX provides did not respect the constraints.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top