IBM ILOG Scheduler User's Manual > Getting Started with Scheduler > Using the Building Blocks > Satisfying Temporal Constraints > Complete Program and Output--Example 1 |
Complete Program and Output--Example 1 |
INDEX
![]() |
You can see the entire program gsBasic.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)); /* SET THE MAKESPAN VARIABLE. */ makespan = IloNumVar(env, 0, IloInfinity, ILOINT); model.add(moving.endsAt(makespan)); return model; } /////////////////////////////////////////////////////////////////////////////// // // PRINTING OF SOLUTIONS // /////////////////////////////////////////////////////////////////////////////// void PrintSolution(const IloSolver solver) { IlcScheduler scheduler(solver); IloEnv env = solver.getEnv(); 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 = IloInstantiate(env, makespan); if (solver.solve(goal)) { PrintSolution(solver); #if defined(ILO_SDXLOUTPUT) IloSDXLOutput output(env); ofstream outFile("gsBasic.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 // /////////////////////////////////////////////////////////////////////////////// /* masonry [0 -- 7 --> 7] carpentry [7..11 -- 3 --> 10..14] plumbing [7 -- 8 --> 15] ceiling [7..12 -- 3 --> 10..15] roofing [10..14 -- 1 --> 11..15] painting [10..15 -- 2 --> 12..17] windows [11..16 -- 1 --> 12..17] facade [15 -- 2 --> 17] garden [15..16 -- 1 --> 16..17] moving [17 -- 1 --> 18] */
In the standard output from a solution, the printed representation of each activity (instance of the class IloActivity
) is its name (or the string "IloActivity
" if the activity is not named) followed by information about its place in the schedule. This information is enclosed in square brackets. It consists of three items: start time, duration, and end time of the activity. Each item can be represented either as a single value or as an interval. If the item is represented as an interval, it appears as two integers separated by two dots.
For example:
masonry [0 -- 7 --> 7]
means the activity named masonry
starts at 0, lasts 7 units of time, and ends at 7.
carpentry [7..11 -- 3 --> 10..14]
means that the activity named carpentry
starts sometime between 7 and 11, lasts 3 units of time, and ends sometime between 10 and 14.
The start and end times of six activities (garden
, windows
, painting
, roofing
, ceiling
, and carpentry
) are not definitely set. In fact, any of these activities can execute from its latest start time to its latest end time (for example, from day 11 to day 14 in the case of carpentry
) without compromising the makespan of the overall project.
Figure 3.2 provides a graphic display of the solution to the problem.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |