Hi,
I have got a number of interval variables which are linked to another interval via the span constraint.
These interval variables have a type (representing a resource) and I need to make sure that the number of concurrent usages of the resource is respected.
To that end, I'd use a cumul / pulse function. However, I have the additional constraint that the spanning interval represents a container for the resources - if I pulse one of the intervals in the container, I would like to pulse the whole container interval.
To give you a simplified example:
from docplex.cp import model as cp
model = cp.CpoModel()
intervals = [cp.interval_var(length=1) for _ in range(3)]
seq = cp.sequence_var(vars=intervals, types=[0, 1, 0])
spanning_interval = cp.interval_var()
model.add(cp.span(interval=spanning_interval, array=intervals))
Pulsing a single interval is easy and I can use it to block the resource
f = 0
for it, t in zip(seq.get_interval_variables(), seq.get_types()):
if t == 1:
f += cp.pulse(interval=it, height=1)
Now, how can I pulse the spanning interval, if any of the critical resources is present?
I tried to do it via a multiplication of pulse functions, but that does not work.
f = 0
for it, t in zip(seq.get_interval_variables(), seq.get_types()):
if t == 1:
f += cp.pulse(interval=it, height=1) * cp.pulse(interval=spanning_interval, height=1)
Note that in the real model, the intervals in the container are actually optional and linked to another interval via the alternative constraint, so the trivial solution of pulsing the spanned interval only does not work, unfortunately.
Is there some alternative approach? Some kind of "conditional" pulsing, perhaps?
Thanks and best regards
Sebastian
------------------------------
Sebastian Bayer
------------------------------
#DecisionOptimization