Decision Optimization

Decision Optimization

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


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

Iterating over a set of elements

  • 1.  Iterating over a set of elements

    Posted 07/16/18 01:23 PM

    Originally posted by: malithwd


    Hi folks,

    I am trying to model the following constrain in OPL. Here π G is string set.

            Np-1
    r >= ∑ y(k,k+1)     ∀p∈ π G
            k=1       

     

    Here is how I tried it,

                        

    tuple Path {{string} nodes;}
    {Path} paths = ...;

    subject to{

     forall(p in paths)
            sum (node in p.nodes) Y[node][next(p.nodes,node)]  <= r;

    }

     

    since i want to iterate till N-1 th element of set and apply function Y for k+1 th element i used "next" function. But here it iterates till N th element. How could it be done using OPL notation to iterate till N-1 th element and get the k+1 th element in function?

     

    Thank you,

    Malith

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Iterating over a set of elements

    Posted 07/17/18 04:19 AM

    Originally posted by: OndrejKral


    Hi, how about

     forall(p in paths)
            sum (node in p.nodes diff last(p.nodes)) Y[node][next(p.nodes,node)]  <= r;

    }

    Ondrej


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Iterating over a set of elements

    Posted 07/17/18 08:59 AM

    Originally posted by: malithwd


    Hi Ondrej,

     

    Nice trick, Thanks. Just needed a little correction as follows (added curly braces to make it a set),

     

     forall(p in paths)
            sum (node in p.nodes diff {last(p.nodes)}) Y[node][next(p.nodes,node)]  <= r;

    }

     

    Cheers,

    Malith


    #DecisionOptimization
    #OPLusingCPLEXOptimizer