Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to efficiently solve LP iteratively with modifying coefficient?

    Posted 03/11/12 10:38 PM

    Originally posted by: YongjiaSong


    Hi all,

    I have a problem in iteratively solving the LP. In each iteration, I have to modify the objective coefficient as well as variable bounds.

    How can I implement this using C++ in CPLEX?

    I have done an easy version of it by only changing the objective coefficient. What I did is:

    IloModel singleLP(env);
    IloCplex singleLP_Cplex(singleLP);
    IloNumVarArray x(env, knap.nbItems, 0, 1);
    IloObjective objective(env, IloObjective::Maximize);
    singleLP.add(objective);
    IloExpr str(env);
    for (int j = 0; j < knap.nbItems; ++j)
    str += x[j]*knap.weight[i][j];
    singleLP.add(str <= knap.capacitykk);
    singleLP_Cplex.setParam(IloCplex::SimDisplay, 0);
    singleLP_Cplex.setParam(IloCplex::PreInd, 0);
    While (iter < MaxIter)
    {
    IloObjective oldobjective = singleLP_Cplex.getObjective();
    singleLP.remove(oldobjective);
    IloExpr newobj(env);
    for (int j = 0; j < knap.nbItems; ++j)
    newobj += x[j]*knap.weightiihttp://k*knap.nbItems+j;
    singleLP.add(IloMaximize(env, newobj));
    singleLP_Cplex.setParam(IloCplex::SimDisplay, 0);
    try{
    singleLP_Cplex.solve();
    }
    iter++;
    }

    Which removes the old objective and a new one. I tried to use objective.setExpr(), but it doesn't work.
    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: How to efficiently solve LP iteratively with modifying coefficient?

    Posted 03/12/12 05:37 PM

    Originally posted by: GuangFeng


    Please take a look at the summary of problem modification APIs here

    If you just need to change linear coefficients in the objective, please consider using IloObjective::setLinearCoef() or IloObjective::setLinearCoefs().
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: How to efficiently solve LP iteratively with modifying coefficient?

    Posted 03/13/12 04:18 AM

    Originally posted by: SystemAdmin


    How did you use IloObjective::setExpr()? I just tried
    cplex.getObjective().setExpr(...);
    

    and that worked without a problem for me.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: How to efficiently solve LP iteratively with modifying coefficient?

    Posted 03/13/12 04:14 PM

    Originally posted by: YongjiaSong


    Hi,

    I think my problem is that I initialize the IloObjective with an objective without an expression, I just set the sense. Later in each iteration, when I set the expression, it doesn't work.

    So now I fix that problem, but I find that iterative LP runs very slow, the LP's are quite small, like 50 variables and 5 constraints. How do I warm up the LP for the next iteration by using the information we've got from previous iteration? Does CPLEX do it automatically or I have to store the optimal basis or something like that?

    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: How to efficiently solve LP iteratively with modifying coefficient?

    Posted 04/03/12 07:26 AM

    Originally posted by: SystemAdmin


    > YongjiaSong wrote:
    > Hi,
    >
    > I think my problem is that I initialize the IloObjective with an objective without an expression, I just set the sense. Later in each iteration, when I set the expression, it doesn't work.
    >
    Note that a statement like
    
    IloObjective objective(env, IloObjective::Maximize);
    

    will invoke this constructor:
    
    IloObjective(
    
    const IloEnv env, IloNum constant=0.0, IloObjective::Sense sense=Minimize, 
    
    const 
    
    char * name=0)
    

    i.e., it will create an objective function with constant -1 (the numerical value of IloObjective::Maximize) and sense 'minimize' -- not what you intended to do. In order to create an empty objective function with sense 'maximize' use
    
    IloObjective objective(env, 0, IloObjective::Maximize);
    


    > So now I fix that problem, but I find that iterative LP runs very slow, the LP's are quite small, like 50 variables and 5 constraints. How do I warm up the LP for the next iteration by using the information we've got from previous iteration? Does CPLEX do it automatically or I have to store the optimal basis or something like that?
    >
    CPLEX will automatically try to use all information that is available from the previous solve. What kind of changes do you apply to the model in the iterations?
    #CPLEXOptimizers
    #DecisionOptimization