Decision Optimization

Decision Optimization

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

 View Only
  • 1.  CP-Optimizer: enforcing interval consecutivity modulo intensity function

    Posted Wed October 06, 2021 08:39 AM
    Edited by System Admin Fri January 20, 2023 04:48 PM
    Hello,

    I want to enforce that two intervals t1, t2 are consecutive, i.e. the second one starts when the first one ends. Naively, I would do that with a simple end_at_start constraint:
        m.add(m.end_at_start(t1,t2))​

    However, I also have an intensity function. And for my purposes, intervals are still "consecutive" when they are only separated by a gap in the intensity function (i.e. as long as there is no resource availability between them). E.g. in the example

        m = CpoModel()
        intensity = CpoStepFunction([(0,100),(10,0),(20,100)])    # gap from 10..20
        t1 = m.interval_var(name='t1', size=10, intensity=intensity)
        m.add(m.forbid_start(t1,intensity))
        m.add(m.forbid_end(t1,intensity))
        t2 = m.interval_var(name='t2', size=5, intensity=intensity)
        m.add(m.forbid_start(t2,intensity))
        m.add(m.forbid_end(t2,intensity))
    
        m.add(m.end_at_start(t1,t2))     # no longer does the right thing
    
        m.add(m.minimize(m.end_of(t2)))
    

    I want the solution t1=(0,10), t2=(20,25), but it is ruled out by the combination of forbid_end and end_at_start, and I get instead t1=(1,21), t2=(21,26).
    I have found the following workaround, which relies on inserting a "glue" interval between t1 and t2, which has size 0 but can stretch to arbitrary length:

        glue = m.interval_var(name='glue', size=0, intensity=intensity)
        m.add(m.end_at_start(t1,glue))
        m.add(m.end_at_start(glue,t2))
    

    This works, but I wonder whether there is a more direct or elegant way of achieving this!



    ------------------------------
    Joachim Schimpf
    ------------------------------
    #DecisionOptimization


  • 2.  RE: CP-Optimizer: enforcing interval consecutivity modulo intensity function

    Posted Fri October 08, 2021 10:52 AM
    Hi Joachim,

    I believe that your approach is quite good. There is no direct way to do this in CP Optimizer and introducing an extra interval is the way to go.
    A slightly different approach would be to have a extra interval variable that starts when t1 starts and end when t2 ends and whose size is the sum of sizes of t1 and t2.
    This is equivalent. Using one or the other depends on the shape of the rest of the model.

    Regards

    ------------------------------
    Philippe Refalo
    IBM ILOG CP Optimizer
    ------------------------------



  • 3.  RE: CP-Optimizer: enforcing interval consecutivity modulo intensity function

    Posted Tue October 12, 2021 06:18 PM
    Thanks Philippe,

    I has also thought of your span-based solution, but the glue-interval looked simpler. But as you say, it depends.  Sometimes one may need the spanning interval anyway (in which case it comes at no extra cost).  And it requires less auxiliaries in the generalised case of more than two consecutive intervals.

    ------------------------------
    Joachim Schimpf
    ------------------------------