Decision Optimization

Decision Optimization

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


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

Cumulative Float Array using OPL

  • 1.  Cumulative Float Array using OPL

    Posted 02/02/17 04:27 AM

    Originally posted by: Twister


    Hi,

     

    I am new to using OPL so I am having trouble formulating a few things. I have two variable called x and y. x is an integer array in the range of 1..20 while y is a float. I want y to be the cumulative sum of x for each corresponding index. So for example I want y[1]=0, y[2]=0.5*(x[1]), y[3]=0.5*(x[1]+x[2]), y[4]=0.5*(x[1]+x[2]+x[3]) and so on. Since y is a float I cannot express this as a constraint. It has to be done as a dexpr but I have no idea how to do this using dexpr since I think you cannot use for loop with dexpr. Any help would be very much appreciated.

     

    Thanks in advance.


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: Cumulative Float Array using OPL

    Posted 02/02/17 05:53 AM

    Originally posted by: ChrisBr


    Hello,

    You might try this:

    dexpr float y[i in 1..20] = 0.5*sum(j in 1..(i-1)) x[j];

    I hope this helps,

    Chris.

     


    #DecisionOptimization
    #OPLusingCPOptimizer