Answers to: Adding Variables or Modifying Existing Constraints During Callbacks with Cplex (C++)http://www.or-exchange.com/questions/14311/adding-variables-or-modifying-existing-constraints-during-callbacks-with-cplex-c<p>I am trying to implement an optimization algorithm using cplex C++ Concert Technology and I have two questions:</p>
<p>1) Is it possible to use a callback (e.g. a lazy constraint) to <em>change</em> an existing constraint of the problem? From what I understand this is not possible, but I am wondering if there is a work around.</p>
<p>2) Can I add new variables to the model with a callback? Encoding some constraints in my lazy constraint callback would be much more convenient if I could define helper variables. Similar as before, I think it is not possible, but perhaps there are some alternatives.</p>
<p>In short, during the callback I can learn some information about the problem and based on this I would like to add some constraints. I have a constraint b = b1 + b2 + .... , but there are exponentially many bi plus I do not know all of them in advance. However, every time I compute a feasible solution I could add one of the bi to the sum that defines b. Clearly there can be a memory blowup here, but I am hoping that I will find a suitable solution before that happens.</p>
<p>p.s. One solution that I have is that I can simply abort the current solving, add and modify the constraints, and then call solve() again. This is one possibility, but I assume there is a better way.</p>
<p>Thank you in advance!</p>enFri, 21 Oct 2016 19:49:27 -0400Answer by Paul Rubinhttp://www.or-exchange.com/questions/14311/adding-variables-or-modifying-existing-constraints-during-callbacks-with-cplex-c/14321<p>1) It is not possible to change a constraint mid-solve, with one exception: you can <em>tighten</em> a constraint, by leaving it in place and piling the tighter version on top of it. For instance, if the original model contains \(a'x \le 20\) and you decide you want \(a'x \le 10\), just add the latter constraint (in a lazy constraint callback) and don't worry about the looser version.</p>
<p>2) No, you cannot add variables mid-solve. There are, however, frameworks for doing this (known as branch-and-price or branch-cut-and-price), some of which can use CPLEX as the solver engine. You might want to look at <a href="https://projects.coin-or.org/Bcp">BCP</a> or <a href="https://projects.coin-or.org/SYMPHONY">Symphony</a>.</p>Paul RubinFri, 21 Oct 2016 19:49:27 -0400http://www.or-exchange.com/questions/14311/adding-variables-or-modifying-existing-constraints-during-callbacks-with-cplex-c/14321