graph Class Reference

[Index] [Hierarchy] [Headers]


A directed or undirected graph More...

#include <GTL/graph.h>

Public Members


Detailed Description

A graph G=(V,E) consists of a set of nodes V and a set of edges E, where every edge can be viewed as a (ordered) pair of nodes (u,v) connecting source u with target v. Obviously this implies a direction on the edges, which is why we call these graphs directed (this is the default). A graph can be made undirected by just ignoring the (implicit) direction.

See Also: node, edge


graph() [public]

Generates an empty graph, i.e. without any nodes and any edges.

graph(const graph& G) [public]

Copy constructor. Please note: This will generate an isomorpic copy of G. Although this graph will look like G it is not physically the same. Especially it consists of nodes and edges, which of course have counterparts in G, but are different. This means that the nodes (edges) in the copy have undefined behaviour if used within a node_map (edge_map ) of the original graph.

Parameters:
G graph

graph(const graph& G, const list<node>& nodes) [public]

Makes new graph isomorphic to the subgraph induced by nodes. The same restriction as for the ordinary copy constructor applies to this one.

Parameters:
G graph
nodes nodes of G, which form the induced subgraph this graph will be isomorphic to.

graph(const graph& G, list<node>::const_iterator it, list<node>::const_iterator end) [public]

Makes new graph isomorphic to the subgraph induced by the nodes in the range from it to end The same restriction as for the ordinary copy constructor applies to this one.

Parameters:
end end of nodes
G graph
it beginning of nodes

~graph() [public virtual]

Destructor. Deletes all nodes and edges.

void make_directed() [public]

Makes graph directed.

void make_undirected() [public]

Makes graph undirected.

bool is_directed() const [public]

Test whether the graph is directed.

Returns:
true iff the graph is directed.

bool is_undirected() const [public]

Test whether the graph is undirected.

Returns:
true iff the graph is undirected

bool is_bidirected(edge_map<edge>& rev) const [public]

Checks if for all edges (v, w) the reverse edge (w,v) is present, too. Additionally the reverse of some edge e will be stored as rev[e]. If there is no reverse edge of e rev[e] will be the invalid edge edge().

Parameters:
rev map associating every edge with its reverse edge.
Returns:
true iff every edge has a reverse edge.

bool is_connected() const [public]

Test whether the graph is connected

Returns:
true iff the graph is connected
See Also:
dfs, bfs

bool is_acyclic() const [public]

Test whether the graph is acyclic

Returns:
true iff the graph contains no cycles
See Also:
topsort

int number_of_nodes() const [public]

Returns the number of nodes in the graph.

Returns:
number of nodes

int number_of_edges() const [public]

Returns the number of (visible) edges in the graph

Returns:
number of edges

node center() const [public]

Returns a center of the graph which is defined as a node with maximum excentricity.

Returns:
one node of the graph center

node new_node() [public virtual]

Adds a new node.

Returns:
new node.

edge new_edge(node s, node t) [public virtual]

Adds new edge from s to t.

Precondition: s,t are valid nodes in this graph.

Parameters:
s source of new edge
t target of new edge
Returns:
new edge.

void del_node(node n) [public]

Deletes node n, and thus all edges incident with n.

Precondition: n is a valid visible node in this graph

Parameters:
n visible node to be deleted

void del_edge(edge e) [public]

Deletes edge e.

Precondition: e is a valid visible edge in this graph.

Parameters:
e edge to be deleted

void clear() [public]

Deletes all nodes and edges, even the hidden ones

node_iterator nodes_begin() const [public]

Iterate through all nodes in the graph.

Returns:
start for iteration through all nodes in the graph.

node_iterator nodes_end() const [public]

Iterate through all nodes in the graph.

Returns:
end for iteration through all nodes in the graph.

edge_iterator edges_begin() const [public]

Iterate through all edges in the graph.

Returns:
start for iteration through all edges in the graph.

edge_iterator edges_end() const [public]

Iterate through all edges in the graph.

Returns:
end for iteration through all edges in the graph.

void hide_edge(edge e) [public]

Hides an edge.

Precondition: e is a valid edge in this graph

Parameters:
e edge to be hidden

void restore_edge(edge e) [public]

Restores a hidden edge

Precondition: e is a valid edge in this graph

Parameters:
e hidden edge

list<edge> hide_node(node n) [public]

Hides a node. Please note: all the edges incident with n will be hidden, too. All these edges are returned in a list.

Precondition: n is a valid node in this graph

Parameters:
e node to be hidden
Returns:
list of implicitly hidden, incident edges

void restore_node(node n) [public]

Restores a hidden node. This only restores the node itself. It doesn't restore the incident edges, i.e. you will have to restore all the edges you get returned when calling graph::hide_node yourself.

Precondition: n is a valid node in this graph

Parameters:
n hidden node

void induced_subgraph(list<node>& subgraph_nodes) [public]

Hides all nodes not contained in subgraph_nodes, i.e. (the visible part of) the graph is the induced subgraph with respect to the nodes in subgraph_nodes. It is allowed to apply this function recursively, i.e. one may call induced_subgraph on a graph that is already a induced subgraph.

Parameters:
subgraph_nodes nodes of subgraph.
See Also:
graph::restore_graph

void restore_graph() [public]

Restores all hidden nodes and edges This means that, although the nodes and edges got hidden at different times, they will be restored all together.

See Also:
graph::induced_subgraph, graph::hide_edge, graph::hide_node

GML_error load(const string& filename) [public]

Load graph from a file in GML-format.

Parameters:
filename file in GML-format.
Returns:
detailed error description (hopefully GML_OK). For details see GML_error::err_num

GML_error load(const char* filename) [public]

Load graph from a file in GML-format.

Parameters:
filename file in GML-format.
Returns:
detailed error description (hopefully GML_OK). For details see GML_error::err_num

int save(const char* filename) const [public]

Save graph to file filename in GML-format, i.e. graph [ node [ id # ] ... edge [ source # target #] ... ]

Parameters:
filename
Returns:
0 on error 1 otherwise

void save(ostream* file = &cout) const [public]

Saves graph to stream file in GML-format.

Parameters:
file output stream defaults to cout.

void pre_new_node_handler() [public virtual]

Virtual function called before a new node is created; can be redefined in a derived class for customization

See Also:
graph::new_node

void post_new_node_handler(node n) [public virtual]

Virtual function called after a new node was created; can be redefined in a derived class for customization

Parameters:
n created node
See Also:
graph::new_node

void pre_del_node_handler(node n) [public virtual]

Virtual function called before a node is deleted; can be redefined in a derived class for customization

Parameters:
n node deleted afterwards
See Also:
graph::del_node

void post_del_node_handler() [public virtual]

Virtual function called after a node was deleted; can be redefined in a derived class for customization

See Also:
graph::del_node

void pre_hide_node_handler(node n) [public virtual]

Virtual function called before a node gets hidden; can be redefined in a derived class for customization

Parameters:
n node to be hidden
See Also:
graph::hide_node

void post_hide_node_handler(node n) [public virtual]

Virtual function called after a node got hidden; can be redefined in a derived class for customization

Parameters:
n hidden node
See Also:
graph::hide_node

void pre_restore_node_handler(node n) [public virtual]

Virtual function called before a node is restored; can be redefined in a derived class for customization

Parameters:
n node to be restored
See Also:
graph::restore_node

void post_restore_node_handler(node n) [public virtual]

Virtual function called after a node was restored; can be redefined in a derived class for customization

Parameters:
n restored node
See Also:
graph::restore_node

void pre_new_edge_handler(node s, node t) [public virtual]

Virtual function called before a new edge is inserted; can be redefined in a derived class for customization

Parameters:
s source of edge created afterwards
t target of edge created afterwards
See Also:
graph::new_edge

void post_new_edge_handler(edge e) [public virtual]

Virtual function called after a new edge was inserted; can be redefined in a derived class for customization

Parameters:
e created edge
See Also:
graph::new_edge

void pre_del_edge_handler(edge e) [public virtual]

Virtual function called before a edge is deleted; can be redefined in a derived class for customization

Parameters:
e edge to be deleted
See Also:
graph::del_edge

void post_del_edge_handler(node, node) [public virtual]

Virtual function called after a edge was deleted; can be redefined in a derived class for customization

Parameters:
s source of edge deleted
t target of edge deleted
See Also:
graph::del_edge

void pre_hide_edge_handler(edge e) [public virtual]

Virtual function called before a edge gets hidden; can be redefined in a derived class for customization

Parameters:
e edge to be hidden
See Also:
graph::hide_edge

void post_hide_edge_handler(edge e) [public virtual]

Virtual function called after a edge got hidden; can be redefined in a derived class for customization

Parameters:
e hidden edge
See Also:
graph::hide_edge

void pre_restore_edge_handler(edge e) [public virtual]

Virtual function called before a edge is restored; can be redefined in a derived class for customization

Parameters:
e edge to be restored
See Also:
graph::restore_edge

void post_restore_edge_handler(edge e) [public virtual]

Virtual function called after a edge was restored; can be redefined in a derived class for customization

Parameters:
e restored edge
See Also:
graph::restore_edge

void pre_clear_handler() [public virtual]

Virtual function called before performing clear; can be redefined in a derived class for customization. Please note: Although nodes and edges are deleted during graph::clear this is not achieved by calling graph::del_node and graph::del_edge which is why the correspondig handler will not be called.

See Also:
graph::clear

void post_clear_handler() [public virtual]

Virtual function called after the graph was cleared; can be redefined in a derived class for customization Please note: Although nodes and edges are deleted during graph::clear this is not achieved by calling graph::del_node and graph::del_edge which is why the correspondig handler will not be called.

See Also:
graph::clear

void pre_make_directed_handler() [public virtual]

Virtual function called before performing make_directed (only if graph was undirected) can be redefined in a derived class for customization

See Also:
graph::make_directed

void post_make_directed_handler() [public virtual]

Virtual function called after performing make_directed; (only if graph was undirected) can be redefined in a derived class for customization

See Also:
graph::make_directed

void pre_make_undirected_handler() [public virtual]

Virtual function called before performing make_undirected; (only if graph was directed) can be redefined in a derived class for customization

See Also:
graph::make_undirected

void post_make_undirected_handler() [public virtual]

Virtual function called after performing make_undirected; (only if graph was directed) can be redefined in a derived class for customization

See Also:
graph::make_undirected

void pre_graph_save_handler(ostream* os) const [public virtual]

Called before writing the graph key to os. This can be used to write top-level keys that should appear before the graph in the file.

Parameters:
os output stream.
See Also:
graph::save

void save_graph_info_handler(ostream*) const [public virtual]

Called before the closing bracket of the list belonging to the graph key is written. This can be used to write information that belong to the graph, and thus should appear within the list associated with the graph key.

Parameters:
os output stream.
See Also:
graph::save

void save_node_info_handler(ostream*, node) const [public virtual]

Called before the closing bracket of the list belonging to the key of node n is written. This can be used to write information belonging to the node n and thus should appear within the list associated with this node.

Parameters:
os output stream.
See Also:
graph::save

void save_edge_info_handler(ostream*, edge) const [public virtual]

Called before the closing bracket of the list belonging to the key of edge e is written. This can be used to write information belonging to the edge e and thus should appear within the list associated with this edge.

Parameters:
os output stream.
See Also:
graph::save

void after_graph_save_handler(ostream* ) const [public virtual]

Called after writing the graph key to os. This can be used to write top-level keys that should appear after the graph in the file.

Parameters:
os output stream.
See Also:
graph::save

void top_level_key_handler(GML_pair* list) [public virtual]

Called when all information belonging to the first key "graph" is parsed, i.e. all the key-value-pairs, which are at the topmost level - except the graph key will be passed to this handler.

Parameters:
list pointer to the list of key-value pairs at top level
See Also:
graph::load

void load_node_info_handler(node n, GML_pair* list ) [public virtual]

Called when all the essential information belonging to a node is parsed. All the key-value-pairs which were not used by GTL will be passed to this handler.

Parameters:
list pointer to the list of key-value-pairs of this node.
n node parsed
See Also:
graph::load

void load_edge_info_handler(edge e, GML_pair* list) [public virtual]

Called when all the essential information belonging to an edge is parsed. All the key-value-pairs which were not used by GTL will be passed to this handler.

Parameters:
list pointer to the list of key-value-pairs of this edge.
e edge parsed
See Also:
graph::load

void load_graph_info_handler(GML_pair* list) [public virtual]

Called when all the essential information belonging to a graph is parsed. All the key-value-pairs which were not used by GTL will be passed to this handler.

Parameters:
list pointer to the list of key-value-pairs of the graph.
See Also:
graph::load

Kdoc