21 #include <unordered_map>
25 typedef std::pair<Time, char> Job;
28 template <
class Result>
void print_result(
const Result &result) {
29 std::unordered_map<Machine, Time> machineTime;
30 for (
auto const &machineJobpair : result) {
31 Machine machine = *machineJobpair.first;
32 Job job = *machineJobpair.second;
33 machineTime[machine] += job.first / machine;
34 std::cout <<
"On machine: " << machine <<
" do job: " << job.second
38 for (
auto const &it : machineTime) {
39 max_time = std::max(max_time, it.second);
41 std::cout <<
"Solution: " << max_time << std::endl;
45 auto returnJobLoadFunctor = [](Job job) {
return job.first; };
47 std::vector<Machine> machines = { 1, 2, 3 };
48 std::vector<Job> jobs = { { 2.1,
'a' }, { 3.1,
'b' }, { 4.1,
'c' },
49 { 5.1,
'd' }, { 6.1,
'e' }, { 7.1,
'f' },
52 std::vector<std::pair<decltype(machines) ::iterator,
53 decltype(jobs) ::iterator>> deterministicResult,
56 std::cout <<
"Deterministic schedule:" << std::endl;
58 machines.begin(), machines.end(), jobs.begin(), jobs.end(),
60 returnJobLoadFunctor);
61 print_result(deterministicResult);
63 std::cout <<
"Randomized schedule:" << std::endl;
64 paal::greedy::schedule_randomized(
65 machines.begin(), machines.end(), jobs.begin(), jobs.end(),
67 returnJobLoadFunctor);
68 print_result(randomizedResult);
This file contains set of simple useful functors or functor adapters.
functor returns its argument
double Time
[Scheduling Jobs Example]
void schedule_deterministic(const MachineIterator mfirst, const MachineIterator mlast, const JobIterator jfirst, const JobIterator jlast, OutputIterator result, GetSpeed get_speed, GetLoad get_load)
detail