IBM ILOG Scheduler User's Manual > Getting Started with Scheduler > Adding Breaks > Complete Program and Output--Example 6 |
Complete Program and Output--Example 6 |
INDEX
![]() |
You can see the entire program gsBreak.cpp
here or view it online in the standard distribution.
#include <ilsched/iloscheduler.h> ILOSTLBEGIN #if defined(ILO_SDXLOUTPUT) #include "sdxloutput.h" #endif /////////////////////////////////////////////////////////////////////////////// // // PROBLEM DEFINITION // /////////////////////////////////////////////////////////////////////////////// /* THREE DESIGNS OF HOUSES EACH HAVING DIFFERENT TASK DURATIONS */ IloNum durationsDesign1 [] = { 7, 3, 8, 3, 1, 2, 1, 2, 1, 1}; IloNum durationsDesign2 [] = {12, 5, 10, 5, 2, 5, 2, 3, 2, 1}; IloNum durationsDesign3 [] = {15, 3, 10, 6, 2, 3, 2, 3, 2, 1}; void MakeHouse(IloModel model, const IloNum* dur, const IloNum startMin, const IloNum endMax, const IloUnaryResourceArray workers, const IloNumVar makespan) { IloEnv env = model.getEnv(); /* CREATE THE ACTIVITIES. */ IloActivity masonry(env, dur[0], "masonry "); masonry.setBreakable(); IloActivity carpentry(env, dur[1], "carpentry "); carpentry.setBreakable(); IloActivity plumbing(env, dur[2], "plumbing "); plumbing.setBreakable(); IloActivity ceiling(env, dur[3], "ceiling "); ceiling.setBreakable(); IloActivity roofing(env, dur[4], "roofing "); IloActivity painting(env, dur[5], "painting "); IloActivity windows(env, dur[6], "windows "); windows.setBreakable(); IloActivity facade(env, dur[7], "facade "); facade.setBreakable(); IloActivity garden(env, dur[8], "garden "); garden.setBreakable(); IloActivity moving(env, dur[9], "moving "); /* SET EARLIEST START */ model.add(masonry.startsAfter(startMin)); model.add(moving.endsBefore(endMax)); /* POST THE TEMPORAL CONSTRAINTS. */ model.add(carpentry.startsAfterEnd(masonry)); model.add(plumbing.startsAfterEnd(masonry)); model.add(ceiling.startsAfterEnd(masonry)); model.add(roofing.startsAfterEnd(carpentry)); model.add(painting.startsAfterEnd(ceiling)); model.add(windows.startsAfterEnd(roofing)); model.add(facade.startsAfterEnd(roofing)); model.add(facade.startsAfterEnd(plumbing)); model.add(garden.startsAfterEnd(roofing)); model.add(garden.startsAfterEnd(plumbing)); model.add(moving.startsAfterEnd(windows)); model.add(moving.startsAfterEnd(facade)); model.add(moving.startsAfterEnd(garden)); model.add(moving.startsAfterEnd(painting)); /* SET MAKESPAN */ model.add(moving.endsBefore(makespan)); /* POST THE RESOURCE CONSTRAINTS. */ model.add(carpentry.requires(workers[0])); model.add(ceiling.requires(workers[0])); model.add(roofing.requires(workers[0])); model.add(windows.requires(workers[0])); model.add(facade.requires(workers[0])); model.add(masonry.requires(workers[1])); model.add(plumbing.requires(workers[2])); model.add(garden.requires(workers[3])); model.add(painting.requires(workers[3])); model.add(moving.requires(workers[3])); } IloModel DefineModel(const IloEnv env, IloNumVar& makespan) { IloModel model(env); /* CREATE THE MAKESPAN VARIABLE. */ IloNum horizon = 150; makespan = IloNumVar(env, 0, horizon, IloNumVar::Int); /* SET ENFORCEMENT LEVEL */ IloSchedulerEnv schedEnv(env); IloResourceParam resParam = schedEnv.getResourceParam(); resParam.setCapacityEnforcement(IloMediumHigh); /* CREATE A SHARED BREAK LIST FOR ALL WORKERS */ IloIntervalList breakParam = schedEnv.getBreakListParam(); breakParam.addPeriodicInterval(5, 2, 7, horizon); /* CREATE THE RESOURCES. */ IloInt nbOfWorkers = 4; IloUnaryResourceArray workers(env,nbOfWorkers); for (IloInt k = 0; k < nbOfWorkers; k++) workers[k] = IloUnaryResource(env); /* CREATE THE ACTIVITIES AND CONSTRAINTS FOR THE HOUSES. */ MakeHouse(model, durationsDesign1, 0, horizon, workers, makespan); MakeHouse(model, durationsDesign1, 0, horizon, workers, makespan); MakeHouse(model, durationsDesign2, 7, 79, workers, makespan); MakeHouse(model, durationsDesign2, 7, 79, workers, makespan); MakeHouse(model, durationsDesign3, 0, horizon, workers, makespan); /* SET THE OBJECTIVE */ model.add(IloMinimize(env, makespan)); return model; } /////////////////////////////////////////////////////////////////////////////// // // PRINTING OF SOLUTIONS // /////////////////////////////////////////////////////////////////////////////// void PrintSolution(const IloSolver solver, const IloNumVar makespan) { IlcScheduler scheduler(solver); IloEnv env = solver.getEnv(); env.out() << "Solution with makespan " << solver.getIntVar(makespan).getMin() << endl; for(IloIterator<IloActivity> act(env); act.ok(); ++act) env.out() << scheduler.getActivity(*act) << endl; solver.printInformation(); } /////////////////////////////////////////////////////////////////////////////// // // MAIN FUNCTION // /////////////////////////////////////////////////////////////////////////////// int main() { try { // Model IloEnv env; IloNumVar makespan; IloModel model = DefineModel(env, makespan); // Algorithm IloSolver solver(model); IloGoal goal = IloRankForward(env, makespan); if (solver.solve(goal)) { PrintSolution(solver,makespan); #if defined(ILO_SDXLOUTPUT) IloSDXLOutput output(env); ofstream outFile("gsBreak.xml"); output.write(IlcScheduler(solver), outFile, solver.getIntVar(makespan)); outFile.close(); #endif } else solver.out() << "No solution !" << endl; env.end(); } catch (IloException& exc) { cout << exc << endl; } return 0; } /////////////////////////////////////////////////////////////////////////////// // // RESULTS // /////////////////////////////////////////////////////////////////////////////// /* Solution with makespan 113 masonry [64..78 -- (7) 7..11 --> 73..87] carpentry [87 -- (3) 5 --> 92] plumbing [78..95 -- (8) 8..12 --> 88..107] ceiling [94 -- (3) 5 --> 99] roofing [102 -- 1 --> 103] painting [99..106 -- 2 --> 101..108] windows [109 -- (1) 1 --> 110] facade [107 -- (2) 2 --> 109] garden [105..108 -- (1) 1 --> 106..109] moving [112 -- 1 --> 113] masonry [0..1 -- (7) 9 --> 9..10] carpentry [9..14 -- (3) 3..5 --> 12..17] plumbing [9..14 -- (8) 8..12 --> 19..24] ceiling [14..17 -- (3) 3..5 --> 17..22] roofing [17..22 -- 1 --> 18..23] painting [17..50 -- 2 --> 19..52] windows [18..23 -- (1) 1 --> 19..24] facade [21..24 -- (2) 2 --> 23..26] garden [21..52 -- (1) 1 --> 22..53] moving [23..53 -- 1 --> 24..54] masonry [25..28 -- (12) 16..18 --> 43..44] carpentry [44 -- (5) 7 --> 51] plumbing [43..51 -- (10) 10..14 --> 57..65] ceiling [51 -- (5) 7 --> 58] roofing [58 -- 2 --> 60] painting [70 -- 5 --> 75] windows [72 -- (2) 2 --> 74] facade [65 -- (3) 3 --> 68] garden [60..66 -- (2) 2..4 --> 64..68] moving [78 -- 1 --> 79] masonry [9..10 -- (12) 16 --> 25..26] carpentry [32..35 -- (5) 5..7 --> 39..40] plumbing [25..37 -- (10) 10..14 --> 39..51] ceiling [25..28 -- (5) 5..7 --> 32..33] roofing [42 -- 2 --> 44] painting [35..56 -- 5 --> 40..61] windows [70 -- (2) 2 --> 72] facade [60 -- (3) 5 --> 65] garden [44..64 -- (2) 2..4 --> 46..66] moving [77 -- 1 --> 78] masonry [43..53 -- (15) 15..21 --> 64..74] carpentry [84 -- (3) 3 --> 87] plumbing [64..81 -- (10) 10..14 --> 78..95] ceiling [74 -- (6) 8 --> 82] roofing [92 -- 2 --> 94] painting [84..99 -- 3 --> 87..102] windows [105 -- (2) 2 --> 107] facade [99 -- (3) 3 --> 102] garden [94..102 -- (2) 2..4 --> 96..106] moving [107..109 -- 1 --> 108..110] */
The start and end times of some activities are fixed, while others have variable start and end dates. The total time to complete the project is 113 days.
The results are interpreted as follows:
moving [107..109 -- 1 --> 108..110]
The moving activity has an earliest start time of 107, a latest start time of 109, a duration of 1, an earliest completion time of 108, and a latest completion time of 110.
garden [94..102 -- (2) 2..4 --> 96..106]
The garden activity has an earliest start time of 94, a latest start time of 102, a processing time of 2, a minimal duration of 2, a maximal duration of 4, an earliest completion time of 96, and a latest completion time of 106.
facade [60 -- (3) 5 --> 65]
The facade activity has a start time of 60, a processing time of 3, a duration of 5, and a completion time of 65.
Figure 6.1 provides a graphic display of the solution to our problem. Activities with variable start and end times are positioned at their earliest start times.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |