Topic
  • 2 replies
  • Latest Post - ‏2013-02-26T10:43:51Z by ChrisBr
SystemAdmin
SystemAdmin
554 Posts

Pinned topic Very basic question about IloIntervalVars

‏2013-02-25T16:26:38Z |
Hi everyone
I have a very basic quesiton about Interval Vars.
I'm optimizing a time table. The "open hours" are 8AM to 4PM Monday through Thursday and 8AM to 1PM Friday. I want to schedule a task of fixed length of 2 hours with the open hours.
Using this convention: the week starts at Sunday midnight; the open hours are these 5 constant ranges: 8-16,32-40,56-64,80-88,104-109. I want IloIntervalVar myvar with fixed length 2 to get values during the open hours.
What is the best way to define this constraint?
Updated on 2013-02-26T10:43:51Z at 2013-02-26T10:43:51Z by ChrisBr
  • SystemAdmin
    SystemAdmin
    554 Posts

    Re: Very basic question about IloIntervalVars

    ‏2013-02-25T21:33:23Z  
    Hello.

    The best way to model that is constraint forbidExtent in OPL (in C++ it is IloForbidExtent). Using this constraint you can specify intervals of times that the interval variable cannot overlap. For task with fixed size you can achieve the same effect using also forbidStart or forbidEnd constraints, however forbidExtent is simpler.

    You can also have a look on sched_calendar example delivered with CPLEX Optimization Studio.

    Best, Petr
  • ChrisBr
    ChrisBr
    60 Posts

    Re: Very basic question about IloIntervalVars

    ‏2013-02-26T10:43:51Z  
    Hello.

    The best way to model that is constraint forbidExtent in OPL (in C++ it is IloForbidExtent). Using this constraint you can specify intervals of times that the interval variable cannot overlap. For task with fixed size you can achieve the same effect using also forbidStart or forbidEnd constraints, however forbidExtent is simpler.

    You can also have a look on sched_calendar example delivered with CPLEX Optimization Studio.

    Best, Petr
    Hello,

    In addition to what Petr has answered, I would try to give you more details.
    One simple way would be to use a stepwise function and use it in a forbidExtent constraint.

    For example, you can define the stepwise function
    
    IloNumToNumStepFunction openHours(env); openHours.setValue(0, 5*24-1, 0);
    

    then define the open hours
    
    openHours.setValue(  8, 16, 100); openHours.setValue( 32, 40, 100); openHours.setValue( 56, 64, 100); openHours.setValue( 80, 88, 100); openHours.setValue(104,109, 100);
    

    Then you can use the forbidExtent constraint:
    
    IloIntervalVar myvar(env, 2); model.add(IloForbidExtent(env, myvar, openHours));
    

    which means that whenever interval variable myvar is present, it cannot contain a value t when openHours(t)=0.

    I hope that helps,

    Chris.