Rosetta
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | Friends | List of all members
utility::graph::Digraph Class Reference

A Digraph with constant time edge insertion and deletion. Extensible. More...

#include <Digraph.hh>

Inheritance diagram for utility::graph::Digraph:
Inheritance graph
[legend]

Public Types

typedef utility::vector1< DirectedNode * > DirectedNodeVector
 
typedef DirectedNode::DirectedEdgeListIter DirectedEdgeListIter
 
typedef DirectedNode::DirectedEdgeListConstIter DirectedEdgeListConstIter
 
typedef utility::VirtualBase parent
 

Public Member Functions

DigraphCOP get_self_ptr () const
 self pointers More...
 
DigraphOP get_self_ptr ()
 
 ~Digraph () override
 virtual destructor. Derived classes must ensure they've destroyed all their nodes and edges through a call to "destroy_everything" before this function is arrived at More...
 
 Digraph ()
 ctor More...
 
 Digraph (platform::Size num_nodes)
 num nodes ctor More...
 
 Digraph (Digraph const &source)
 copy ctor. Must not be called by derived class copy ctors. More...
 
Digraphoperator= (Digraph const &source)
 assignment operator. source and this must have the same type. More...
 
void copy_connectivity (Digraph const &source)
 copy the edge connectivity from a source graph with a potentially unknown type. More...
 
platform::Size num_nodes () const
 the number of nodes in the graph More...
 
void set_num_nodes (platform::Size num_nodes)
 set the number of nodes in the graph – deletes any existing edges in the graph More...
 
void add_node ()
 Add a new node to the graph; preserve all of the existing edges in the graph. More...
 
DirectedEdgeadd_edge (platform::Size tail_node, platform::Size head_node)
 add a directed edge between two vertices. Invokes "create_edge" from the derived class. Returns a pointer to the edge after its been added, allowing the calling function to immediately set data for this edge. More...
 
DirectedEdgeadd_edge (DirectedEdge const *example_edge)
 add an edge to this graph copying the data from an edge in another graph. Returns a pointer to the edge after its been added, allowing the calling function to immediately set data for this edge. More...
 
bool get_edge_exists (platform::Size tail_node, platform::Size head_node) const
 is an edge already present in the graph? O(V) worst case. O(1) iff all vertices have O(1) edges More...
 
void drop_all_edges ()
 delete all the edges present in the graph More...
 
void drop_all_edges_for_node (platform::Size node)
 delete all the edges for a single vertex in the graph More...
 
void print_vertices () const
 send summary information to the screen for all vertices in the graph More...
 
void output_connectivity (std::ostream &os) const
 send an edge list to the stream os. More...
 
void output_dimacs (std::ostream &os) const
 describe this graph in dimacs form to the stream os. More...
 
DirectedNode const * get_node (platform::Size index) const
 
DirectedNodeget_node (platform::Size index)
 
platform::Size num_edges () const
 
DirectedEdgeListConstIter const_edge_list_begin () const
 returns a const iterator to the beginning of the (unordered) edge list for the graph. this edge list contains all the edges in the graph, not simply those for a particular vertex More...
 
DirectedEdgeListIter edge_list_begin ()
 returns a non-const iterator to the beginning of the (unordered) edge list for the graph. this edge list contains all the edges in the graph, not simply those for a particular vertex More...
 
DirectedEdgeListConstIter const_edge_list_end () const
 returns a const iterator to the end of the (unordered) edge list for the graph. this edge list contains all the edges in the graph, not simply those for a particular vertex More...
 
DirectedEdgeListIter edge_list_end ()
 returns a non-const iterator to the end of the (unordered) edge list for the graph. this edge list contains all the edges in the graph, not simply those for a particular vertex More...
 
DirectedEdgefind_edge (platform::Size tail_node, platform::Size head_node)
 returns a pointer to the directed edge connecting nodes tail_node and head_node, if that edge exists in the graph, o.w. returns 0. Focuses the graph on this edge for fast subsequent retrieval. More...
 
DirectedEdge const * find_edge (platform::Size tail_node, platform::Size head_node) const
 returns a const pointer to the directed edge connecting nodes tail_node and head_node, if that edge exists in the graph, o.w. returns 0. Focuses the graph on this edge for fast subsequent retrieval. More...
 
DirectedEdgefocused_edge ()
 returns a pointer to the focused edge More...
 
DirectedEdge const * focused_edge () const
 returns a const-pointer to the focused edge More...
 
virtual void delete_edge (DirectedEdge *edge)
 remove an edge from the graph. (NEW AS OF 12/9/07) Never call C++'s "delete" function on an edge pointer directly. Derived classes must implement this function. If they wish to use unordered_object_pools to manage their memory More...
 
platform::Size getTotalMemoryUsage () const
 returns a count of all the memory used by every vertex and edge in a graph by invoking the polymorphic count_static_memory and count_dynamic_memory of each (possibly derived) node and edge object as well as for the (possibly derived) graph class. More...
 
- Public Member Functions inherited from utility::VirtualBase
 VirtualBase ()=default
 Default constructor. More...
 
virtual ~VirtualBase ()=default
 The virtual destructor is one of the main reasons for the VirtualBase class. More...
 
 VirtualBase (VirtualBase const &)=default
 
 VirtualBase (VirtualBase &&)=default
 
VirtualBaseoperator= (VirtualBase const &)=default
 
VirtualBaseoperator= (VirtualBase &&)=default
 

Protected Member Functions

virtual platform::Size count_static_memory () const
 
virtual platform::Size count_dynamic_memory () const
 
void drop_edge (DirectedEdgeListIter edge_iter)
 remove an edge from the entire-graph edge list. Called only by class DirectedEdge during its destructor More...
 
void delete_everything ()
 deallocate all nodes and edges from the graph More...
 
virtual DirectedNodecreate_new_node (platform::Size node_index)
 factory method for node creation, defined by derived graph classes, called by the base class More...
 
virtual DirectedEdgecreate_new_edge (platform::Size index1, platform::Size index2)
 factory method for edge creation, defined by derived graph classes, called by the base class More...
 
virtual DirectedEdgecreate_new_edge (DirectedEdge const *example_edge)
 factory method for edge copy-construction. Derived class should downcast the example_edge pointer and may read that edge's data. More...
 
boost::unordered_object_pool< DirectedEdgeListElement > & edge_list_element_pool ()
 Used by class DirectedNode only, this is the pool from which edge lists are to allocate their edge lists elements from. More...
 

Private Attributes

platform::Size num_nodes_
 
DirectedNodeVector nodes_
 
platform::Size num_edges_
 
boost::unordered_object_pool< DirectedEdgeListElement > * edge_list_element_pool_
 the pool from which edge lists are to allocate their edge list elements More...
 
DirectedEdgeList edge_list_
 
boost::unordered_object_pool< DirectedEdge > * edge_pool_
 the pool from which class Digraph allocates DirectedEdge objects. Not used by derived classes More...
 
DirectedEdgefocused_edge_
 Quick-access to a frequently needed edge – the most recently sought edge in a call to find_edge() or the most recently added edge. More...
 

Friends

class DirectedNode
 
class DirectedEdge
 

Detailed Description

A Digraph with constant time edge insertion and deletion. Extensible.

Member Typedef Documentation

◆ DirectedEdgeListConstIter

◆ DirectedEdgeListIter

◆ DirectedNodeVector

◆ parent

Constructor & Destructor Documentation

◆ ~Digraph()

utility::graph::Digraph::~Digraph ( )
override

virtual destructor. Derived classes must ensure they've destroyed all their nodes and edges through a call to "destroy_everything" before this function is arrived at

destructor

References delete_everything(), edge_list_element_pool_, and edge_pool_.

◆ Digraph() [1/3]

utility::graph::Digraph::Digraph ( )

ctor

default constructor; creates an empty graph (no nodes, no edges)

Referenced by count_static_memory().

◆ Digraph() [2/3]

utility::graph::Digraph::Digraph ( platform::Size  num_nodes)

num nodes ctor

Do not call this constructor from a derived class in the initialization list, since this constructor calls the polymorphic function create_new_node, and polymorphism does not work during constructors or destructors.

Parameters
num_ig_nodes- [in] - number of nodes that this graph will contain

References create_new_node(), create_a3b_hbs::ii, nodes_, and num_nodes().

◆ Digraph() [3/3]

utility::graph::Digraph::Digraph ( Digraph const &  source)

copy ctor. Must not be called by derived class copy ctors.

copy constructor relies on factory methods and virtual "copy_from" methods

This copy constructor should NOT be used by derived classes. At the time this is called, the identity of this has not yet been resolved – this constructor will produce DirectedNode and DirectedEdge objects when it calls "create_new_node" and not DerivedDirectedNode or DerivedDirectedEdge objects. Derived class copy constructors should call the base class assignment operator once the initial construction has been completed.

References add_edge(), const_edge_list_begin(), const_edge_list_end(), utility::graph::DirectedEdge::copy_from(), create_new_node(), find_edge(), create_a3b_hbs::ii, nodes_, and num_nodes_.

Member Function Documentation

◆ add_edge() [1/2]

DirectedEdge * utility::graph::Digraph::add_edge ( DirectedEdge const *  example_edge)

add an edge to this graph copying the data from an edge in another graph. Returns a pointer to the edge after its been added, allowing the calling function to immediately set data for this edge.

for use in Digraph operator=

Uses the edge copy constructor so that data stored on edges of one graph may be placed rapidly into the new edge of this graph.

References utility::graph::DirectedEdgeList::begin(), create_new_edge(), debug_assert, edge_list_, focused_edge_, get_edge_exists(), utility::graph::DirectedEdge::get_head_node_ind(), utility::graph::DirectedEdge::get_tail_node_ind(), num_edges_, utility::graph::DirectedEdgeList::push_front(), and utility::graph::DirectedEdge::set_pos_in_owners_list().

◆ add_edge() [2/2]

DirectedEdge * utility::graph::Digraph::add_edge ( platform::Size  tail_index,
platform::Size  head_index 
)

add a directed edge between two vertices. Invokes "create_edge" from the derived class. Returns a pointer to the edge after its been added, allowing the calling function to immediately set data for this edge.

creates a new edge between nodes tail_index and head_index. DirectedNodes do not have to be listed in order. For speed, does NOT check to see if edge already exists – except in debug mode.

uses factory method create_new_edge and adds the created edge to the graph's edge list. Not threadsafe. Only a single thread should add edges to the graph at a time.

Parameters
tail_index- [in] - index of one of the two nodes the edge is to connect
head_index- [in] - index of the second of the two nodes the edge is to connect

References create_new_edge(), debug_assert, edge_list_, focused_edge_, get_edge_exists(), utility::graph::DirectedEdgeList::last(), num_edges_, utility::graph::DirectedEdgeList::push_back(), and utility::graph::DirectedEdge::set_pos_in_owners_list().

Referenced by copy_connectivity(), Digraph(), and operator=().

◆ add_node()

void utility::graph::Digraph::add_node ( )

Add a new node to the graph; preserve all of the existing edges in the graph.

References create_new_node(), nodes_, and num_nodes_.

◆ const_edge_list_begin()

DirectedEdgeListConstIter utility::graph::Digraph::const_edge_list_begin ( ) const
inline

returns a const iterator to the beginning of the (unordered) edge list for the graph. this edge list contains all the edges in the graph, not simply those for a particular vertex

References utility::graph::DirectedEdgeList::const_begin(), and edge_list_.

Referenced by copy_connectivity(), Digraph(), and operator=().

◆ const_edge_list_end()

DirectedEdgeListConstIter utility::graph::Digraph::const_edge_list_end ( ) const
inline

returns a const iterator to the end of the (unordered) edge list for the graph. this edge list contains all the edges in the graph, not simply those for a particular vertex

References utility::graph::DirectedEdgeList::const_end(), and edge_list_.

Referenced by copy_connectivity(), Digraph(), and operator=().

◆ copy_connectivity()

void utility::graph::Digraph::copy_connectivity ( Digraph const &  source)

copy the edge connectivity from a source graph with a potentially unknown type.

copy the connectivity of the source graph, but do not copy the data stored in the nodes and edges of the source graph. Useful for when copying a graph of a different type (e.g. from an EnergyDigraph into a Digraph)

References add_edge(), const_edge_list_begin(), const_edge_list_end(), drop_all_edges(), num_nodes_, and set_num_nodes().

◆ count_dynamic_memory()

platform::Size utility::graph::Digraph::count_dynamic_memory ( ) const
protectedvirtual

References num_edges_, and num_nodes_.

Referenced by getTotalMemoryUsage().

◆ count_static_memory()

platform::Size utility::graph::Digraph::count_static_memory ( ) const
protectedvirtual

References Digraph().

Referenced by getTotalMemoryUsage().

◆ create_new_edge() [1/2]

DirectedEdge * utility::graph::Digraph::create_new_edge ( DirectedEdge const *  example_edge)
protectedvirtual

factory method for edge copy-construction. Derived class should downcast the example_edge pointer and may read that edge's data.

References edge_pool_, utility::graph::DirectedEdge::get_head_node_ind(), and utility::graph::DirectedEdge::get_tail_node_ind().

◆ create_new_edge() [2/2]

DirectedEdge * utility::graph::Digraph::create_new_edge ( platform::Size  index1,
platform::Size  index2 
)
protectedvirtual

factory method for edge creation, defined by derived graph classes, called by the base class

factory method for edge creation Should be overriden in derived classes

References edge_pool_.

Referenced by add_edge().

◆ create_new_node()

DirectedNode * utility::graph::Digraph::create_new_node ( platform::Size  node_index)
protectedvirtual

factory method for node creation, defined by derived graph classes, called by the base class

factory method for node creation Should be overriden in derived classes

References DirectedNode, and ObjexxFCL::index().

Referenced by add_node(), Digraph(), and set_num_nodes().

◆ delete_edge()

void utility::graph::Digraph::delete_edge ( DirectedEdge edge)
virtual

remove an edge from the graph. (NEW AS OF 12/9/07) Never call C++'s "delete" function on an edge pointer directly. Derived classes must implement this function. If they wish to use unordered_object_pools to manage their memory

References edge_pool_.

Referenced by delete_everything(), utility::graph::DirectedNode::drop_all_edges(), and drop_all_edges().

◆ delete_everything()

void utility::graph::Digraph::delete_everything ( )
protected

deallocate all nodes and edges from the graph

deletes each edge in the graph and then deletes each node

its important to note that nodes must outlive their incident edges

References utility::graph::DirectedEdgeList::begin(), delete_edge(), edge_list_, utility::graph::DirectedEdgeList::end(), focused_edge_, create_a3b_hbs::ii, nodes_, and num_nodes_.

Referenced by set_num_nodes(), and ~Digraph().

◆ drop_all_edges()

void utility::graph::Digraph::drop_all_edges ( )

delete all the edges present in the graph

deletes all edges in the graph

References utility::graph::DirectedEdgeList::begin(), delete_edge(), edge_list_, and utility::graph::DirectedEdgeList::end().

Referenced by copy_connectivity(), and operator=().

◆ drop_all_edges_for_node()

void utility::graph::Digraph::drop_all_edges_for_node ( platform::Size  node)

delete all the edges for a single vertex in the graph

deletes all edges adjacent to the node specified

Parameters
node- [in] - index of the node

References utility::graph::DirectedNode::drop_all_edges(), and get_node().

◆ drop_edge()

void utility::graph::Digraph::drop_edge ( DirectedEdgeListIter  iter)
protected

remove an edge from the entire-graph edge list. Called only by class DirectedEdge during its destructor

removes edge from edge list at iterator iter

each edge keeps track of its position in its owner's graph's edge list so it can efficiently delete itself should it need to.

Parameters
iter- [in] - the iterator in the non-const edge list pointing at the edge that's deleting itself
citer- [in] - the iterator in the const edge list pointing at the edge that's deleting itself

References edge_list_, utility::graph::DirectedEdgeList::erase(), focused_edge_, and num_edges_.

Referenced by utility::graph::DirectedEdge::~DirectedEdge().

◆ edge_list_begin()

DirectedEdgeListIter utility::graph::Digraph::edge_list_begin ( )
inline

returns a non-const iterator to the beginning of the (unordered) edge list for the graph. this edge list contains all the edges in the graph, not simply those for a particular vertex

References utility::graph::DirectedEdgeList::begin(), and edge_list_.

◆ edge_list_element_pool()

boost::unordered_object_pool< DirectedEdgeListElement >& utility::graph::Digraph::edge_list_element_pool ( )
inlineprotected

Used by class DirectedNode only, this is the pool from which edge lists are to allocate their edge lists elements from.

References edge_list_element_pool_.

◆ edge_list_end()

DirectedEdgeListIter utility::graph::Digraph::edge_list_end ( )
inline

returns a non-const iterator to the end of the (unordered) edge list for the graph. this edge list contains all the edges in the graph, not simply those for a particular vertex

References edge_list_, and utility::graph::DirectedEdgeList::end().

◆ find_edge() [1/2]

DirectedEdge * utility::graph::Digraph::find_edge ( platform::Size  tail_node,
platform::Size  head_node 
)

returns a pointer to the directed edge connecting nodes tail_node and head_node, if that edge exists in the graph, o.w. returns 0. Focuses the graph on this edge for fast subsequent retrieval.

returns the edge connecting tail_node and head_node

graph keeps a pointer to the last edge that was accessed to that search is fairly efficient.

Parameters
tail_node- [in] - index of the first node
head_node- [in] - index of the second node

References focused_edge_, nodes_, and utility::graph::DirectedEdge::same_edge().

Referenced by Digraph(), and get_edge_exists().

◆ find_edge() [2/2]

DirectedEdge const * utility::graph::Digraph::find_edge ( platform::Size  tail_node,
platform::Size  head_node 
) const

returns a const pointer to the directed edge connecting nodes tail_node and head_node, if that edge exists in the graph, o.w. returns 0. Focuses the graph on this edge for fast subsequent retrieval.

returns the edge connecting tail_node and head_node (const version)

graph keeps a pointer to the last edge that was accessed to that search is fairly efficient.

Parameters
tail_node- [in] - index of the tail node
head_node- [in] - index of the head node

References focused_edge_, nodes_, and utility::graph::DirectedEdge::same_edge().

◆ focused_edge() [1/2]

DirectedEdge* utility::graph::Digraph::focused_edge ( )
inline

returns a pointer to the focused edge

References focused_edge_.

◆ focused_edge() [2/2]

DirectedEdge const* utility::graph::Digraph::focused_edge ( ) const
inline

returns a const-pointer to the focused edge

References focused_edge_.

◆ get_edge_exists()

bool utility::graph::Digraph::get_edge_exists ( platform::Size  tail_node,
platform::Size  head_node 
) const

is an edge already present in the graph? O(V) worst case. O(1) iff all vertices have O(1) edges

returns true if an edge between tail_node and head_node exists

Parameters
tail_node- [in] - index of the one of the nodes
head_node- [in] - index of the other node

References find_edge().

Referenced by add_edge().

◆ get_node() [1/2]

DirectedNode* utility::graph::Digraph::get_node ( platform::Size  index)
inline

References debug_assert, nodes_, and num_nodes_.

◆ get_node() [2/2]

DirectedNode const* utility::graph::Digraph::get_node ( platform::Size  index) const
inline

References debug_assert, nodes_, and num_nodes_.

Referenced by drop_all_edges_for_node().

◆ get_self_ptr() [1/2]

DigraphOP utility::graph::Digraph::get_self_ptr ( )
inline

◆ get_self_ptr() [2/2]

DigraphCOP utility::graph::Digraph::get_self_ptr ( ) const
inline

self pointers

◆ getTotalMemoryUsage()

platform::Size utility::graph::Digraph::getTotalMemoryUsage ( ) const

returns a count of all the memory used by every vertex and edge in a graph by invoking the polymorphic count_static_memory and count_dynamic_memory of each (possibly derived) node and edge object as well as for the (possibly derived) graph class.

References utility::graph::DirectedEdgeList::const_begin(), utility::graph::DirectedEdgeList::const_end(), count_dynamic_memory(), count_static_memory(), edge_list_, create_a3b_hbs::ii, nodes_, and num_nodes().

◆ num_edges()

platform::Size utility::graph::Digraph::num_edges ( ) const
inline

References num_edges_.

Referenced by output_dimacs().

◆ num_nodes()

platform::Size utility::graph::Digraph::num_nodes ( ) const
inline

the number of nodes in the graph

References num_nodes_.

Referenced by Digraph(), getTotalMemoryUsage(), and set_num_nodes().

◆ operator=()

Digraph & utility::graph::Digraph::operator= ( Digraph const &  source)

assignment operator. source and this must have the same type.

operator = (). Relies on factory methods and virtual "copy_from" methods

operator= must only be performed on graphs of the same type e.g. an EnergyDigraph may be copied from another EnergyDigraph, but should not be copied from a Digraph.

References add_edge(), const_edge_list_begin(), const_edge_list_end(), drop_all_edges(), create_a3b_hbs::ii, nodes_, num_nodes_, and set_num_nodes().

◆ output_connectivity()

void utility::graph::Digraph::output_connectivity ( std::ostream &  os) const

send an edge list to the stream os.

writes out a list of all the edges in the graph

Parameters
os- [in] - the output stream to write to

References utility::graph::DirectedEdgeList::begin(), demo.D060_Folding::counter, edge_list_, and utility::graph::DirectedEdgeList::end().

◆ output_dimacs()

void utility::graph::Digraph::output_dimacs ( std::ostream &  os) const

describe this graph in dimacs form to the stream os.

writes out a connectivity description of the graph in the famous dimacs format. (where the first column "DIMACS:" should be sed'ed out)

Parameters
os- [in] - the output stream to write to

References utility::graph::DirectedEdgeList::begin(), edge_list_, utility::graph::DirectedEdgeList::end(), num_edges(), num_nodes_, and utility::graph::DirectedEdgeList::size().

◆ print_vertices()

void utility::graph::Digraph::print_vertices ( ) const

send summary information to the screen for all vertices in the graph

calls print() on each of the nodes in the graph

References create_a3b_hbs::ii, nodes_, and num_nodes_.

◆ set_num_nodes()

void utility::graph::Digraph::set_num_nodes ( platform::Size  num_nodes)

set the number of nodes in the graph – deletes any existing edges in the graph

alternative to integer constructor; first create an empty graph and later tell the graph how many nodes it has. If the graph is not already empty, it will delete everything its holding.

References create_new_node(), delete_everything(), create_a3b_hbs::ii, nodes_, num_nodes(), and num_nodes_.

Referenced by copy_connectivity(), and operator=().

Friends And Related Function Documentation

◆ DirectedEdge

friend class DirectedEdge
friend

◆ DirectedNode

friend class DirectedNode
friend

Referenced by create_new_node().

Member Data Documentation

◆ edge_list_

DirectedEdgeList utility::graph::Digraph::edge_list_
private

◆ edge_list_element_pool_

boost::unordered_object_pool< DirectedEdgeListElement >* utility::graph::Digraph::edge_list_element_pool_
private

the pool from which edge lists are to allocate their edge list elements

Referenced by edge_list_element_pool(), and ~Digraph().

◆ edge_pool_

boost::unordered_object_pool< DirectedEdge >* utility::graph::Digraph::edge_pool_
private

the pool from which class Digraph allocates DirectedEdge objects. Not used by derived classes

Referenced by create_new_edge(), delete_edge(), and ~Digraph().

◆ focused_edge_

DirectedEdge* utility::graph::Digraph::focused_edge_
mutableprivate

Quick-access to a frequently needed edge – the most recently sought edge in a call to find_edge() or the most recently added edge.

Referenced by add_edge(), delete_everything(), drop_edge(), find_edge(), and focused_edge().

◆ nodes_

DirectedNodeVector utility::graph::Digraph::nodes_
private

◆ num_edges_

platform::Size utility::graph::Digraph::num_edges_
private

◆ num_nodes_

platform::Size utility::graph::Digraph::num_nodes_
private

The documentation for this class was generated from the following files: