IBM ILOG Scheduler User's Manual > Getting Started with Scheduler > Using Discrete Resources > Working with Discrete Resources > Complete Program and Output--Example 3 |
Complete Program and Output--Example 3 |
INDEX
![]() |
You can see the entire program gsDisc.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 // /////////////////////////////////////////////////////////////////////////////// IloModel DefineModel(const IloEnv env, IloNumVar& makespan) { IloModel model(env); /* CREATE THE ACTIVITIES. */ IloActivity masonry(env, 7, "masonry "); IloActivity carpentry(env, 3, "carpentry "); IloActivity plumbing(env, 8, "plumbing "); IloActivity ceiling(env, 3, "ceiling "); IloActivity roofing(env, 1, "roofing "); IloActivity painting(env, 2, "painting "); IloActivity windows(env, 1, "windows "); IloActivity facade(env, 2, "facade "); IloActivity garden(env, 1, "garden "); IloActivity moving(env, 1, "moving "); /* ADD 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)); /* CREATE THE RESOURCE. */ IloDiscreteResource workers(env, 2); /* ADD THE RESOURCE CONSTRAINTS. */ model.add(masonry.requires(workers)); model.add(carpentry.requires(workers)); model.add(plumbing.requires(workers)); model.add(ceiling.requires(workers)); model.add(roofing.requires(workers)); model.add(painting.requires(workers)); model.add(windows.requires(workers)); model.add(facade.requires(workers)); model.add(garden.requires(workers)); model.add(moving.requires(workers)); /* SET THE MAKESPAN VARIABLE. */ makespan = IloNumVar(env, 0, IloInfinity, ILOINT); model.add(moving.endsAt(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 = IloSetTimesForward(env, makespan); if (solver.solve(goal)) { PrintSolution(solver,makespan); #if defined(ILO_SDXLOUTPUT) IloSDXLOutput output(env); ofstream outFile("gsDisc.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 19 masonry [0 -- 7 --> 7] carpentry [7 -- 3 --> 10] plumbing [7 -- 8 --> 15] ceiling [11 -- 3 --> 14] roofing [10 -- 1 --> 11] painting [16 -- 2 --> 18] windows [14 -- 1 --> 15] facade [15 -- 2 --> 17] garden [15 -- 1 --> 16] moving [18 -- 1 --> 19] */
The start and end times of all activities are fixed and the total time to complete the project is 19 days. Worker1 works from day 0 to day 17, Worker2 works from day 7 to day 19. Notice that the tasks could be switched between the workers at days 7 and 15.
Figure 4.1 provides a graphic display of the solution to our problem.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |