TCPSPSuite
laggraph.hpp
1 #ifndef LAGGRAPH_HPP
2 #define LAGGRAPH_HPP
3 
4 #include <cstdlib> // for size_t
5 #include <iterator> // for input_iterator_tag
6 #include <limits> // for numeric_limits
7 #include <map> // for map, map<>::const_iterator
8 #include <vector> // for vector, vector<>::const_iterator
9 #include "generated_config.hpp" // for ENABLE_CONSISTENCY_CHECKS
10 class Job; // lines 10-10
11 
12 class LagGraph {
13 public:
14  typedef unsigned int vertex;
15  static const vertex no_vertex = std::numeric_limits<vertex>::max();
16 
17  typedef struct { int lag; double drain_factor; unsigned int max_recharge; } edge;
18  typedef struct { vertex s; vertex t; int lag; double drain_factor; unsigned int max_recharge; } full_edge;
19 
20 
21  class EdgeContainer {
22  public:
23  typedef full_edge value_type;
24  typedef full_edge *pointer;
25  typedef const full_edge *const_pointer;
26  typedef full_edge &reference;
27  typedef const full_edge &const_reference;
28  typedef size_t size_type;
29 
30  template<class base>
31  class iterator {
32  public:
33  typedef std::input_iterator_tag iterator_category;
34  typedef base value_type;
35  typedef base *pointer;
36  typedef base &reference;
37  typedef size_t size_type;
38  //typedef ptrdiff_t difference_type;
39 
40  iterator(const EdgeContainer *c, bool end = false);
41 
42  value_type &operator*();
43  value_type *operator->();
44 
45  iterator<base> operator++(int);
46  iterator<base> operator++();
47 
48  bool operator==(const iterator<base> &other) const;
49  bool operator!=(const iterator<base> &other) const;
50 
51  private:
52  const EdgeContainer *c;
53  std::vector< std::map< vertex, edge >>::const_iterator outer;
54  std::map<vertex, edge>::const_iterator inner_iterator;
55 
56  full_edge buf;
57  };
58 
59  EdgeContainer(const LagGraph *g, bool reverse = false);
60  EdgeContainer(const LagGraph *g, unsigned int vertex, bool reverse = false);
61  EdgeContainer(const LagGraph *g,
62  std::vector< std::map< vertex, edge >>::const_iterator start,
63  std::vector< std::map< vertex, edge >>::const_iterator end,
64  std::vector< std::map< vertex, edge >>::const_iterator index_start);
65 
66  // TODO why do these two have to be const? I don't get it.
67  iterator<full_edge> begin() const;
68  iterator<full_edge> end() const;
69  iterator<const full_edge> cbegin() const;
70  iterator<const full_edge> cend() const;
71 
72 
73  private:
74  const LagGraph *g;
75  std::vector< std::map< vertex, edge >>::const_iterator base_start;
76  std::vector< std::map< vertex, edge >>::const_iterator base_end;
77  std::vector< std::map< vertex, edge >>::const_iterator index_start;
78  };
79 
80  LagGraph();
81 
82  void set_limitations(unsigned long limitations);
83 
84  vertex add_vertex();
85  void add_edge(const Job & s, const Job & t, edge lag);
86  void delete_edge(const Job &s, const Job &t);
87 
88  edge *get_edge(const Job & s, const Job & t);
89  const edge *get_edge(const Job & s, const Job & t) const;
90  edge *get_edge(vertex s, vertex t);
91  const edge *get_edge(vertex s, vertex t) const;
92 
93  EdgeContainer edges();
94  const EdgeContainer edges() const;
95  EdgeContainer reverse_edges();
96  const EdgeContainer reverse_edges() const;
97 
98  // TODO rewrite this to const Job &!
99  const EdgeContainer neighbors(vertex v) const;
100  const EdgeContainer reverse_neighbors(vertex v) const;
101 
102  size_t neighbor_count(vertex v) const;
103  size_t reverse_neighbor_count(vertex v) const;
104  size_t edge_count() const;
105  size_t vertex_count() const;
106 
107 /*
108  // Public Algorithms
109  std::map<unsigned int, int> critical_start_times();
110  std::map<unsigned int, int> critical_end_times();
111 */
112 
113  #ifdef ENABLE_CONSISTENCY_CHECKS
114  void check_consistency();
115  #else
116  inline void check_consistency() {};
117  #endif
118 
119  // deepcopy
120  LagGraph clone() const;
121 
122 private:
123  void add_edge(vertex s, vertex t, edge e);
124 
125  size_t edge_counter;
126 
127  std::vector< std::map< vertex, edge >> adj;
128  std::vector< std::map< vertex, edge >> reverse_adj;
129 
130  void check_edge_iterator_consistency();
131 };
132 
133 #endif
Job
A job of an TCPSP instance.
Definition: job.hpp:21