Bridges-C++  3.4.4
Bridges(C++ API)
Public Member Functions | List of all members
bridges::datastructure::GraphAdjMatrix< K, E1, E2 > Class Template Reference

#include <GraphAdjMatrix.h>

Inheritance diagram for bridges::datastructure::GraphAdjMatrix< K, E1, E2 >:
bridges::datastructure::DataStructure

Detailed Description

template<typename K, typename E1 = K, typename E2 = E1>
class bridges::datastructure::GraphAdjMatrix< K, E1, E2 >

This class provides methods to represent adjacency matrix based graphs.

The class is simply a wrapper around the C++ STL unordered_map class and thus derives all its operations from it. Given the use of operator overloading, the adjacency matrix implementation is almost identical to a normal array representation, except that any ordered type can be used to index into the matrix.

Since the adjacency matrix typically contains only a numerical value, we keep edge specific information in a separate map using a generic parameter for the type.

Generic Parameters: K that is used as an index, E1 information specific to graph vertices E2 information specific to graph edges

Author
Kalpathi Subramanian, Dakota Carmer
Date
6/29/15, 7/10/16, 11/27/16, 4/22/18

There is a tutorial about Graph Adjacency Matrix : https://bridgesuncc.github.io/tutorials/Graph_AM.html

Public Member Functions

virtual const string getDStype () const override
 
virtual ~GraphAdjMatrix ()
 
 GraphAdjMatrix ()=default
 
 GraphAdjMatrix (const GraphAdjMatrix &)=delete
 
GraphAdjMatrixoperator= (const GraphAdjMatrix &)=delete
 
void addVertex (const K &k, const E1 &e=E1())
 
void addEdge (const K &src, const K &dest, const unsigned int &wt)
 
const unordered_map< K, unordered_map< K, int > > & getMatrix () const
 
const unordered_map< K, int > & getMatrix (K key) const
 
unordered_map< K, Element< E1 > * > * getVertices ()
 
const Element< E1 > * getVertex (const K &key) const
 
Element< E1 > * getVertex (const K &key)
 
E1 getVertexData (const K &src)
 
void setVertexData (const K &vID, const E1 &data)
 
E2 const & getEdgeData (const K &src, const K &dest) const
 
void setEdgeData (const K &src, const K &dest, const E2 &data)
 Loads edge information. More...
 
ElementVisualizergetVisualizer (const K &k)
 
LinkVisualizergetLinkVisualizer (const K &k1, const K &k2)
 
- Public Member Functions inherited from bridges::datastructure::DataStructure
virtual ~DataStructure ()=default
 

Constructor & Destructor Documentation

◆ ~GraphAdjMatrix()

template<typename K , typename E1 = K, typename E2 = E1>
virtual bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::~GraphAdjMatrix ( )
inlinevirtual

◆ GraphAdjMatrix() [1/2]

template<typename K , typename E1 = K, typename E2 = E1>
bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::GraphAdjMatrix ( )
default

◆ GraphAdjMatrix() [2/2]

template<typename K , typename E1 = K, typename E2 = E1>
bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::GraphAdjMatrix ( const GraphAdjMatrix< K, E1, E2 > &  )
delete

Member Function Documentation

◆ addEdge()

template<typename K , typename E1 = K, typename E2 = E1>
void bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::addEdge ( const K &  src,
const K &  dest,
const unsigned int &  wt 
)
inline

Sets the weight of the edge from "src" to "dest", to "wt". This will overwrite the existing edge weight.

Parameters
srcThe key of the source Vertex
destThe key of the destination Vertex
wtThe weight of the edge
Exceptions
out_of_rangeIf "src" or "dest" is non-existent within this graph

◆ addVertex()

template<typename K , typename E1 = K, typename E2 = E1>
void bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::addVertex ( const K &  k,
const E1 &  e = E1() 
)
inline

Adds a vertex of key "k" and value "e" to the graph. Sets all of its edges to be of weight 0.

Parameters
kVertex key
eVertex data

◆ getDStype()

template<typename K , typename E1 = K, typename E2 = E1>
virtual const string bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::getDStype ( ) const
inlineoverridevirtual
Returns
The string representation of this data structure type

Implements bridges::datastructure::DataStructure.

◆ getEdgeData()

template<typename K , typename E1 = K, typename E2 = E1>
E2 const& bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::getEdgeData ( const K &  src,
const K &  dest 
) const
inline
Gets edge data for the edge from "src" to "dest"
Parameters
srcThe key of the source Vertex
destThe key of the destination Vertex
Returns
edge specific data

◆ getLinkVisualizer()

template<typename K , typename E1 = K, typename E2 = E1>
LinkVisualizer* bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::getLinkVisualizer ( const K &  k1,
const K &  k2 
)
inline

Returns the link visualizer corresponding to two graph nodes with an existing link; error returned if no link exists.

Parameters
k1The key of the link source vertex
k2The key of the link destination vertex
Returns
the visualizer that controls the attributes of this link

◆ getMatrix() [1/2]

template<typename K , typename E1 = K, typename E2 = E1>
const unordered_map<K, unordered_map<K, int> >& bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::getMatrix ( ) const
inline

Return the adjacency matrix

Returns
The matrix of this graphs edges

◆ getMatrix() [2/2]

template<typename K , typename E1 = K, typename E2 = E1>
const unordered_map<K, int>& bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::getMatrix ( key) const
inline

Return the adjacency matrix row at Key key

Parameters
keyThe input key value that identifies the row being retrieved
Returns
The row of this adjacency matrix corresponding to the key

◆ getVertex() [1/2]

template<typename K , typename E1 = K, typename E2 = E1>
Element<E1>* bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::getVertex ( const K &  key)
inline

Return the vertex correspondingto key "key"

Returns
the requested vertex of this graph

◆ getVertex() [2/2]

template<typename K , typename E1 = K, typename E2 = E1>
const Element<E1>* bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::getVertex ( const K &  key) const
inline

Return the vertex correspondingto key "key" - const version

Returns
the requested vertex of this graph

◆ getVertexData()

template<typename K , typename E1 = K, typename E2 = E1>
E1 bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::getVertexData ( const K &  src)
inline

Gets vertex data for a graph vertex

Parameters
srcThe key of the source vertex
Returns
E vertex specific data

◆ getVertices()

template<typename K , typename E1 = K, typename E2 = E1>
unordered_map<K, Element<E1> *>* bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::getVertices ( )
inline

Return the graph vertices

Returns
The graph verticies

◆ getVisualizer()

template<typename K , typename E1 = K, typename E2 = E1>
ElementVisualizer* bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::getVisualizer ( const K &  k)
inline

Returns the visualizer corresponding to a graph vertex; convenient method to set attributes of the graph vertex

Parameters
kThe key of the graph vertex
Returns
the visualizer that controls the attributes of this node

◆ operator=()

template<typename K , typename E1 = K, typename E2 = E1>
GraphAdjMatrix& bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::operator= ( const GraphAdjMatrix< K, E1, E2 > &  )
delete

◆ setEdgeData()

template<typename K , typename E1 = K, typename E2 = E1>
void bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::setEdgeData ( const K &  src,
const K &  dest,
const E2 &  data 
)
inline

Loads edge information.

Parameters
srcThe key of the source Vertex
destThe key of the destination Vertex
datadata to associate with the edge

◆ setVertexData()

template<typename K , typename E1 = K, typename E2 = E1>
void bridges::datastructure::GraphAdjMatrix< K, E1, E2 >::setVertexData ( const K &  vID,
const E1 &  data 
)
inline
Loads vertex specific information for a graph vertex
Parameters
vIDvertex key
datadata to associate with the vertex

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