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