0

I am new to Cplex. I need to compute the overlap between several intervals at same time. For that, i compute the overlap_length between two intervals at a time, and i save the max and min of the start/end points. For example, let's consider three intervals vars I1, I2, I3. The objective is to maximize the overlap between the three. Then, the code is as follow:

over1=mdl.overlap_length(I1,I2)

start1=max(mdl.start_of(I1),mdl.start_of(I2))

end1=min(mdl.end_of(I1),mdl.end_of(I2))

over1=mdl.overlap_length(I3,(start1,end1)

And then i maximize the over1. With that, i get the following error:

AssertionError: To express a fixed interval, 'interval2' should be a tuple of two integers

In fact, the start1 and end1 are CP integer expressions. I didn't find a way to convert or to get the value! Is there anyone who have an idea how to do that?

Thanks,

Community
  • 1
  • 1

1 Answers1

0

In your last line start1 and end1 needs to be bounds, they need to be values not decision variables. So as a workaround, you could rely on an artificial interval.

since OPL is very close to docplex but IMHO opinion easier let me show you the way in OPL.

using CP;

dvar interval I1 in 0..20;
dvar interval I2 in 0..20;
dvar interval I3 in 0..20;

dvar int over1;
dvar int start1;
dvar int end1;

dvar interval artificialInterval;

maximize over1;

subject to
{

    over1==overlapLength(I1,I2);

    start1==maxl(startOf(I1),startOf(I2));

    end1==minl(endOf(I1),endOf(I2));

    startOf(artificialInterval)==start1;
    endOf(artificialInterval)==end1;

    over1==overlapLength(I3,artificialInterval);
}   

works fine

Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Thank you, I have tried to implement your proposition but in docplex i canno't assign the values startOf(artificialInterval)==start1; so ihave tried to add it as aconstraint and it doesn't work... – user12484944 Feb 04 '20 at 21:44
  • see https://stackoverflow.com/questions/60071915/how-to-initiate-the-interval-variable-bounds-in-docplex-python/60074141#60074141 – Alex Fleischer Feb 05 '20 at 10:51