Topic
7 replies Latest Post - ‏2013-01-30T19:38:04Z by SystemAdmin
kilos
kilos
8 Posts
ACCEPTED ANSWER

Pinned topic Question on using IloUserCutCallBack

‏2012-02-29T20:21:53Z |
Hi all:

I have encountered with a problem when I tried to implement the user cut callback to solve an MIP. Basically, when the callback is called on a node, it reads the values of the current fractional solution, then a small LP is generated and solved, the result of which is used to obtain a user cut to the original MIP.
Here is what I have (in pseudo codes) and corresponding outcomes, and I'm dying to know what's wrong with it... Many thanks for your help!

IloUserCutCallBack(IloIntVarArray x) {

IloEnv env = getEnv();
IloModel model(env);
IloRangeArray con(env);
IloNumVarArray y(env);

for (;;) {
getValues(x_bar, x);
generate constraints for the LP using x_bar and y;
con.add(constraints);
}
cout << con.getSize(); //the size of con looks fine
model.add(con);
IloCplex cplex(model);
cout <<cplex.getNrows() << ", " << cplex.getNcols() << endl; //the weird thing happens here: cplex has zero columns as well as zero rows! And I have no clue about it..
if (cplex.solve())
generate user cuts using x and return;
}

I'm using CPLEX 12.2/12.3 with C++ concert technology in the environment of VS 2008. Any thoughts are appreciated!

Thanks,
David
Updated on 2013-01-30T19:38:04Z at 2013-01-30T19:38:04Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    7929 Posts
    ACCEPTED ANSWER

    Re: Question on using IloUserCutCallBack

    ‏2012-03-01T22:11:16Z  in response to kilos
    Does the problem persist if you replace
    IloEnv env = getEnv();
    

    by a simple
    IloEnv env;
    

    so as to create a new environment instead of reusing an existing one (of course you should then do env.end() at the end of your callback).
    Updated on 2014-03-24T23:33:33Z at 2014-03-24T23:33:33Z by iron-man
    • kilos
      kilos
      8 Posts
      ACCEPTED ANSWER

      Re: Question on using IloUserCutCallBack

      ‏2012-03-02T05:07:44Z  in response to SystemAdmin
      Hi Daniel,

      Thanks for the reply. I just tried out your suggestion but Cplex throws an exception saying "mixing mismatch environments". I guess it's because the duals are obtained from the LP environment, and the original variables (x) are from the MIP environment; therefore, it wouldn't allow a mixed use of them for generating cuts. Essentially, I was trying to generate Benders cuts on each B&B node of an MIP when needed.

      Thanks a bunch!
      David
      • SystemAdmin
        SystemAdmin
        7929 Posts
        ACCEPTED ANSWER

        Re: Question on using IloUserCutCallBack

        ‏2012-03-02T05:13:51Z  in response to kilos
        Does this mean that the model in your callback now looks correct but you ran into another problem?
        By the way, I could not reproduce the problem you described. To me the model in the callback always looks correct. Are you sure your pseudo-callback contained all the relevant code?
        • kilos
          kilos
          8 Posts
          ACCEPTED ANSWER

          Re: Question on using IloUserCutCallBack

          ‏2012-03-02T21:49:07Z  in response to SystemAdmin
          Hi Daniel:

          I was running into another error due to the use of two environments, with the previously described problem remaining unsolved, I'm afraid.

          I've checked the example iloBendersAtsp in Cplex 12.3, where the getEnv() method is adopted in its cut callback. And I also have reviewed my codes for several times without capturing anything. I'm sorry that I couldn't send my codes to you due to confidentiality issues; but I believe the pseudo-codes have captured all relevant aspects. (In the main(), I just called cplex.use(name_callback(env, ...)) to use it, nothing more.)

          In addition, I wondered when you created the subproblem in the callback, did you also add constraints to a rangeArray first, then add this rangeArray to the model? Many thanks!

          Best regards,
          David
        • kilos
          kilos
          8 Posts
          ACCEPTED ANSWER

          Re: Question on using IloUserCutCallBack

          ‏2012-03-03T22:35:49Z  in response to SystemAdmin
          In addition, below are the codes used (some details are omitted). I also tried the lazy constraint callback, but the same problem. Thank you again for your kind help!

          ILOUSERCUTCALLBACK3(cutCallback,
          IloBool&, aborted,
          vector<network*>&, A,
          IloIntVarArray&, x
          ) {
          if (!aborted) {

          IloEnv env = getEnv();

          IloRangeArray L(env), G(env);
          IloNumVarArray omega(env, A.size(), 0, IloInfinity);

          for (IloInt it=0; it<A.size(); it++) {
          if (...) {
          G.add(IloRange(env, Ait->weight1 * getValue(xit), omegait));
          L.add(IloRange(env, omegait, Ait->weight2 * getValue(xit)));
          }
          }
          cout << "Constraint sizes are " << L.getSize() << ", " << G.getSize() << endl;
          IloModel model(env);
          model.add(L);
          model.add(G);
          IloCplex cplex(model);
          cout << "# rows = " << cplex.getNrows() << endl; // still get zero rows here
          cplex.setParam(IloCplex::SimDisplay, 0);
          if (cplex.solve()) {
          //post processing...
          }
          }
          }

          Best regards,
          David
        • kilos
          kilos
          8 Posts
          ACCEPTED ANSWER

          Re: Question on using IloUserCutCallBack

          ‏2012-03-05T22:44:32Z  in response to SystemAdmin
          Some more details on the error:

          in the callback, the model actually takes the two rangeArrays, but it fails when being extracted to the IloCplex instance I created. It throws a concert exception saying "IloExtractable 36860 IloRangeI has not been extracted by IloAlgorithm".

          Does anyone have a similar experience on this issue? Many thanks!
          David
          • SystemAdmin
            SystemAdmin
            7929 Posts
            ACCEPTED ANSWER

            Re: Question on using IloUserCutCallBack

            ‏2013-01-30T19:38:04Z  in response to kilos
            Hi David
            I am experiencing the same problem.I have gone through your problem description and discussion. Can you please share me how did you fix the problem?
            Thanks.
            Roni