Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Position of an interval in a seq

  • 1.  Position of an interval in a seq

    Posted Thu May 02, 2019 06:44 AM

    Originally posted by: WeeLoon


    Supposed I have interval a -> b -> c in a sequence.

     

    I would like to have a value where a = 1, b = 2, c = 3 and use them in objective function.

     

    I try to use cumulFunction, but cumulFunctionValue can only be extracted after the solution exists.

     

    Which function can I use to achieve this?

     

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: Position of an interval in a seq

    Posted Fri May 03, 2019 10:00 AM

    Originally posted by: Petr Vilím


    Hello,

    there is no simple way to access position of an interval variable in a sequence. The main reason is that it does't propagate well and we don't even use it internally.

    I would step back first. What kind of objective function do you have in mind? Maybe we can find a way to model it without the actual positions.

    Best regards, Petr


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: Position of an interval in a seq

    Posted Fri May 03, 2019 08:59 PM

    Originally posted by: WeeLoon


    Hi Petr,

     

    I manage to find a workaround by modifying the objective. Thanks for your help.

     

    Best regards, WeeLoon


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: Position of an interval in a seq

    Posted Thu July 18, 2019 11:02 AM

    Great you found a way.

    Otherwise other users could use that small example:

    using CP;

    int n=5;

    range r=1..n;
    range r0=0..n;

    dvar interval itvs[i in r] size i;

    dvar sequence  seq in all(i in r)itvs[i] types all(i in r)i;

    dvar int nextType[i in r];
    dvar int rank[i in r0];
    dvar int rankbis[i in r] in r;
    dvar int typeInSequence[r] in r; // compute the type of ith interval in the sequence

    subject to
    {

    // input

    noOverlap(seq);
    startBeforeStart(itvs[1],itvs[3]);
    startBeforeStart(itvs[3],itvs[5]);
    startBeforeStart(itvs[5],itvs[2]);
    startBeforeStart(itvs[2],itvs[4]);

    // and then let s compute typeInSequence

    forall(i in 1..n) nextType[i]==(typeOfNext(seq,itvs[i],0));

    rank[1]==1;
    forall(i in 1..n)  (nextType[i]!=0) => (rank[i]+1==rank[nextType[i]]);

    forall(i in r) rankbis[i]==rank[i];

    inverse(rankbis,typeInSequence);

     

    }

    execute
    {
    writeln("ranks = ",rankbis);
    writeln("typeInSequence = ",typeInSequence);

    }

    which gives

     

    ranks =  [1 4 2 5 3]
    typeInSequence =  [1 3 5 2 4]

    regards

     

    Alex Fleischer

    PS:

    Many how to with OPL at https://www.linkedin.com/pulse/how-opl-alex-fleischer/

    Many examples from a very good book : https://www.linkedin.com/pulse/model-building-oplcplex-alex-fleischer/

    Making optimization simple : https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/


    #DecisionOptimization
    #OPLusingCPOptimizer