IBM ILOG Scheduler User's Manual > Integrated Applications > Scheduling with State Resources: the Trolley Problem, with Transition Times > Defining the Problem, Designing a Model > Resources |
Resources |
INDEX
![]() |
Scheduler provides a way to create a state resource with transition times, just as with unary resources (Chapter 20). The following code creates a symmetrical transition time table and associates it with the state resource trolley
. The enforcement level IloBasic
means that the scheduler will spend a basic amount of effort (the default) at enforcing the applicable constraints; IloMediumHigh
specifies that more effort be expended.
/* CREATE THE TROLLEY POSITION RESOURCE */ IloAnyArray arrayOfPossibleAreas(env, 5, (IloAny)AREAA, (IloAny)MACH1, (IloAny)MACH2, (IloAny)MACH3, (IloAny)AREAS); IloAnySet setOfPossibleAreas(env,arrayOfPossibleAreas); trolley = IloStateResource(env,setOfPossibleAreas, "trolley"); /* CREATE THE (SYMMETRIC) TRANSITION TIME TABLE */ IloTransitionParam transitionParam(env, 5, IloTrue); for (i = 0; i < 5; i++) for (j = i; j < 5; j++) transitionParam.setValue(i,j,transitDurations[j + (5 * i)]); /* ASSOCIATE A TRANSITION TIME TO THE RESOURCE */ IloTransitionTime transitionTime(trolley,transitionParam); /* SELECT APPROPRIATE ENFORCEMENT LEVEL */ trolley.setTransitionTimeEnforcement(IloBasic); trolley.setCapacityEnforcement(IloMediumHigh);
The Job
class remains the same as for the first version of the trolley example, except that we must define, for each activity that requires the state resource (load/unload activities), the transition type of the activity. The transition type of an activity is the index of the transition table that will be used to compute the transition time between two activities. In our example, the transition type of a load/unload activity depends on the area where the activity must take place.
The transition time between two activities is introduced to some of the startsAfterEnd
constraints to increase propagation and improve the solution.
Job::Job(IloEnv env, const char* name, IloNum loadDuration, IloUnaryResource machine1, IloNum duration1, IloInt area1, IloUnaryResource machine2, IloNum duration2, IloInt area2) : _name(name), _loadA( env,loadDuration), _unload1( env,loadDuration), _process1(env,duration1), _load1( env,loadDuration), _unload2( env,loadDuration), _process2(env,duration2), _load2( env,loadDuration), _unloadS( env,loadDuration), _area1(area1), _area2(area2), _machine1(machine1), _machine2(machine2) { char buffer[256]; sprintf(buffer, "arrival_load_%s", name); _loadA.setName(buffer); sprintf(buffer, "area%ld_unload_%s", area1, name); _unload1.setName(buffer); sprintf(buffer, "machine%ld_%s", area1, name); _process1.setName(buffer); sprintf(buffer, "area%ld_load_%s", area1, name); _load1.setName(buffer); sprintf(buffer, "area%ld_unload_%s", area2, name); _unload2.setName(buffer); sprintf(buffer, "machine%ld_%s", area2, name); _process2.setName(buffer); sprintf(buffer, "area%ld_load_%s", area2, name); _load2.setName(buffer); sprintf(buffer, "stock_load_%s", name); _unloadS.setName(buffer); _loadA.setTransitionType(AREAA - 1); _unload1.setTransitionType(_area1 - 1); _load1.setTransitionType(_area1 - 1); _unload2.setTransitionType(_area2 - 1); _load2.setTransitionType(_area2 - 1); _unloadS.setTransitionType(AREAS - 1); } Job::~Job() {} void Job::addToModel(IloModel model, IloStateResource trolley, IloNumVar makespan, IloTransitionParam transitionParam) { /* ADD MACHINE REQUIREMENT CONSTRAINTS */ model.add(_process1.requires(_machine1)); model.add(_process2.requires(_machine2)); /* ADD TEMPORAL CONSTRAINTS BETWEEN ACTIVITIES */ IloNum delay = transitionParam.getValue((IloInt)_loadA.getTransitionType(), (IloInt)_unload1.getTransitionType()); model.add(_unload1.startsAfterEnd(_loadA, delay)); model.add(_process1.startsAfterEnd(_unload1)); model.add(_load1.startsAfterEnd(_process1)); delay = transitionParam.getValue((IloInt)_load1.getTransitionType(), (IloInt)_unload2.getTransitionType()); model.add(_unload2.startsAfterEnd(_load1, delay)); model.add(_process2.startsAfterEnd(_unload2)); model.add(_load2.startsAfterEnd(_process2)); delay = transitionParam.getValue((IloInt)_load2.getTransitionType(), (IloInt)_unloadS.getTransitionType()); model.add(_unloadS.startsAfterEnd(_load2, delay)); /* ADD TROLLEY POSITION REQUIREMENTS */ model.add(_loadA.requires(trolley, (IloAny)AREAA)); model.add(_unload1.requires(trolley, (IloAny)_area1)); model.add(_load1.requires(trolley, (IloAny)_area1)); model.add(_unload2.requires(trolley, (IloAny)_area2)); model.add(_load2.requires(trolley, (IloAny)_area2)); model.add(_unloadS.requires(trolley, (IloAny)AREAS)); /* ADD MAKESPAN CONSTRAINT */ model.add(_unloadS.endsBefore(makespan)); }
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |