Decision Optimization

Decision Optimization

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


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

How to abort for-loop with if condition?

  • 1.  How to abort for-loop with if condition?

    Posted 07/01/13 09:11 AM

    Originally posted by: Dortmunder


    Hi everyone,

    I have a beginners question about for loops in CPLEX.

    For my program I need to check at which time step my binary matrix has the last "1" for each unit and use it on one of my constraints.

    If I write my code in CPLEX according to the help documentation it should look like this (NbTimeSteps is the TimeSteps arrays range):

     

    forall (u in Units)

     for (t in TimeSteps == NbTimeSteps; t>1; t--)

      { if (BinaryMatrix[u][t] == 1)

         ( Matrix[u][t] == Array[u] break ) }

     

    Apparently the syntax is very different and I figured that at least the for-loop should look more like this:

         for (t in TimeSteps == NbTimeSteps, t>=2, t-1)


    Still, the if-condition cannot be operated in the for-loop. Is it a generally disallowed operation or is my syntax simply wrong?

    Would the break operator work if my if-condition worked?

    Grateful for any help I can get! Thanks in advance!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to abort for-loop with if condition?

    Posted 07/02/13 08:57 AM

    Hi

     

    first you can write outside of the subject to block

     

    int lastelement[i in 1..scale]=max(j in 1..scale : b[j]==1) j;

     

    and then in the constraint block something like

     

    forall(i in 1..scale) x[i][lastelement[i]]==2;

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: How to abort for-loop with if condition?

    Posted 07/02/13 05:13 PM

    Originally posted by: Dortmunder


    Hi Alex,

    thanks a lot for your help, it works!

    Btw you probably meant b[i][j] == 1, right? ;-)

    Thanks again

    Tarik

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: How to abort for-loop with if condition?

    Posted 07/03/13 01:52 AM

    Hi

     

    indeed, I meant b[i][j] == 1

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer