GEDLIB  1.0
ged_graph.hpp
Go to the documentation of this file.
1 /***************************************************************************
2 * *
3 * Copyright (C) 2018 by David B. Blumenthal *
4 * *
5 * This file is part of GEDLIB. *
6 * *
7 * GEDLIB is free software: you can redistribute it and/or modify it *
8 * under the terms of the GNU Lesser General Public License as published *
9 * by the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * GEDLIB is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with GEDLIB. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21 
27 #ifndef SRC_ENV_GED_GRAPH_HPP_
28 #define SRC_ENV_GED_GRAPH_HPP_
29 
30 #include "common_types.hpp"
31 #include "matrix.hpp"
32 
33 //#include "ged_graph.fwd.hpp"
34 
35 namespace ged {
36 
37 namespace detail {
38 
39 namespace al_graph_prop {
40 
41 struct node;
42 
43 struct edge;
44 
45 struct graph;
46 
47 }
48 
49 namespace am_graph_prop {
50 
51 struct node;
52 
53 struct edge;
54 
55 struct graph;
56 
57 }
58 
59 typedef boost::adjacency_list<
60  boost::vecS,
61  boost::vecS,
62  boost::undirectedS,
63  al_graph_prop::node,
64  al_graph_prop::edge
65  > GedGraphAL;
66 
67 typedef boost::adjacency_matrix<
68  boost::undirectedS,
69  am_graph_prop::node,
70  am_graph_prop::edge
71  > GedGraphAM;
72 
73 namespace al_graph_prop {
74 
75 struct node {
76  LabelID label{invalid_label()};
77 };
78 
79 struct edge {
80  LabelID label{invalid_label()};
81 };
82 
83 struct graph {};
84 
85 }
86 
87 namespace am_graph_prop {
88 
89 struct node {};
90 
91 struct edge {
92  GedGraphAL::edge_descriptor cref;
93 };
94 
95 struct graph {};
96 
97 }
98 
99 }
100 
104 class GEDGraph {
105 
106 public:
107 
108  typedef std::size_t NodeID;
109 
110  typedef detail::GedGraphAL::edge_descriptor EdgeID;
111 
112  typedef std::vector<GEDGraph>::size_type GraphID;
113 
114  typedef std::map<NodeID, NodeID> NodeNodeMap;
115 
116  typedef std::map<NodeID, std::size_t> NodeSizeTMap;
117 
118  typedef std::map<std::size_t, NodeID> SizeTNodeMap;
119 
120  typedef detail::GedGraphAL::out_edge_iterator incident_edge_iterator;
121 
122  typedef detail::GedGraphAL::edge_iterator edge_iterator;
123 
124  typedef detail::GedGraphAL::vertex_iterator node_iterator;
125 
129  GEDGraph();
130 
135  GEDGraph(GraphID id);
136 
141  GEDGraph(const GEDGraph & ged_graph);
142 
147  GraphID id() const;
148 
152  void clear();
153 
158  static NodeID dummy_node();
159 
164  static NodeID undefined_node();
165 
170  static EdgeID dummy_edge();
171 
172 
177  NodeID add_node();
178 
185  EdgeID add_edge(NodeID tail, NodeID head);
186 
192  void set_label(NodeID node, LabelID label);
193 
199  void set_label(EdgeID edge, LabelID label);
200 
206  LabelID get_node_label(NodeID node) const;
207 
213  LabelID get_edge_label(EdgeID edge) const;
214 
221  LabelID get_edge_label(NodeID node_1, NodeID node_2) const;
222 
227  void setup_adjacency_matrix();
228 
236  NodeID tail(EdgeID edge) const;
237 
245  NodeID head(EdgeID edge) const;
246 
247 
255  EdgeID get_edge(NodeID tail, NodeID head) const;
256 
257 
265  EdgeID safe_get_edge(NodeID tail, NodeID head) const;
266 
267 
275  bool is_edge(NodeID tail, NodeID head) const;
276 
284  bool safe_is_edge(NodeID tail, NodeID head) const;
285 
291  std::size_t degree(NodeID node) const;
292 
297  std::size_t num_nodes() const;
298 
303  std::size_t num_edges() const;
304 
309  bool initialized() const;
310 
314  void un_init();
315 
319  std::size_t maxdeg() const;
320 
325  std::pair<node_iterator, node_iterator> nodes() const;
326 
331  std::pair<edge_iterator, edge_iterator> edges() const;
332 
338  std::pair<incident_edge_iterator, incident_edge_iterator> incident_edges(NodeID node) const;
339 
344  const detail::GedGraphAL & get_adjacency_list() const;
345 
346 private:
347 
348  detail::GedGraphAL alist_;
349 
350  detail::GedGraphAM amatrix_;
351 
352  GraphID id_;
353 
354  bool initialized_;
355 };
356 
364 std::ostream & operator<<(std::ostream & os, const GEDGraph & graph);
365 
366 }
367 
368 #include "ged_graph.ipp"
369 
370 #endif /* SRC_ENV_GED_GRAPH_HPP_ */
std::map< NodeID, NodeID > NodeNodeMap
Map that assigns node IDs to node IDs.
Definition: ged_graph.hpp:114
std::map< NodeID, std::size_t > NodeSizeTMap
Map that assigns node IDs to integers.
Definition: ged_graph.hpp:116
ged::Matrix class declaration.
std::map< std::size_t, NodeID > SizeTNodeMap
Map that assigns node IDs to integers.
Definition: ged_graph.hpp:118
std::vector< GEDGraph >::size_type GraphID
Type of internally used graph IDs.
Definition: ged_graph.hpp:112
GEDGraph class definition.
std::ostream & operator<<(std::ostream &os, const std::map< Key, Value > &map)
Streams std::map.
detail::GedGraphAL::edge_iterator edge_iterator
Iterator type for iterating over all edges of the graph.
Definition: ged_graph.hpp:122
detail::GedGraphAL::out_edge_iterator incident_edge_iterator
Iterator type for iterating over all the incident edges of a node in the graph.
Definition: ged_graph.hpp:120
std::size_t LabelID
Internally used type of node and edge labels.
Type declarations used by various classes.
constexpr LabelID invalid_label()
Returns an invalid label.
The normalized input graphs used by GEDLIB. All labels are integers.
Definition: ged_graph.hpp:104
detail::GedGraphAL::vertex_iterator node_iterator
Iterator type for iterating over all nodes in the graph.
Definition: ged_graph.hpp:124
detail::GedGraphAL::edge_descriptor EdgeID
Internally used edge ID type.
Definition: ged_graph.hpp:110
Global namespace for GEDLIB.
std::size_t NodeID
Internally used vertex ID type.
Definition: ged_graph.hpp:108