Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Problem with model.remove(objective)

    Posted 11/09/11 11:46 AM

    Originally posted by: SystemAdmin


    Hi everybody,
    I have an integer progamming model and I want to solve it by a local approach. Since I need to modify the model at each iteration, I need to pass a new model to Cplex. The modifications concern only the objective function, i.e., (at each iteration of the algorithm) I just need to replace the objective function with a new one. The new objective function is constructed by using the solution of the current (sub)problem. I tried the model.remove(objective); but I got some errors! I modified the program until I got a program without error, but I discovered that no changes are present in the new objective function! And the algorithm solves the same problem at each iteration! I don't understand why no change is present in the new objective function. Below you find the Cplex codes that I used in my program.

    Any suggestion is highly appreciated.

    Thank you in advance.

    
    
    
    void main() 
    { 
    // Here I define the variables and the vectors, etc. IloEnv env; IloModel model(env); 
    // Here I define the IloNumVarArray's  
    ////////////////////////////////////////// 
    // Here I read the data 
    // Here I define the constraints of the model IloExpr objectif(env); 
    // Here I give the expression of the objective function (a "linear" function) 
    //////////////////////////////////////////// model.add(IloMinimize(env,objectif)); objectif.end();
    // when I add this part (I mean "objectif.end();"), Cplex produces some errors! but when I delete this part there is no error! 
    //////////////////////////////////////////// 
    // Solving the model by Cplex: IloCplex cplex(model); 
    
    int res = cplex.solve(); 
    
    if (res)
    { NewOptimalValue = cplex.getObjValue(); 
    } 
    
    else
    { cout<<
    "The model is infeasible "<<endl; 
    } 
    //////////////////////////////////////////// 
    // :::::::::::::::::::::::::: Starting point of the algorithm :::::::::::::::::::::::::: 
    
    do
    { 
    ////////////////////////////////////////// 
    // I keep a backup of the current solution in order to use it in the futur 
    // I need to calculate some auxiliary vectors that are used algorithm, the backup version of the solutions is used for this aim 
    // Now, I need to remove the current objective function in order to construct a new one (a "quadratic" function) 
    // This operation is done at each iteration of the algorithm model.remove(objectif); 
    // Now, I want to define the new objective function IloExpr objectif(env); 
    // Here I give the expresstion of the new objective function! model.add(IloMinimize(env,objectif)); objectif.end();
    // This expression produces no error! 
    //////////////////////////////////////////// 
    // Solving the model by Cplex. IloCplex cplex(model); 
    //////////////////////////////////////////// 
    
    int res = cplex.solve(); 
    
    if (res)
    { NewOptimalValue = cplex.getObjValue(); NumberOfIterations++; 
    } 
    
    else
    { cout<<
    "There was a problem in solving the subproblem :( "<<endl; NumberOfIterations = MaxIterations;
    // In order to terminate the program 
    } 
    }
    
    while(NumberOfIterations < MaxIterations); 
    // :::::::::::::::::::::::::: End point of the algorithm :::::::::::::::::::::::::: env.end(); 
    }
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Problem with model.remove(objective)

    Posted 11/09/11 08:20 PM

    Originally posted by: SystemAdmin


    The model.remove() method is suitable for constraints but not the objective. You should instead use the IloObjective.setExpr() or the model.setLinearCoef(s)() method to modify the objective function at every iteration. If you were to use the IloObjective.setExpr() method, the pseudo code could look like the following:

    
    
    
    void main() 
    { 
    // Here I define the variables and the vectors, etc. IloEnv env; IloModel model(env); 
    // Here I define the IloNumVarArray's  
    ////////////////////////////////////////// 
    // Here I read the data 
    // Here I define the constraints of the model IloExpr objectif(env); 
    // Here I give the expression of the objective function (a "linear" function) 
    //////////////////////////////////////////// 
    //model.add(IloMinimize(env,objectif)); IloObjective obj = IloMinimize(env,objectif,
    "Objective_Function"); model.add(obj);   
    //objectif.end();// when I add this part (I mean "objectif.end();"), Cplex produces some errors! but when I delete this part there is no error! 
    //////////////////////////////////////////// 
    // Solving the model by Cplex: IloCplex cplex(model); 
    
    int res = cplex.solve(); 
    
    if (res)
    { NewOptimalValue = cplex.getObjValue(); 
    } 
    
    else
    { cout<<
    "The model is infeasible "<<endl; 
    } 
    //////////////////////////////////////////// 
    // :::::::::::::::::::::::::: Starting point of the algorithm :::::::::::::::::::::::::: 
    
    do
    { 
    ////////////////////////////////////////// 
    // I keep a backup of the current solution in order to use it in the futur 
    // I need to calculate some auxiliary vectors that are used algorithm, the backup version of the solutions is used for this aim 
    // Now, I need to remove the current objective function in order to construct a new one (a "quadratic" function) 
    // This operation is done at each iteration of the algorithm 
    //model.remove(objectif); 
    // Now, I want to define the new objective function IloExpr new_objectif(env); 
    // Here I give the expresstion of the new objective function! 
    //model.add(IloMinimize(env,objectif)); 
    //objectif.end();// This expression produces no error! obj.setExpr(new_objectif); 
    //////////////////////////////////////////// 
    // Solving the model by Cplex. IloCplex cplex(model); 
    //////////////////////////////////////////// 
    
    int res = cplex.solve(); 
    
    if (res)
    { NewOptimalValue = cplex.getObjValue(); NumberOfIterations++; 
    } 
    
    else
    { cout<<
    "There was a problem in solving the subproblem :( "<<endl; NumberOfIterations = MaxIterations;
    // In order to terminate the program 
    } 
    }
    
    while(NumberOfIterations < MaxIterations); 
    // :::::::::::::::::::::::::: End point of the algorithm :::::::::::::::::::::::::: env.end(); 
    }
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Problem with model.remove(objective)

    Posted 11/20/11 08:49 AM

    Originally posted by: SystemAdmin


    Thank you AbhishekRaman! I have no more such errors!
    #CPLEXOptimizers
    #DecisionOptimization