graph Class Reference

A directed or undirected graph. More...

List of all members.

Public Member Functions

 graph ()
 graph (const graph &G)
 graph (const graph &G, const list< node > &nodes)
 graph (const graph &G, list< node >::const_iterator it, list< node >::const_iterator end)
virtual ~graph ()
void make_directed ()
void make_undirected ()
bool is_directed () const
bool is_undirected () const
bool is_bidirected (edge_map< edge > &rev) const
bool is_connected () const
bool is_acyclic () const
int number_of_nodes () const
int number_of_edges () const
node center () const
virtual node new_node ()
virtual edge new_edge (node s, node t)
void del_node (node n)
void del_all_nodes ()
void del_edge (edge e)
void del_all_edges ()
void clear ()
node_iterator nodes_begin () const
node_iterator nodes_end () const
edge_iterator edges_begin () const
edge_iterator edges_end () const
list< nodeall_nodes () const
list< edgeall_edges () const
node choose_node () const
void hide_edge (edge e)
void restore_edge (edge e)
list< edgehide_node (node n)
void restore_node (node n)
void induced_subgraph (list< node > &subgraph_nodes)
void restore_graph ()
list< edgeinsert_reverse_edges ()
GML_error load (const string &filename, bool preserve_ids=false)
GML_error load (const char *filename, bool preserve_ids=false)
int save (const char *filename) const
void save (ostream *file=&cout) const
virtual void pre_new_node_handler ()
virtual void post_new_node_handler (node n)
virtual void pre_del_node_handler (node n)
virtual void post_del_node_handler ()
virtual void pre_hide_node_handler (node n)
virtual void post_hide_node_handler (node n)
virtual void pre_restore_node_handler (node n)
virtual void post_restore_node_handler (node n)
virtual void pre_new_edge_handler (node s, node t)
virtual void post_new_edge_handler (edge e)
virtual void pre_del_edge_handler (edge e)
virtual void post_del_edge_handler (node, node)
virtual void pre_hide_edge_handler (edge e)
virtual void post_hide_edge_handler (edge e)
virtual void pre_restore_edge_handler (edge e)
virtual void post_restore_edge_handler (edge e)
virtual void pre_clear_handler ()
virtual void post_clear_handler ()
virtual void pre_make_directed_handler ()
virtual void post_make_directed_handler ()
virtual void pre_make_undirected_handler ()
virtual void post_make_undirected_handler ()
virtual void pre_graph_save_handler (ostream *os) const
virtual void save_graph_info_handler (ostream *) const
virtual void save_node_info_handler (ostream *, node) const
virtual void save_edge_info_handler (ostream *, edge) const
virtual void after_graph_save_handler (ostream *) const
virtual void top_level_key_handler (GML_pair *list)
virtual void load_node_info_handler (node n, GML_pair *list)
virtual void load_edge_info_handler (edge e, GML_pair *list)
virtual void load_graph_info_handler (GML_pair *list)


Detailed Description

A directed or undirected graph.

Date
Revision

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


Constructor & Destructor Documentation

graph::graph (  ) 

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

graph::graph ( const graph G  ) 

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:
<code>G</code> graph

graph::graph ( const graph G,
const list< node > &  nodes 
)

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

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

graph::graph ( const graph G,
list< node >::const_iterator  it,
list< node >::const_iterator  end 
)

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:
<code>G</code> graph
<code>it</code> beginning of nodes
<code>end</code> end of nodes

virtual graph::~graph (  )  [virtual]

Destructor. Deletes all nodes and edges.


Member Function Documentation

void graph::make_directed (  ) 

Makes graph directed.

void graph::make_undirected (  ) 

Makes graph undirected.

bool graph::is_directed (  )  const

Test whether the graph is directed.

Returns:
true iff the graph is directed.

bool graph::is_undirected (  )  const

Test whether the graph is undirected.

Returns:
true iff the graph is undirected

bool graph::is_bidirected ( edge_map< edge > &  rev  )  const

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:
<code>rev</code> map associating every edge with its reverse edge.
Returns:
true iff every edge has a reverse edge.

bool graph::is_connected (  )  const

Test whether the graph is connected

Returns:
true iff the graph is connected
See also:
dfs

bfs

bool graph::is_acyclic (  )  const

Test whether the graph is acyclic

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

int graph::number_of_nodes (  )  const

Returns the number of nodes in the graph.

Returns:
number of nodes

int graph::number_of_edges (  )  const

Returns the number of (visible) edges in the graph

Returns:
number of edges

node graph::center (  )  const

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

Returns:
one node of the graph center

virtual node graph::new_node (  )  [virtual]

Adds a new node.

Returns:
new node.

virtual edge graph::new_edge ( node  s,
node  t 
) [virtual]

Adds new edge from s to t.

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

Parameters:
<code>s</code> source of new edge
<code>t</code> target of new edge
Returns:
new edge.

void graph::del_node ( node  n  ) 

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

Precondition: n is a valid visible node in this graph

Parameters:
<code>n</code> visible node to be deleted

void graph::del_all_nodes (  ) 

Deprecated:
Deletes all visible nodes, i.e. the hidden ones stay.

void graph::del_edge ( edge  e  ) 

Deletes edge e.

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

Parameters:
<code>e</code> edge to be deleted

void graph::del_all_edges (  ) 

Deprecated:
Deletes all visible edges, i.e. the hidden ones stay.

void graph::clear (  ) 

Deletes all nodes and edges, even the hidden ones

node_iterator graph::nodes_begin (  )  const

Iterate through all nodes in the graph.

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

node_iterator graph::nodes_end (  )  const

Iterate through all nodes in the graph.

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

edge_iterator graph::edges_begin (  )  const

Iterate through all edges in the graph.

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

edge_iterator graph::edges_end (  )  const

Iterate through all edges in the graph.

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

list<node> graph::all_nodes (  )  const

Deprecated:
Returns:
a list of all nodes of the graph

list<edge> graph::all_edges (  )  const

Deprecated:
Returns:
a list of all edges of the graph

node graph::choose_node (  )  const

Deprecated:

void graph::hide_edge ( edge  e  ) 

Hides an edge.

Precondition: e is a valid edge in this graph

Parameters:
<code>e</code> edge to be hidden

void graph::restore_edge ( edge  e  ) 

Restores a hidden edge

Precondition: e is a valid edge in this graph

Parameters:
<code>e</code> hidden edge

list<edge> graph::hide_node ( node  n  ) 

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:
<code>e</code> node to be hidden
Returns:
list of implicitly hidden, incident edges

void graph::restore_node ( node  n  ) 

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:
<code>n</code> hidden node

void graph::induced_subgraph ( list< node > &  subgraph_nodes  ) 

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:
<code>subgraph_nodes</code> nodes of subgraph.
See also:
graph::restore_graph

void graph::restore_graph (  ) 

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

list<edge> graph::insert_reverse_edges (  ) 

Deprecated:
inserts for all edges of the graph a reverse edge NOTE: this functions does NOT care about existing reverse edges

GML_error graph::load ( const string &  filename,
bool  preserve_ids = false 
) [inline]

Load graph from a file in GML-format. The optional parameter preserve_ids controls whether to give the nodes the same ids as in the GML file. You can enable this for debugging but you should disable it for final releases since it may make node_map unecessarily large.

Parameters:
<code>filename</code> file in GML-format.
<code>preserve_ids</code> if true all the nodes will get the same id as in the GML file. If false (default) the nodes will be numbered consecutively beginning with 0. However the order of the nodes in the GML file will be preserved.
Returns:
detailed error description (hopefully GML_OK). For details see GML_error::err_num.

GML_error graph::load ( const char *  filename,
bool  preserve_ids = false 
)

Load graph from a file in GML-format. The optional parameter preserve_ids controls whether to give the nodes the same ids as in the GML file. You can enable this for debugging but you should disable it for final releases since it may make node_map unecessarily large.

Parameters:
<code>filename</code> file in GML-format.
<code>preserve_ids</code> if true all the nodes will get the same id as in the GML file. If false (default) the nodes will be numbered consecutively beginning with 0. However the order of the nodes in the GML file will be preserved.
Returns:
detailed error description (hopefully GML_OK). For details see GML_error::err_num.

int graph::save ( const char *  filename  )  const

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

Parameters:
<code>filename</code> 
Returns:
0 on error 1 otherwise

void graph::save ( ostream *  file = &cout  )  const

Saves graph to stream file in GML-format.

Parameters:
<code>file</code> output stream defaults to cout.

virtual void graph::pre_new_node_handler (  )  [inline, virtual]

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

See also:
graph::new_node

virtual void graph::post_new_node_handler ( node  n  )  [inline, virtual]

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

Parameters:
<code>n</code> created node
See also:
graph::new_node

virtual void graph::pre_del_node_handler ( node  n  )  [inline, virtual]

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

Parameters:
<code>n</code> node deleted afterwards
See also:
graph::del_node

virtual void graph::post_del_node_handler (  )  [inline, virtual]

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

See also:
graph::del_node

virtual void graph::pre_hide_node_handler ( node  n  )  [inline, virtual]

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

Parameters:
<code>n</code> node to be hidden
See also:
graph::hide_node

virtual void graph::post_hide_node_handler ( node  n  )  [inline, virtual]

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

Parameters:
<code>n</code> hidden node
See also:
graph::hide_node

virtual void graph::pre_restore_node_handler ( node  n  )  [inline, virtual]

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

Parameters:
<code>n</code> node to be restored
See also:
graph::restore_node

virtual void graph::post_restore_node_handler ( node  n  )  [inline, virtual]

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

Parameters:
<code>n</code> restored node
See also:
graph::restore_node

virtual void graph::pre_new_edge_handler ( node  s,
node  t 
) [inline, virtual]

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

Parameters:
<code>s</code> source of edge created afterwards
<code>t</code> target of edge created afterwards
See also:
graph::new_edge

virtual void graph::post_new_edge_handler ( edge  e  )  [inline, virtual]

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

Parameters:
<code>e</code> created edge
See also:
graph::new_edge

virtual void graph::pre_del_edge_handler ( edge  e  )  [inline, virtual]

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

Parameters:
<code>e</code> edge to be deleted
See also:
graph::del_edge

virtual void graph::post_del_edge_handler ( node  ,
node   
) [inline, virtual]

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

Parameters:
<code>s</code> source of edge deleted
<code>t</code> target of edge deleted
See also:
graph::del_edge

virtual void graph::pre_hide_edge_handler ( edge  e  )  [inline, virtual]

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

Parameters:
<code>e</code> edge to be hidden
See also:
graph::hide_edge

virtual void graph::post_hide_edge_handler ( edge  e  )  [inline, virtual]

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

Parameters:
<code>e</code> hidden edge
See also:
graph::hide_edge

virtual void graph::pre_restore_edge_handler ( edge  e  )  [inline, virtual]

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

Parameters:
<code>e</code> edge to be restored
See also:
graph::restore_edge

virtual void graph::post_restore_edge_handler ( edge  e  )  [inline, virtual]

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

Parameters:
<code>e</code> restored edge
See also:
graph::restore_edge

virtual void graph::pre_clear_handler (  )  [inline, 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

virtual void graph::post_clear_handler (  )  [inline, 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

virtual void graph::pre_make_directed_handler (  )  [inline, 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

virtual void graph::post_make_directed_handler (  )  [inline, 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

virtual void graph::pre_make_undirected_handler (  )  [inline, 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

virtual void graph::post_make_undirected_handler (  )  [inline, 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

virtual void graph::pre_graph_save_handler ( ostream *  os  )  const [inline, 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:
<code>os</code> output stream.
See also:
graph::save

virtual void graph::save_graph_info_handler ( ostream *   )  const [inline, 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:
<code>os</code> output stream.
See also:
graph::save

virtual void graph::save_node_info_handler ( ostream *  ,
node   
) const [inline, 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:
<code>os</code> output stream.
See also:
graph::save

virtual void graph::save_edge_info_handler ( ostream *  ,
edge   
) const [inline, 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:
<code>os</code> output stream.
See also:
graph::save

virtual void graph::after_graph_save_handler ( ostream *   )  const [inline, 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:
<code>os</code> output stream.
See also:
graph::save

virtual void graph::top_level_key_handler ( GML_pair *  list  )  [virtual]

Called after the graph is completely built. The topmost list of key-value-pairs is passed to this handler. NB: This list also contains the graph key, which was used to build the graph.

Parameters:
<code>list</code> pointer to the list of key-value pairs at top level
See also:
graph::load

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

Called after a node is created. The whole list of key-value-pairs belonging to this node is passed to this handler together with the node itself.

Parameters:
<code>n</code> node parsed
<code>list</code> pointer to the list of key-value-pairs of this node.
See also:
graph::load

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

Called after an edge is created. The whole list of key-value-pairs belonging to this edge is passed to this handler together with the edge itself.

Parameters:
<code>e</code> edge parsed
<code>list</code> pointer to the list of key-value-pairs of this edge.
See also:
graph::load

virtual void graph::load_graph_info_handler ( GML_pair *  list  )  [virtual]

Called after the graph is completely built. The whole list for the graph key used to build this graph is passed to this handler.

Parameters:
<code>list</code> pointer to the list of key-value-pairs of the graph.
See also:
graph::load