Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Accessing sequence intervals (post-optim)

    Posted 03/28/11 12:14 PM

    Originally posted by: davidoff


    Is there a way to access the elements of a sequence (that is the array "pi" according to the documentation) ? Basically, I'd like to iterate on the chosen interval of the sequence in post optimization : I can do it through the array of intervals on which the sequence is built, but I was thinking of something like : sequence.item(0), item(1), item(sequence.length()-1) . Then, if the sequence is associated with a non-overlap constraint, this would simply gives the chosen intervals in their chronological order

    David
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: Accessing sequence intervals (post-optim)

    Posted 03/29/11 03:31 AM

    Originally posted by: SystemAdmin


    Hello,
    You can use the first/next functions on the sequence as follows.

    
    using CP; 
    
    int n=10;   dvar interval x[i in 1..n] size i; dvar sequence s in x;   constraints 
    { noOverlap(s); 
    }   execute 
    { 
    
    for (var a = s.first(); a != 
    
    null; a = s.next(a)) writeln(a); 
    }
    


    Using this type of iteration, you can access the interval variables themselves.
    But if you need to access some data associated with the interval variables, you may have to sort the sequence yourself. In the piece of code below, I assume you want to get an information info[i] associated with interval x[i] in chronological order:

    
    using CP; 
    
    int n=10;   dvar interval x    [i in 1..n] size i; 
    
    int           info [i in 1..n] = (i % 5);   dvar sequence s in x;   constraints 
    { noOverlap(s); 
    }   
    // Sorted interval start times tuple Start 
    { 
    
    int s; 
    
    int i; 
    } sorted 
    {Start
    } sol = 
    { <startOf(x[i]),i> | i in 1..n 
    };   execute 
    { 
    
    for (var pos = 0; pos <n; pos++) 
    { var i = Opl.item(sol,pos).i; writeln(
    "At position ", pos, 
    " info=", info[i]); 
    } 
    }
    


    Philippe
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: Accessing sequence intervals (post-optim)

    Posted 03/29/11 08:47 AM

    Originally posted by: davidoff


    Thanks Philippe. Is that documented ?

    Regards

    David
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: Accessing sequence intervals (post-optim)

    Posted 03/29/11 09:10 AM

    Originally posted by: SystemAdmin


    Yes, it is documented in:
    IDE and OPL > Optimization Programming Language (OPL) > IBM ILOG Script Reference Manual > OPL Classes
    Class IloIntervalSequenceVar

    Philippe
    #DecisionOptimization
    #OPLusingCPOptimizer