27 #ifndef SRC_ENV_GED_GRAPH_IPP_ 28 #define SRC_ENV_GED_GRAPH_IPP_ 38 initialized_{
false} {}
45 initialized_{
false} {}
49 alist_(ged_graph.alist_),
50 amatrix_(ged_graph.amatrix_),
52 initialized_{ged_graph.initialized_} {}
57 return std::numeric_limits<NodeID>::max() - 1;
63 return std::numeric_limits<NodeID>::max();
69 return std::numeric_limits<EdgeID>::max();
76 NodeID new_node{boost::add_vertex(alist_)};
78 throw Error(
"Cannot add node. Maximal number of nodes reached.");
88 auto alist_ed = boost::add_edge(tail, head, alist_);
90 return alist_ed.first;
97 for (
auto eitr = boost::edges(alist_); eitr.first != eitr.second; ++eitr.first) {
99 NodeID source {boost::source(e, alist_)};
100 NodeID target {boost::target(e, alist_)};
102 auto am_edge = boost::add_edge(source, target, tmp);
103 if (am_edge.second ==
false) {
104 throw Error(
"Parallel edge detected!");
106 tmp[am_edge.first].cref = e;
108 std::swap(tmp, amatrix_);
115 alist_[v].label = l_id;
121 alist_[e].label = l_id;
130 return alist_[node].label;
136 return alist_[e].label;
148 std::pair<GEDGraph::incident_edge_iterator, GEDGraph::incident_edge_iterator>
151 return boost::out_edges(v, alist_);
154 const detail::GedGraphAL &
163 return static_cast<std::size_t
>(boost::out_degree(v, alist_));
170 for (
auto node = this->
nodes().first; node != this->
nodes().second; node++) {
173 return static_cast<std::size_t
>(
maxdeg);
179 return boost::source(e, alist_);
191 initialized_ =
false;
193 detail::GedGraphAM tmp(1);
194 std::swap(tmp, amatrix_);
200 return boost::target(e, alist_);
203 std::pair<GEDGraph::node_iterator, GEDGraph::node_iterator>
206 return boost::vertices(alist_);
212 return static_cast<std::size_t
>(boost::num_vertices(alist_));
215 std::pair<GEDGraph::edge_iterator, GEDGraph::edge_iterator>
218 return boost::edges(alist_);
224 return static_cast<std::size_t
>(boost::num_edges(alist_));
236 initialized_ =
false;
242 auto am_edge = boost::edge(source, target, amatrix_);
243 if (am_edge.second ==
false) {
246 return amatrix_[am_edge.first].cref;
252 for (
auto iedges =
incident_edges(source); iedges.first != iedges.second; ++iedges.first) {
253 EdgeID e { *iedges.first };
255 if (n == target)
return e;
266 auto am_edge = boost::edge(source, target, amatrix_);
267 return am_edge.second;
273 for (
auto iedges =
incident_edges(source); iedges.first != iedges.second; ++iedges.first) {
274 EdgeID e { *iedges.first };
276 if (n == target)
return true;
282 os <<
"ID = " << graph.
id() <<
", number of nodes = " << graph.
num_nodes() <<
", number of edges = " << graph.
num_edges();
283 os <<
"\nadjacency matrix:\n ";
285 os <<
"\033[1m" << std::setw(3) << std::right << graph.
get_node_label(*
head) <<
"\033[0m" <<
" ";
289 os <<
"\033[1m" << std::setw(3) << std::right << graph.
get_node_label(*
tail) <<
"\033[0m" <<
" ";
299 os << std::setw(3) << std::right << 0 <<
" ";
void un_init()
Declare graph as un-initialized.
std::size_t num_nodes() const
Returns the number of nodes.
EdgeID add_edge(NodeID tail, NodeID head)
Adds a new edge to the graph.
const detail::GedGraphAL & get_adjacency_list() const
Returns the internal adjacency list representation.
GEDGraph()
Constructs an empty graph without meaningful ID.
std::vector< GEDGraph >::size_type GraphID
Type of internally used graph IDs.
EdgeID get_edge(NodeID tail, NodeID head) const
Retrieves an edge from its incident nodes.
NodeID head(EdgeID edge) const
Returns the head of an edge.
bool is_edge(NodeID tail, NodeID head) const
Checks if an edge exists.
static EdgeID dummy_edge()
Returns a dummy edge.
std::size_t degree(NodeID node) const
Returns node degree.
std::size_t maxdeg() const
Returns the maximum degree of the graph.
EdgeID safe_get_edge(NodeID tail, NodeID head) const
Retrieves an edge from its incident nodes.
std::size_t LabelID
Internally used type of node and edge labels.
void clear()
Clears the graph.
NodeID tail(EdgeID edge) const
Returns the tail of an edge.
LabelID get_node_label(NodeID node) const
Returns the label of a given node.
std::size_t num_edges() const
Returns the number of edges.
static NodeID dummy_node()
Returns a dummy node.
static NodeID undefined_node()
Returns an undefined node.
std::ostream & operator<<(std::ostream &os, const GEDGraph &graph)
Streams a graph.
LabelID get_edge_label(EdgeID edge) const
Returns the label of a given edge.
void set_label(NodeID node, LabelID label)
Sets a node's label.
std::pair< incident_edge_iterator, incident_edge_iterator > incident_edges(NodeID node) const
Provides access to all incident edges of a node.
std::pair< node_iterator, node_iterator > nodes() const
Provides access to all nodes in the graph.
constexpr LabelID invalid_label()
Returns an invalid label.
The normalized input graphs used by GEDLIB. All labels are integers.
detail::GedGraphAL::edge_descriptor EdgeID
Internally used edge ID type.
constexpr LabelID dummy_label()
Returns a dummy label.
constexpr std::size_t undefined()
Returns undefined size.
Global namespace for GEDLIB.
NodeID add_node()
Adds a new vertex to the graph.
std::size_t NodeID
Internally used vertex ID type.
bool initialized() const
Checks if graph has already been initialized.
GraphID id() const
Returns the ID of the graph.
bool safe_is_edge(NodeID tail, NodeID head) const
Checks if an edge exists.
void setup_adjacency_matrix()
Prepares the adjacency matrix to allow quick retrieval of edges.
std::pair< edge_iterator, edge_iterator > edges() const
Provides access to all edge in the graph.