TCPSPSuite
graphalgos.hpp
1 #ifndef GRAPHALGOS_H
2 #define GRAPHALGOS_H
3 
4 #include "../instance/laggraph.hpp" // for LagGraph, LagGraph::vertex
5 #include "../util/log.hpp"
6 
7 #include <vector> // for vector
8 class Instance;
9 
10 template <typename visit_func, typename backtrack_func, typename traverse_func>
11 class DFS {
12 public:
13  using vertex = LagGraph::vertex;
14 
15  DFS(const LagGraph & graph, const LagGraph::vertex start, visit_func visit,
16  backtrack_func backtrack, traverse_func traverse, bool reverse = false);
17 
18 private:
19  visit_func visit;
20  backtrack_func backtrack;
21  traverse_func traverse;
22  const LagGraph & graph;
23 
24  std::vector<bool> visited;
25 
26  void dfs_rec(vertex v, vertex from, bool reverse);
27 };
28 
29 class TopologicalSort {
30 public:
31  TopologicalSort(const LagGraph & graph);
32  std::vector<LagGraph::vertex> get();
33 
34 private:
35  const LagGraph & graph;
36 };
37 
38 // TODO this is currently only based on earliest starts / latest finishs.
39 // We should incorporate dependency path length here!
40 class NecessaryOrderComputer {
41 public:
42  NecessaryOrderComputer(const Instance & instance);
43  // Returns, for each job, the minimum number of jobs that must be finished
44  // before the respective job can start.
45  const std::vector<size_t> & get_predecessor_count() const noexcept;
46  // Returns, for each job, the minimum number of jobs that cannot have started
47  // before the respective job finishes
48  const std::vector<size_t> & get_successor_count() const noexcept;
49 
50 private:
51  std::vector<size_t> predecessor_count;
52  std::vector<size_t> successor_count;
53 
54  const Instance & instance;
55 
56  void compute();
57 
58  std::vector<unsigned int> earliest_starts;
59  std::vector<unsigned int> latest_finishs;
60 };
61 
62 class CriticalPathComputer {
63 public:
64  CriticalPathComputer(const Instance & instance);
65  std::vector<unsigned int> get_forward();
66  std::vector<unsigned int> get_reverse();
67 
68 private:
69  Log l;
70  const Instance & instance;
71 };
72 
73 class APLPComputer {
74 public:
75  APLPComputer(const Instance & instance);
76  // -1 as path length means 'no path'
77  std::vector<std::vector<int>> get();
78 
79 private:
80  std::vector<std::vector<int>> result;
81  std::vector<unsigned int> topological_order;
82 
83  void compute_SSLP(unsigned int start_job);
84 
85  const Instance & instance;
86 };
87 
88 #include "graphalgos_templates.cpp"
89 
90 #endif
Instance
a TCPSP instance
Definition: instance.hpp:24