Topic
  • 5 replies
  • Latest Post - ‏2012-05-16T12:52:08Z by SystemAdmin
SystemAdmin
SystemAdmin
1883 Posts

Pinned topic Add constraints to an IloOplModel

‏2012-05-15T08:43:19Z |
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
Updated on 2012-05-16T12:52:08Z at 2012-05-16T12:52:08Z by SystemAdmin
  • AlexFleischer
    AlexFleischer
    1206 Posts

    Re: Add constraints to an IloOplModel

    ‏2012-05-15T13:56:45Z  
    hi,

    could

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


    help?

    Regards
    Updated on 2014-03-26T05:56:34Z at 2014-03-26T05:56:34Z by AlexFleischer
  • gustavokambara
    gustavokambara
    3 Posts

    Re: Add constraints to an IloOplModel

    ‏2012-05-16T01:15:11Z  
    hi,

    could

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">IloOplModel opl = ... opl.getCplex().getModel(); </pre>

    help?

    Regards
    But how can I add such constraints since I don't have the decision variables explicitly declared in Java?
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: Add constraints to an IloOplModel

    ‏2012-05-16T07:00:48Z  
    But how can I add such constraints since I don't have the decision variables explicitly declared in Java?
    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
  • gustavokambara
    gustavokambara
    3 Posts

    Re: Add constraints to an IloOplModel

    ‏2012-05-16T11:50:06Z  
    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
    And where do you use X? V[t] = X[t]?
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: Add constraints to an IloOplModel

    ‏2012-05-16T12:52:08Z  
    And where do you use X? V[t] = X[t]?
    Yes, sorry, I meant X (replace V with X)