All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
generalised_assignment_example.cpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 // 2014 Piotr Godlewski
4 //
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //=======================================================================
19 
20 #include <iostream>
21 #include <vector>
22 
23 int main() {
24  // sample problem
25  std::vector<int> machines = {0,1};
26  std::vector<int> jobs = {0,1};
27 
28  std::vector<std::vector<int>> cost(2, std::vector<int>(2));
29  cost[0][0] = 2;
30  cost[0][1] = 3;
31  cost[1][0] = 1;
32  cost[1][1] = 3;
33  auto costf = [&](int i, int j) { return cost[i][j]; };
34 
35  std::vector<std::vector<int>> time(2, std::vector<int>(2));
36  time[0][0] = 2;
37  time[0][1] = 2;
38  time[1][0] = 1;
39  time[1][1] = 1;
40  auto timef = [&](int i, int j) { return time[i][j]; };
41 
42  std::vector<int> T = { 2, 2 };
43  auto Tf = [&](int i) { return T[i]; };
44 
45  std::vector<std::pair<int, int>> jobs_to_machines;
46 
47  // solve it
49  machines.begin(), machines.end(), jobs.begin(), jobs.end(), costf,
50  timef, Tf, std::back_inserter(jobs_to_machines));
51 
52  // print result
53  if (result.first == paal::lp::OPTIMAL) {
54  for (auto jm : jobs_to_machines) {
55  std::cout << "Job " << jm.first << " assigned to Machine "
56  << jm.second << std::endl;
57  }
58  std::cout << "Cost of the solution: " << *(result.second) << std::endl;
59  } else {
60  std::cout << "The instance is infeasible" << std::endl;
61  }
62  paal::lp::glp::free_env();
63  return 0;
64 }
IRResult generalised_assignment_iterative_rounding(MachineIter mbegin, MachineIter mend, JobIter jbegin, JobIter jend, const Cost &c, const ProceedingTime &t, const MachineAvailableTime &T, JobsToMachinesOutputIterator jobs_to_machines, Components components=Components(), Visitor visitor=Visitor())
Solves the Generalised Assignment problem using Iterative Rounding.
int main()
[Generalised Assignment Example]