Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

extractable is not dynamically updated

  • 1.  extractable is not dynamically updated

    Posted 03/18/10 04:09 PM

    Originally posted by: SystemAdmin


    Hi everybody,

    According to the following statement from the manual:


    When you change an extractable object, for example by removing it from a model, Concert Technology notifies algorithms that have extracted the model containing this extractable object about the change. Member functions that carry out such notification are noted in this documentation.

    and also from my experience when an instance of IloRangeArray or any other extrable which is added to a model is modified outside the model then the correspnding changes will take place inside the model at least once the model is extracted. This not what I am experiencing today with Concert 29 while still the help manual emphasises on it.

    Immagine you have an instance of IloRangeArray added to the master problem of benders and you need to add cuts to it and due to any reason you ndont want to have the cuts being added directly to the model.

    Any one has experienced this before?

    Best regards,
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: extractable is not dynamically updated

    Posted 03/18/10 05:13 PM

    Originally posted by: SystemAdmin


    This is strange as this is actually tested in our regression tests.

    Is it possible for you to construct a simple example that triggers this bug?
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: extractable is not dynamically updated

    Posted 03/18/10 05:52 PM

    Originally posted by: SystemAdmin


    Hi Tobias,

    I am ina very bad hurry before approachign a deadline so I made it very simple. Looks naive but might be worth testing:
    I made a simple exampel as following:
    #include <ilcplex/ilocplex.h>
    ILOSTLBEGIN
    int main(int argc, char **argv) {

    IloEnv env;
    try {

    IloNumVarArray x(env, 10, 0,1, ILOINT);

    IloModel model(env);
    IloCplex cplex(env);
    IloExpr exprObj(env);
    exprObj = IloSum(x);

    IloRangeArray rng1(env);
    IloRangeArray rng2(env);

    rng1.add(x[1]+x[2] + x[3] + x[4] <= 1);

    IloObjective obj(env, IloMaximize(env));
    obj.setExpr(exprObj);
    model.add(rng1);
    model.add(rng2);

    cplex.extract(model);
    cplex.solve();
    cout<< cplex.getObjValue() << endl;
    cplex.exportModel("before.lp");
    rng2.add(x[5]+x[6] + x[7] + x[8] <= 1);

    // optional cplex.extract(model);
    cplex.solve();
    cout<< cplex.getObjValue() << endl;
    cplex.exportModel("after.lp");
    }
    catch(IloException& e) {
    cerr << " ERROR: " << e << endl;
    }
    catch(...) {
    cerr << " ERROR" << endl;
    }
    env.end();
    return 0;
    }
    this is my output
    // before.lp
    \Problem name: IloCplex

    Minimize
    obj:
    Subject To
    id14: id1 + id2 + id3 + id4 <= 1
    Bounds
    0 <= id1 <= 1
    0 <= id2 <= 1
    0 <= id3 <= 1
    0 <= id4 <= 1
    Binaries
    id1 id2 id3 id4
    End

    // after.lp
    \Problem name: IloCplex

    Minimize
    obj:
    Subject To
    id14: id1 + id2 + id3 + id4 <= 1
    Bounds
    0 <= id1 <= 1
    0 <= id2 <= 1
    0 <= id3 <= 1
    0 <= id4 <= 1
    Binaries
    id1 id2 id3 id4
    End

    I hope that helps.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: extractable is not dynamically updated

    Posted 03/19/10 03:17 AM

    Originally posted by: SystemAdmin


    At least for your example the behavior you describe is expected (and correct).
    It is the same for CPLEX 10.2 and CPLEX 12.1.

    The documentation of IloRangeArray::add() does not claim that algorithms that have extracted the array are notified. Only methods that are marked with the following sentence do so (see IloRange::setExpr()):
    • snip ---
    Note
    The member function setExpr notifies Concert Technology algorithms about this change of this invoking object.
    • snap ---
    So adding to/removing from an IloRangeArray will not notify algorithms about the change in the array. Only changes to the array elements themselves will be propagated.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: extractable is not dynamically updated

    Posted 03/19/10 03:39 AM

    Originally posted by: SystemAdmin


    Thanks for your reply.
    what is the way around it if you dont want to add all such cuts directly to the model and and later on iterating over all the objects in the model to remove them? IloCOnstraintArray looks the same.
    best regards,
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: extractable is not dynamically updated

    Posted 03/19/10 04:37 AM

    Originally posted by: SystemAdmin


    Can't you just also add to the model when you add to the array in your approach? Or is that too cumbersome?
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: extractable is not dynamically updated

    Posted 03/19/10 05:07 AM

    Originally posted by: SystemAdmin


    This is definitely possible but as iterations proceed it get more and more time consuming to remove the range, modify it, add it again. Moreover, when it is removed the allocated memry does not seem to be freed and when you add it again a duplicate space seems being occupied.
    this way the trend of increase in memory size is higher.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: extractable is not dynamically updated

    Posted 03/19/10 05:26 AM

    Originally posted by: SystemAdmin


    I don't see why you have to remove the range from the model. Do you do this to get the update into the model? That would not be necessary. Once the range is in the model any changes applied to the range itself will be propagated to the model.
    Or are you using the range array to specify different sets of active constraints between the iterations?
    Concerning your memory issues: is it possible that you miss some calls to end() if you no longer need the ranges?
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: extractable is not dynamically updated

    Posted 03/19/10 05:34 AM

    Originally posted by: SystemAdmin


    Thanks for your attention.
    Let me explain it more clear again.

    For every given piece of info I must run my benders algorithm. This bedners algorithm needs minor modifications in the master problem as well as subprblem. So I do not need to re-create them.
    The thing I need is to remove the set of cuts added before and starting a fresh iteratiove procedure again.

    I would rather not using normal ranges because then I dont want to iterate over the whole objects (O(n^5)) in the model to find them and remove them. I would rather have them in an iloragne array so that can be more effiecientluy removed.

    Apparently range arrays are not updated automatically when a cut is added. is there any way around it? documentation does not recommand anything to my understanding.
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: extractable is not dynamically updated

    Posted 03/19/10 05:53 AM

    Originally posted by: SystemAdmin


    Now I got it, sorry. I think you can do the following:
    // Prepare model and do initial solve
    ...
    while ( !finished ) {
       // Create cuts to be added.
       IloRangeArray ranges(env);
       ...
     
       // Add new cuts to model and resolve.
       model.add(ranges);
       cplex.solve();
     
       // Remove all cuts that were added before.
       model.remove(ranges);
    }
    

    This should do the trick. Adding and removing the arrays of ranges directly to the model will trigger the appropriate updates. In the example you posted earlier this would just be an additional 'model.add(rng2)' before the second solve instead of 'cplex.extract(model)'.
    Is that feasible for you?
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: extractable is not dynamically updated

    Posted 03/19/10 06:08 AM

    Originally posted by: SystemAdmin


    Hi again, thanks for your comment. I dont know how can you write so nice and colorfull snippets but I can only reply in plain text.
    That is exactly what I mean; what if you need to declare the ilorangearray before the loop because we have to add cut to our cuts at each iteration. Doing this way as I have already experienced gets difficult as iterations proceed. imagine at iteration 40+ removing and adding 40+ cuts is actually time quite consuming. in my case is equal to the time spent to solve one of my lp problems.

    // Prepare model and do initial solve
    ...
    // Create cuts to be added.
    IloRangeArray ranges(env);
    while ( !finished ) {
    ...
    // Add cut to the range
    ranges.add(range);
    // Add new cuts to model and resolve.
    model.add(ranges);
    cplex.solve();

    // Remove all cuts that were added before.
    model.remove(ranges);
    }
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: extractable is not dynamically updated

    Posted 03/19/10 06:41 AM

    Originally posted by: SystemAdmin


    I attached the markups for "fancy posts" to this message.
    I am a little confused now: Your last snippet looks reasonable to me but it is still too slow or it is not doing what you want?
    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: extractable is not dynamically updated

    Posted 03/19/10 07:00 AM

    Originally posted by: SystemAdmin


    thanks;

    it does actually but is too slow and I am sure there should be a more clever way of doing it.
    #CPLEXOptimizers
    #DecisionOptimization