IBMDecisionOptimization / docplex-examples

These samples demonstrate how to use the DOcplex library to model and solve optimization problems.
https://ibmdecisionoptimization.github.io/
Apache License 2.0
392 stars 228 forks source link

Opposite of no_overlap #66

Open prakashgawas opened 2 years ago

prakashgawas commented 2 years ago

Hi, I am using python for CP solving. I would like to know if there is constraint that does the opposite of no_overlap. This will be like overlap(interval, arr, n) interval - single interval variable arr - array of interval variables n - positive integer less than length of arr

this will mean that atleast n interval variables from arr overlap in the interval of interval

This is for a situation in job scheduling when a job is not possible to be scheduled on a machine because there are already n higher priority jobs.

p-shaw commented 2 years ago

Hello, you can use the overlapLength expression to know how much overlap there are between two interval variables. This way you can count the number of non-zero overlaps between 'interval' and all the elements of 'arr'. Something like:

mdl.sum([mdl.overlap_length(interval, a) > 0 for a in arr]) >= n
prakashgawas commented 2 years ago

Hello, Thanks for the reply, but actually what I need is a bit more complex. I need that whenever interval starts then n intervals from a set have already started or start parallelly with interval. that is something above the overlap constraint