All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
scheduling_jobs_on_identical_parallel_machines_example.cpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Smulewicz
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
16 
19 
20 #include <iostream>
21 #include <utility>
22 
26 int main() {
27  typedef double Time;
28  typedef std::pair<Time, char> Job;
29 
30  auto returnJobTimeFunctor = [](Job job) { return job.first; };
31 
32  // sample data
33  int numberOfMachines = 3;
34  std::vector<Job> jobs = { { 2.1, 'a' },
35  { 3.1, 'b' },
36  { 4.1, 'c' },
37  { 5.1, 'd' },
38  { 6.1, 'e' },
39  { 7.1, 'f' },
40  { 8.1, 'g' } };
41  std::vector<std::pair<int, decltype(jobs)::iterator>> result;
42 
44  numberOfMachines, jobs.begin(), jobs.end(), back_inserter(result),
45  returnJobTimeFunctor);
46 
47  std::vector<Time> sumOfMachine;
48  sumOfMachine.resize(numberOfMachines);
49  for (auto machineJobPair : result) {
50  auto machine = machineJobPair.first;
51  auto job = machineJobPair.second;
52  sumOfMachine[machine] += job->first;
53  std::cout << "On machine: " << machine << " do job: " << job->second
54  << std::endl;
55  }
56  Time maximumLoad =
57  *std::max_element(sumOfMachine.begin(), sumOfMachine.end());
58 
59  // print result
60  std::cout << "Solution:" << maximumLoad << std::endl;
61  return 0;
62 }
63 
int main()
[Scheduling Jobs On Identical Parallel Machines Example]
void scheduling_jobs_on_identical_parallel_machines(int n_machines, InputIterator first, InputIterator last, OutputIterator result, GetTime get_time)
detail
double Time
[Scheduling Jobs Example]