Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  iterating an objective function in cplex

    Posted 04/13/16 04:13 AM

    Originally posted by: nr-mz


    Dear All,

     

     

    I would like to write you to ask for a help please.

     

    Actually, in my problem I need to solve a set of constraints for different objective functions. Indeed, I have a set of activities i,  and for each of the activities I have a decision variable named  S[ i ]. Also a set of constraints is defined. Now, for each activity i,  I should minimize S[ i ] subject to the constarint. 

     
    For that purpose, I have defined the constaints and added them to my IloCplex object, which is named cplex. Then I have defined the objective function and added it as well to cplex. In order to iterate over  i, I create a For loop and then I do like following:
     
     
    for(int i=0; i<I;i++){
     
     IloLinearNumExpr obj = modeler.linearNumExpr();
     
    modeler.addMinimize(obj); 
     
    obj.addTerm(1, S_StartDateOfActvity[i]);
     
    cplex.solve();
     
     if (modeler.solve()){
            System.out.println("Solved  "+modeler.getObjValue());
          }
          
          else{"opl
            System.out.println(" NOT SOLVED");
          }
    }
     
    But by this way I cannot iterate over i. Cplex solves just for first i  and I it sends the error message saying " opl cannot handle multiple objectives"
     

    I added these commands " modeler.end();" and "modeler.remove( (IloAddable) obj);" but still I cannot overcome the error message.

     

    Actually, I wonder what I should do if I want to iterate the objective function over i and in each iteration solve the objictive function with my constraints. Could you please help me?
     
    I thank you so much for your attention.

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: iterating an objective function in cplex

    Posted 04/13/16 05:34 AM

    Don't use modeler.end(). With 'modeler.remove(obj)' you were almost there, you just removed the wrong thing. Try something like this:

    IloObjective objfun = modeler.addMinimize(obj);
    ...
    modeler.remove(objfun);

    To correctly remove the objective function at the end of an iteration.

    Also, you should to obj.addTerm(...) before you do addMinimize(obj).


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: iterating an objective function in cplex

    Posted 04/13/16 06:47 AM

    Originally posted by: nr-mz


    Thank you so much for your answer

     

    Best Regards


    #CPLEXOptimizers
    #DecisionOptimization