Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to change an existing model by adding constraints in JAVA (internal error, please notify IBM)

    Posted 07/11/13 07:24 AM

    Originally posted by: 3HDM_Dorota_Mankowska


    Hello everyone,

    I am looking for a procedure to make a loop, in which in every iteration the old model will be imported and updated by one extra constraint and exported.

    I add the inequalities step by step to a Vector using static Vector<IloLinearNumExpr> for the Left-Hand-Sides and static Vector<Double> for the Righ-Hand-Sides. This are generated within a class makeCuts with respect to the current situation. Afterwards, I want to reformulate my model by writing it new and adding all the saved inequalities within a class Master_Cut by 

    for (int i = 0; i<cutsLeftSides.size(); i++)
    model.addGe(cutsLeftSides.get(i), cutsRightSides.get(i));

    The error is as follows:

    internal error (Please notify IBM)
    at ilog.concert.cppimpl.concert_wrapJNI.operator_ge__SWIG_1(Native Method)
    at ilog.concert.cppimpl.concert_wrap.operator_ge(concert_wrap.java:747)
    at ilog.concert.IloModelerAdvImpl.ge(IloModelerAdvImpl.java:1471)
    at ilog.concert.IloModelerAdvImpl.ge(IloModelerAdvImpl.java:1462)
    at ilog.concert.IloModelerAdvImpl.addGe(IloModelerAdvImpl.java:1256)
    at CombBend.Master_cut(CombBend.java:416)
    at CPLEX_CombBend.main(CPLEX_CombBend.java:629)

    Can you please tell me, what is wrong with this formula? Or how can I do this in a different way?

    Thank you in advance for your help.

    Best wishes,
    Dorota


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: How to change an existing model by adding constraints in JAVA

    Posted 07/11/13 11:52 AM

    Without seeing your code, it's hard to say. You might try the following:

    for (int i = 0; i<cutsLeftSides.size(); i++) {
      IloLinearNumExpr left = cutsLeftSides.get(i);
      double right = cutsRightSides.get(i);
      System.err.println("Left = " + left + ", right = " + right);
      model.addGe(left, right);
    }

    It would be interesting to see whether the left and right sides are extracted properly and whether they indeed have the correct classes.

    Paul


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: How to change an existing model by adding constraints in JAVA (internal error, please notify IBM)

    Posted 07/12/13 12:34 AM

    It seems like you are using the oplall.jar. Do you use any OPL in your program? If not, can you try if the problem persists if you use cplex.jar (from the cplex/lib folder) instead of oplall.jar?

    Are you trying to add these cuts within a callback or only after model.solve() returned?


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: How to change an existing model by adding constraints in JAVA (internal error, please notify IBM)

    Posted 07/15/13 05:17 AM

    Originally posted by: 3HDM_Dorota_Mankowska


    Thank you for your reply.

    I've tried both and both solution doesn't work. I've solved the problem using Vectors. And no, I don't use it within a callback.

    Nevertheless, do you know any possibility to add an inequality to a model, which has been already solved with model.solve() and exported via model.export()? or do I have to build the model over and over again? Because this causes "Cplex Error 1001: out of memory" pretty quickly.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: How to change an existing model by adding constraints in JAVA (internal error, please notify IBM)

    Posted 07/15/13 05:47 AM

    In order to add a constraint without rebuilding the rest of the model just do cplex.add(...). The next call to cplex.solve() or cplex.exportModel() will take this new constraint into account as well.

    Running out of memory may have several reasons. For example, you may be leaking memory because you did not call end() on all objects before starting a new loop. Or CPLEX may run out of memory during MIP search because the tree got too large.

    To get to the bottom of this out of memory problem we would need to see as much of your code as possible (with a hint where the out of memory occurs) and the log file for the solve that runs out of memory.


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: How to change an existing model by adding constraints in JAVA (internal error, please notify IBM)

    Posted 07/15/13 06:05 AM

    Originally posted by: 3HDM_Dorota_Mankowska


    In my opinion, it is impossible to add or modify an inequality after creating, exporting and importing a model (because I have a loop). At least, it doesn't work in my case. I think, maybe the problem occurs because the lp-form of the model doesn't correspond to the new inequality form which is a_1x_1+a_2x_2+...a_nx_n<=C. I don't know but I can see that cplex.add() doesn't work.

    I do call cplex.end() every time, so this cannot occur any problems. Anyway, it doesn't free the memory. I'll try to use cplex.setParam(IloCplex.StringParam.WorkDir, "C:/temp_ilog_nodes"); to write the node file on my disk. Maybe it will help.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: How to change an existing model by adding constraints in JAVA (internal error, please notify IBM)

    Posted 07/15/13 06:40 AM

    > In my opinion, it is impossible to add or modify an inequality after creating, exporting and importing a
    > model (because I have a loop). At least, it doesn't work in my case. I think, maybe the problem occurs
    > because the lp-form of the model doesn't correspond to the new inequality form which is
    > a_1x_1+a_2x_2+...a_nx_n<=C. I don't know but I can see that cplex.add() doesn't work.
    >
    You must be doing something wrong here because this does work (and has been tested over and over again). Now you are saying you are importing the model again? Is the sequence of commands like this:

    cplex.exportModel("model.sav");
    cplex.solve();
    cplex.importModel("model.sav");
    cplex.add(...);

    If so then you need to be aware that cplex.importModel() will create new instances of IloNumVar to represent the variables in the model just read. In the new constraint you need to use those new instances (and not the IloNumVar instances you used to create the initial model).

    Again, if you could show us some code (or at least the outline of it) it would be much easier to help you (and maybe even spot what you are doing wrong).


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: How to change an existing model by adding constraints in JAVA (internal error, please notify IBM)

    Posted 07/17/13 10:09 AM

    Originally posted by: 3HDM_Dorota_Mankowska


    Thank you.

    As long as I always create new instances of IloNumVar, Cplex cannot deal with this method. Nevertheless, I have solved the problem in a different way.


    #CPLEXOptimizers
    #DecisionOptimization