Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Add constraints to an IloOplModel

    Posted Tue May 15, 2012 04:43 AM

    Originally posted by: SystemAdmin


    Hi,
    Here's my problem : I have two MILP that I compute one after the other.
    The second one uses the same data as the first one and some result from the first optimization.
    In order to be able add cuts an to use heuristics easily, I computed my problem in C++,
    But to be able to change fastely the model, I computed it in OPL.
    So, I import the .mod and .data with the associated functions, but IloOplModel does non have an add() method, so I canot add the constraints that use first optimization data.
    And I don't want to have to write an .dat file and then add it as a second Source for the problem because I think this is stupid to write a file to open it right away. Thus, I don't know if that is possible...

    Is there a way to convert an IloOplModel into a IloModel once it has been initialized with its .mod and .dat files ?

    Thanks for your time,
    Adrian
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Add constraints to an IloOplModel

    Posted Tue May 15, 2012 09:57 AM
    hi,

    could

    IloOplModel opl = ...
    opl.getCplex().getModel();
    


    help?

    Regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Add constraints to an IloOplModel

    Posted Tue May 15, 2012 09:15 PM

    Originally posted by: gustavokambara


    But how can I add such constraints since I don't have the decision variables explicitly declared in Java?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Add constraints to an IloOplModel

    Posted Wed May 16, 2012 03:01 AM

    Originally posted by: SystemAdmin


    This one, I've got the answer !

    opl.generate();
    IloModel model = opl.getCplex().getModel();

    IloNumVarMap X = opl.getElement("X").asNumVarMap();

    for(IloInt t=1; t<=T; t++){
    for(IloInt r=1; r<=R; r++){
    IloRange C(env, f_min(t,r), V[t].get(r), f_max(t,r));
    model.add(C);
    }
    Thanks again, Alex
    Adrian
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Add constraints to an IloOplModel

    Posted Wed May 16, 2012 07:50 AM

    Originally posted by: gustavokambara


    And where do you use X? V[t] = X[t]?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Add constraints to an IloOplModel

    Posted Wed May 16, 2012 08:52 AM

    Originally posted by: SystemAdmin


    Yes, sorry, I meant X (replace V with X)
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Add constraints to an IloOplModel

    Posted Tue January 17, 2017 10:41 AM

    Originally posted by: chumpster


    Hi, I have an extension to this question:

    Once I get an IloModel from opl.getCplex().getModel(); and make some modifications to it, how do I update the IloCplex object to call solve()?

    I tried to use cplex.setModel(model) to update cplex but all I get is a 
    java.lang.UnsupportedOperationException. Please let me know what I'm missing or doing wrong. 

    Thanks in advance.

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Add constraints to an IloOplModel

    Posted Tue January 17, 2017 11:18 AM

    Hi,

    same as within in a main in OPL you have two options:

    1) With regeneration

     

    2) Without regeneration

    • In OPL see https://www.ibm.com/developerworks/community/forums/html/topic?id=0289cdc7-a237-4442-91f3-9c8e2944a8a7&ps=25
    • In Java  see example CPLEX_Studio127\opl\examples\opl_interfaces\java\cutstock_change\src\cutstock_change
    • for (int i = 1; i < nWdth + 1; i++) {
                          double coef = subCplex.getValue(subOpl.getElement("Use") .asIntVarMap().get(i));
                          IloForAllRange forAll = (IloForAllRange) masterOpl.getElement( "ctFill").asConstraintMap().get(i);
                          masterCplex.setLinearCoef(forAll, newVar, coef);
                      }


    #DecisionOptimization
    #OPLusingCPLEXOptimizer