Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Modelling similar problems

    Posted 03/27/19 03:41 PM

    Originally posted by: BrunoAsiv


    Hi,

     

    I'm trying to solve multiple very similar models in a user cut callback and I'm wondering what is the most efficient between rebuilding the model every time or simply modifying the existing model. Here's a brief outline of what needs to change between models based on the code structure:

     

    loop 1

    {

           loop 2

           {

                   change the right hand term of |N| + |A| constraints

                   loop 3

                   {

                           set the coefficient of a variable to 0 in the objective function;

                           set the coefficient of a variable to 1 in the objective function;

                           add a constraint where one variable == 0;

                           remove a constraint where one variable == 0;

                           solve the instance and calculate cuts;

                   }

           }

    }

     

    In my current code, instead of changing the right hand terms of the constraints, I actually remove them and rebuild them (I didn't notice at first I only needed to change the rht). Removing the constraints from the model has proven to be extremely slow which is why I'm asking this question.

     

    To give an idea of the number of constraints: my models are based on a graph G=(N,A) where |N| is the number of nodes and |A| is the number of arcs. I have a total of |N| + |A| constraints of which I need to modify the right hand term.

     

    Also, if I were to simply modify the model between each instance, which function would set the right hand term of the IloExpr representing my constraints ?

     

    Thank you.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Modelling similar problems

    Posted 03/28/19 02:29 AM

    I am assuming you are using C++ (Java would be similar, C and Python would be completely different)

    My gut feeling is that this wil be the fastest:

    • For updating the constraints collect all constraints to be modified in an IloRangeArray and then update them with a single call to IloRangeArray::setBounds().
    • For updating the objective function, keep an explicit array of coefficients for each variable. Then modify this array, remove the old objective from the model and rebuild and add a new one from the explicit array.
    • For constraints that fix variables to zero or unfix them, collect all variables to be fixed/unfixed into an IloNumVarArray and change all bounds with a single call to IloNumVarArray::setBounds()

    In general, any modification you make to the model triggers a notification to the algorithm that has extracted your model so that the algorithm can update the extracted model to the changes. This is expensive. If you perform updates in batches (like with IloNumVarArray::setBounds() instead of a sequence of IloNumVar::setBounds()) you get only one notification for each batch instead of one notification for each modified element. This usually is much more efficient.

    You can completely avoid these notifications by first unextracting the current model (IloCplex::clearModel()), then modify the IloModel instance and then re-extract the model (IloCplex::extract()). This requires a full re-extraction. Whether this is faster than doing the bulk updates has to be tested.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Modelling similar problems

    Posted 03/28/19 10:18 PM

    Originally posted by: BrunoAsiv


    Thank you for your help!


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Modelling similar problems

    Posted 03/29/19 12:24 AM

    Originally posted by: BrunoAsiv


    Quick follow up question: if I only want to set the lower bounds, do I simply put an array of IloInfinity for the upper bounds array argument in setBounds() ?


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Modelling similar problems

    Posted 03/29/19 04:18 AM

    Whether passing IloInfinity as upper bound is correct or not depends on what the original bounds of the variable are. setBounds() will just set the bounds you pass.

    It may be best to maintain throughout the algorithm an IloNumArray origlb and IloNumArray origub that stores the original/initial lower and upper bounds of the variables. Then you can easily reset bounds to these values.


    #CPLEXOptimizers
    #DecisionOptimization