Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Nested for loop vs Separated multiple for loop

  • 1.  Nested for loop vs Separated multiple for loop

    Posted 03/08/16 12:46 PM

    Originally posted by: Sung_Hwang


    Hello,

     

    I am using CPLEX opl for an optimization.

     

    I would like to ask a question which approach is better for CPLEX performance, 1) Nested for loop or 2) Separated for loop ?

     

    For example, I am going to build the constraint set as below.

    1) Nested for loop

    forall (d in period, w in workers, t in training: d== tr.dayNumber){

       forall (d2 in period : d <= d2 <= d+8 && schedule[p][d2]=="V")

               X_[p][d] ==0;

     

      

     forall (d2 in period : d <= d2 <= d+8 && schedule[p][d2]=="L")

               X_[p][d] ==0;

    }

     

    or 

    2)  Separated for loop

    forall (d in period, w in workers, t in training: d== tr.dayNumber){

       forall (d2 in period : d <= d2 <= d+8 && schedule[p][d2]=="V")

               X_[p][d] ==0;

    }

     

    forall (d in period, w in workers, t in training: d== tr.dayNumber){ 

         forall (d2 in period : d <= d2 <= d+8 && schedule[p][d2]=="L")

                X_[p][d] ==0;

    }

     

    Thank you in advance for all your comments

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Nested for loop vs Separated multiple for loop

    Posted 03/11/16 05:00 AM

    Hi,

    I would go for nested.

    Because it saves some computation at extraction time.

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer