Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  span sub-sequence

    Posted 03/13/11 03:29 PM

    Originally posted by: davidoff


    Hello

    I'm wondering how to access some subsequence duration . For instance , I have a sequence of 5 intervals A, B,C,D,E , whose first(A) and last(E) are sure but the other ones optional. There is a noOverlap constraint on these intervals with a transition matrix.

    I 'd like to span the interval that goes from the beginning of the second interval (if any) to the end of the pre-last interval. That is if the chosen intervals are in the chronological order A,D,C,E, then I'd like to compute endOf(C)-startOf(D)

    This is ok using an optional interval that spans B,C,D (see first code sample),

    
    using CP; dvar interval a[i in 1..5] optional(i!=1 && i!=5) in 0..5 size 1; dvar interval aspan optional;   
    
    int dist[i in 1..5][j in 1..5] = 1;
    //ftoi(abs(i-j)); tuple triplet 
    { 
    
    int c1; 
    
    int c2; 
    
    int d; 
    }; 
    {triplet
    } Dist = 
    { <i, j, dist[i,j]> | i in 1..5, j in 1..5
    }; dvar sequence s in all(i in 1..5) a[i] types all(i in 1..5) i;   maximize sum(i in 1..5) presenceOf(a[i]); subject to 
    { noOverlap(s,Dist); first(s,a[1]); last(s,a[5]); span(aspan , all(i in 2..4) a[i]);
    //ok for one day sizeOf(aspan) <= 2; 
    }
    


    Now, this model cannot be extended if I have a sequence of ten intervals A1,A2,...,A10 with A1, A5 and A10 are sure, A1 is the first of the sequence, and A10 the last. In this case, if I want to span the intervals between A1 and A5, I can't use a spanning interval that spans all the intervals but A1,A5 and A10. Indeed, if the chosen sequence order is for instance A1,A3,A4,A5,A7,A10 then this spanning interval will span the interval startOf(A3)..endOf(A7) while I would like to span only startOf(A3)..endOf(A4)

    I found a workaround to do so using the transition time (see second sample below), but I'm not completely satisfied with that. I'm wondering if there is a simpler (and accurate) way ?

    
    using CP; range r = 1..10; dvar interval a[i in r] optional(i!=1 && i!=5 && i!=10) in 0..10 size 1; 
    
    int dist[i in r][j in r] = (i!=j); tuple triplet 
    { 
    
    int c1; 
    
    int c2; 
    
    int d; 
    }; 
    {triplet
    } Dist = 
    { <i, j, dist[i,j]> | i in r, j in r
    }; dvar sequence s in all(i in r) a[i] types all(i in r) i; dexpr 
    
    int type1 = typeOfNext(s, a[1] , 1);
    //type of the first task after the first dexpr 
    
    int type2 = typeOfPrev(s, a[5] , 5);
    //type of the last task before the last dexpr 
    
    int beginAfterFirst = endOf(a[1]) + dist[1,type1];
    //actually a lower bound dexpr 
    
    int endsBeforeFirst = startOf(a[5]) - dist[5,type2];
    //actually an upper bound maximize sum(i in r) presenceOf(a[i]); subject to 
    { noOverlap(s,Dist); first(s,a[1]); last(s,a[10]);   endsBeforeFirst - beginAfterFirst <= 2; 
    }
    


    Thanks for any hint

    David
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: span sub-sequence

    Posted 03/13/11 03:57 PM

    Originally posted by: SystemAdmin


    Hello David.

    Your second model is right! To get the real value instead of lower/upper bounds, there are functions endOfPrevious and startOfNext which can help you. The syntax is:
    endOfPrev(sequence, interval, firstval)
    startOfNext(sequence, interval, lastval)
    If the interval is absent then both these functions returns zero. If the interval is first, then endOfPrev returns firstval. If the interval is last, then startOfNext returns lastval. Otherwise it returns end of the previous / start of the next interval in the sequence.

    For more information, have a look on C++ documentation of function IloStartOfNext (OPL function has the same semantics).

    Cheers, Petr
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: span sub-sequence

    Posted 03/13/11 05:38 PM

    Originally posted by: davidoff


    Hello,

    I missed it in the documentation.
    Thank you very much !

    David
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: span sub-sequence

    Posted 03/13/11 05:39 PM

    Originally posted by: davidoff


    Hello,

    I missed it in the documentation.
    Thank you very much !

    David
    #DecisionOptimization
    #OPLusingCPOptimizer