Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  C++: Remove/delete added cuts before solving again

    Posted 09/21/12 04:52 AM

    Originally posted by: MarkusS.


    Hi!

    I am repeatedly solving a model and what to delete some/all of my added cuts before resolving.

    Right now, I am doing this in the following way:

    In the LazyConstraint/UserCutCB, "myCutStruct" is a pointer to a struct.
    IloExtractableI* myC=add(myCut>=0).getImpl();
    myCutStruct->myCuts.push_back(myC);
    myCut.end();
    


    After calling cplex.solve() in my main class:
    for(int i=0;i<stop;i++)
    {
    myModel.remove(myCutStruct->myCuts.at(i));
            myCutStruct->myCuts.at(i)->end();
    }
    myCutStruct->myCuts.clear();
    

    Is this doing what I want/if yes, is there a better way?

    Thanky you for your helpe!
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: C++: Remove/delete added cuts before solving again

    Posted 09/23/12 05:54 PM

    Originally posted by: SystemAdmin


    Cuts added in a callback are not literally added to the model, and cannot be deleted from the model. They expire when the call to solve returns.

    Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: C++: Remove/delete added cuts before solving again

    Posted 09/24/12 06:11 AM

    Originally posted by: MarkusS.


    Thank you, so this means the passage "Not only does CPLEX® track all modifications of the model it has extracted, but also it tries to maintain as much solution information from a previous invocation of solve as is possible and reasonable. You have already encountered what is perhaps the most important modification method, that is, the method IloModel::add for adding modeling objects to a model. Conversely, you may call IloModel::remove to remove a modeling object from a model." in the manual does not apply to cuts added in a callback?

    To understand CPLEX a little bit better, what does my code do (nothing?)/why doesn't it result in some kind of error if the cuts automatically expire and then I remove them?
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: C++: Remove/delete added cuts before solving again

    Posted 09/25/12 05:46 PM

    Originally posted by: SystemAdmin


    > MarkusS. wrote:
    > Thank you, so this means the passage "Not only does CPLEX® track all modifications of the model it has extracted, but also it tries to maintain as much solution information from a previous invocation of solve as is possible and reasonable. You have already encountered what is perhaps the most important modification method, that is, the method IloModel::add for adding modeling objects to a model. Conversely, you may call IloModel::remove to remove a modeling object from a model." in the manual does not apply to cuts added in a callback?

    Correct (as I understand things).
    >
    > To understand CPLEX a little bit better, what does my code do (nothing?)/why doesn't it result in some kind of error if the cuts automatically expire and then I remove them?

    Apparently it just fails silently. As a test (using the Java API, but C++ should be the same), I created a small model, created a constraint
    but did not add it to the model, then invoked remove() on that constraint. No exception was thrown, and the model was unaffected.

    Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: C++: Remove/delete added cuts before solving again

    Posted 10/01/12 10:54 AM

    Originally posted by: SystemAdmin


    > > Thank you, so this means the passage "Not only does CPLEX® track all modifications of the model it has extracted, but also it tries to maintain as much solution information from a previous invocation of solve as is possible and reasonable. You have already encountered what is perhaps the most important modification method, that is, the method IloModel::add for adding modeling objects to a model. Conversely, you may call IloModel::remove to remove a modeling object from a model." in the manual does not apply to cuts added in a callback?
    >
    > Correct (as I understand things).
    >
    You understand correctly. Cuts are not remembered here.

    > > To understand CPLEX a little bit better, what does my code do (nothing?)/why doesn't it result in some kind of error if the cuts automatically expire and then I remove them?
    >
    > Apparently it just fails silently. As a test (using the Java API, but C++ should be the same), I created a small model, created a constraint
    > but did not add it to the model, then invoked remove() on that constraint. No exception was thrown, and the model was unaffected.
    >
    It does not exactly fail silently. Removing something that was never added is just a no-op. In order to check whether something is actually extracted to an algorithm you can use the isExtracted() method. As you already observed, it is safe to remove things that were never added.
    #CPLEXOptimizers
    #DecisionOptimization