|
GraphLibrary
0.0.1
A simple library that implements various graph algorithms.
|
Stores and implements a Graph. More...
#include <Graph.hpp>
Classes | |
| class | Edge_Iterator |
| Edge_Iterator class. Used to iterate over all Edges in the Graph More... | |
Public Types | |
| using | val_t = SCALAR |
| Value type. More... | |
| using | idx_t = gl::index_type |
| Index type. More... | |
| using | Edge = gl::Edge< val_t > |
| Edge type. More... | |
| using | Node = gl::Node< val_t > |
| Node type. More... | |
| using | dest_vec_t = std::vector< std::pair< idx_t, val_t >> |
| Destination-Vector type. More... | |
| using | idx_list_t = std::vector< idx_t > |
| Index List type. More... | |
| using | ordered_list_t = std::list< idx_t > |
| Ordered List type. More... | |
| using | visit_list_t = std::vector< bool > |
| Visited-List type. More... | |
| template<class info_t > | |
| using | BFS_queue_t = std::deque< info_t > |
| BFS type. More... | |
| using | DFS_queue_t = std::stack< idx_t > |
| DFS type. More... | |
| using | matrix_t = std::vector< Edge > |
| Matrix Representation type. More... | |
| using | nodeList_t = std::list< Edge > |
| ListNode Representation type. More... | |
| using | rootList_t = std::vector< nodeList_t > |
| ListRoot Representation type. More... | |
| using | EdgeIterator = Edge_Iterator< false > |
| Edge iterator type. More... | |
| using | ConstEdgeIterator = Edge_Iterator< true > |
| Edge const_iterator type. More... | |
| using | NodeIterator = typename std::vector< Node >::iterator |
| Node iterator type. More... | |
| using | ConstNodeIterator = typename std::vector< Node >::const_iterator |
| Node const_iterator type. More... | |
Public Member Functions | |
| bool | operator== (const Graph< SCALAR, gl::Matrix, DIRECTION > &rhs) |
| bool | operator!= (const Graph< SCALAR, STORAGE_KIND, DIRECTION > &rhs) |
Construction | |
Various functions to create/destroy a Graph. | |
| Graph (const idx_t &numNodes=0, const std::string &label="Graph") | |
| Construct Graph from node count and label. More... | |
| Graph (const std::string °reeSeq, const std::string &label="Simple Undirected Graph") | |
| Construct Graph from node count and label. More... | |
| Graph (const Property &property) | |
| Construct Graph from property. More... | |
| ~Graph () | |
| gl::Graph< SCALAR, gl::Matrix, DIRECTION > | toMatrix () const |
| Outputs a graph in Adjacency Matrix storage format with the same edges as this. This function only exists for ListGraphs. More... | |
| gl::Graph< SCALAR, gl::List, DIRECTION > | toList () const |
| Outputs a graph in Adjacency List storage format with the same edges as this. This function only exists for MatrixGraphs. More... | |
Property interface | |
Provides access to the properties of the Graph. | |
| std::string | getGraphLabel () const |
| Returns the label of the graph. More... | |
| void | setGraphLabel (const std::string &label) |
| Changes the label of the graph. More... | |
| idx_t | numNodes () const |
| Returns the number of nodes currently in the graph. More... | |
| idx_t | numEdges () const |
| Returns the number of edges currently in the graph. More... | |
| bool | isDirected () const |
| Returns true if the graph is directed, false if not. More... | |
| bool | isUndirected () const |
| Returns true if the graph is undirected, false if not. More... | |
| bool | hasCycle () const |
| Checks whether the given undirected graph containes cycles using an iterative BFS approach. More... | |
Edge interface | |
Provides access to the properties of the edges in a Graph. | |
| void | setEdge (const idx_t &start, const idx_t &end, const val_t &weight=1, const Color &color=Color()) |
| Sets an edge including start/end points and weight. More... | |
| void | setEdge (const Edge &edge) |
| Adds an edge directly from an Edge object. More... | |
| void | setEdgesFromListFile (const std::string &inFile) |
| Adds edges found in inFile to the graph. More... | |
| void | setEdgesFromMatrixFile (const std::string &inFile) |
| Adds edges found in inFile to the graph. More... | |
| void | updateEdge (const idx_t &start, const idx_t &end, const val_t &weight, const gl::Color &color) |
| Updates edge properties. Parameters "start" & "end" mandatory, the rest optional. More... | |
| void | delEdge (const idx_t &start, const idx_t &end) |
| Deletes the edge going from start to end. More... | |
| bool | hasEdge (const idx_t &start, const idx_t &end) const |
| Checks whether an edge exists from start to end. More... | |
| val_t | getEdgeWeight (const idx_t &start, const idx_t &end) const |
| Finds the weight of the edge going from start to end. More... | |
| Color | getEdgeColor (const idx_t &src, const idx_t &dest) const |
| Returns the color of the edge from src to dest. More... | |
| EdgeIterator | edge_begin () |
| EdgeIterator to the first edge. More... | |
| EdgeIterator | edge_end () |
| EdgeIterator to behind the last edge. More... | |
| ConstEdgeIterator | edge_cbegin () const |
| ConstEdgeIterator to the first edge. More... | |
| ConstEdgeIterator | edge_cend () const |
| ConstEdgeIterator to the last edge. More... | |
Node interface | |
Provides access to the properties of the nodes in the Graph. | |
| idx_list_t | getNeighbours (const idx_t &node) const |
| Returns a list of all endpoints of outgoing edges from start. More... | |
| idx_list_t | getUnvisitedNeighbours (const idx_t &node, const std::vector< bool > &visited) const |
| Returns a list of endpoints + edge weights of outgoing edges from start. More... | |
| dest_vec_t | getNeighbourWeights (const idx_t &node) const |
| Returns a list of endpoints + edge weights of outgoing edges from start. More... | |
| dest_vec_t | getUnvisitedNeighbourWeights (const idx_t &node, const visit_list_t &visited) const |
| Returns a list of endpoints + edge weights of unvisited outgoing edges from start. More... | |
| void | updateNode (const idx_t &id, const std::string &label, const val_t &capacity, const gl::Color &color, const std::pair< float, float > &position) |
| Updates node properties. Parameter "id" mandatory, the rest optional. More... | |
| std::string | getNodeLabel (const idx_t &id) const |
| Finds the label of the given node. More... | |
| val_t | getNodeCapacity (const idx_t &id) const |
| Finds the flow capacity of the given node. More... | |
| std::pair< float, float > | getNodePosition (const idx_t &id) const |
| Finds the position of the given node. More... | |
| idx_t | getNodeDegree (const idx_t &id) const |
| Finds the degree of the given node (i.e. count of all in- & outgoing edges). More... | |
| idx_t | getNodeInDegree (const idx_t &id) const |
| Gets the in-degree of a node (i.e. count of all incoming edges). More... | |
| idx_t | getNodeOutDegree (const idx_t &id) const |
| Gets the in-degree of a node (i.e. count of all outgoing edges). More... | |
| Color | getNodeColor (const idx_t &id) const |
| Returns the color of a node. More... | |
| void | readPositionsFromFile (const std::string &inFile) |
| Updates node positions in the format "<id> <x-coord> <y-coord>" found in inFile. More... | |
| NodeIterator | node_begin () |
| NodeIterator to the first node. More... | |
| NodeIterator | node_end () |
| NodeIterator to behind the last node. More... | |
| ConstNodeIterator | node_cbegin () const |
| ConstNodeIterator to the first node. More... | |
| ConstNodeIterator | node_cend () const |
| ConstNodeIterator to behind the last node. More... | |
checkRange | |
Asserts that the given index/indecies is within the graph. | |
| void | checkRange (const idx_t &idx1) const |
| Only one index that gets range checked. More... | |
| void | checkRange (const idx_t &idx1, const idx_t &idx2) const |
| Two indices ("edge") that get range checked. More... | |
Protected Attributes | |
| Property | property_ |
| Stores various properties of the Graph. More... | |
| std::vector< Node > | nodes_ |
| Stores information about all nodes in the Graph. More... | |
| std::conditional_t < std::is_same_v< STORAGE_KIND, Matrix >, matrix_t, rootList_t > | edges_ |
| Stores information about all edges in the Graph. More... | |
Private Member Functions | |
| void | construct () |
| Auxiliary function. Creates an empty Graph using the deduced storage format. More... | |
Stores and implements a Graph.
This class has functions to create and edit the graph, as well as access certain properties of the graph.
| SCALAR | Number type used to store edge weights. |
| STORAGE_KIND | Class type used to signify that a matrix shall be stored in either Adjacency Matrix or Adjacency List format. Accepted Values: gl::Matrix, gl::List |
| DIRECTION | Class type used to signify that the graph is either directed or undirected. Accepted Values: gl::Directed, gl::Undirected |
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::val_t = SCALAR |
Value type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::idx_t = gl::index_type |
Index type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::Edge = gl::Edge<val_t> |
Edge type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::Node = gl::Node<val_t> |
Node type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::dest_vec_t = std::vector<std::pair<idx_t, val_t>> |
Destination-Vector type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::idx_list_t = std::vector<idx_t> |
Index List type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::ordered_list_t = std::list<idx_t> |
Ordered List type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::visit_list_t = std::vector<bool> |
Visited-List type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::BFS_queue_t = std::deque<info_t> |
BFS type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::DFS_queue_t = std::stack<idx_t> |
DFS type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::matrix_t = std::vector<Edge> |
Matrix Representation type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::nodeList_t = std::list<Edge> |
ListNode Representation type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::rootList_t = std::vector<nodeList_t> |
ListRoot Representation type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::EdgeIterator = Edge_Iterator<false> |
Edge iterator type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::ConstEdgeIterator = Edge_Iterator<true> |
Edge const_iterator type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::NodeIterator = typename std::vector<Node>::iterator |
Node iterator type.
| using gl::Graph< SCALAR, STORAGE_KIND, DIRECTION >::ConstNodeIterator = typename std::vector<Node>::const_iterator |
Node const_iterator type.
|
inline |
Construct Graph from node count and label.
| [in] | numNodes | Number of nodes/vertices in the graph. |
| [in] | label | Label of the graph. |
|
inline |
Construct Graph from node count and label.
| [in] | degreeSeq | Degree Sequence of an undirected graph (e.g. 5 1 1 1 1 1"). |
| [in] | label | Label of the graph. |
|
inline |
Construct Graph from property.
| [in] | property | Properties for a graph. |
|
inline |
|
inline |
Outputs a graph in Adjacency Matrix storage format with the same edges as this. This function only exists for ListGraphs.
|
inline |
Outputs a graph in Adjacency List storage format with the same edges as this. This function only exists for MatrixGraphs.
|
inline |
Returns the label of the graph.
|
inline |
Changes the label of the graph.
| [in] | label | New label of the graph |
|
inline |
Returns the number of nodes currently in the graph.
|
inline |
Returns the number of edges currently in the graph.
|
inline |
Returns true if the graph is directed, false if not.
|
inline |
Returns true if the graph is undirected, false if not.
|
inline |
Checks whether the given undirected graph containes cycles using an iterative BFS approach.
|
inline |
Sets an edge including start/end points and weight.
| [in] | start | edge origin point |
| [in] | end | edge end point |
| [in] | weight | new edge weight |
| [in] | color | (Optional) new edge color |
|
inline |
Adds edges found in inFile to the graph.
The edges shall be in a line delimited list format, e.g.:
Where the three numbers per line represent the start, end and weight of the new edge. This adds the two edges (1->2 with weight 3) and (7->4 with weight 6.7) to the graph.
| [in] | inFile | file name of input file |
|
inline |
Adds edges found in inFile to the graph.
The edges shall be in a comma delimited adjacency matrix format, e.g.:
This adds the 11 edges (0->0 with weight 1), (0->2 with weight 3) etc. to the graph.
| [in] | inFile | file name of input file |
|
inline |
Deletes the edge going from start to end.
| [in] | start | edge origin point |
| [in] | end | edge end point |
|
inline |
Checks whether an edge exists from start to end.
| [in] | start | edge origin point |
| [in] | end | edge end point |
|
inline |
Finds the weight of the edge going from start to end.
| [in] | start | edge origin point |
| [in] | end | edge end point |
|
inline |
Returns the color of the edge from src to dest.
| [in] | src | edge origin point |
| [in] | dest | edge destination point |
|
inline |
EdgeIterator to the first edge.
|
inline |
EdgeIterator to behind the last edge.
|
inline |
ConstEdgeIterator to the first edge.
|
inline |
ConstEdgeIterator to the last edge.
|
inline |
Returns a list of all endpoints of outgoing edges from start.
| [in] | node | edge origin point |
|
inline |
Returns a list of endpoints + edge weights of outgoing edges from start.
| [in] | node | edge origin point |
| [in] | visited | boolean list of previously visited nodes |
|
inline |
Returns a list of endpoints + edge weights of outgoing edges from start.
| [in] | node | edge origin point |
|
inline |
Returns a list of endpoints + edge weights of unvisited outgoing edges from start.
| [in] | node | edge origin point |
| [in] | visited | boolean list of previously visited nodes |
|
inline |
Updates node properties. Parameter "id" mandatory, the rest optional.
| [in] | id | ID of the node that should be updated. |
| [in] | label | (Optional) New label for the node. |
| [in] | capacity | (Optional) New flow capacity for the node. |
| [in] | color | (Optional) New color for the node. |
| [in] | position | (Optional) New x/y position for the node. |
|
inline |
Finds the label of the given node.
| [in] | id | ID of the node whose label is to be found. |
|
inline |
Finds the flow capacity of the given node.
| [in] | id | node whose flow capacity is to be found |
|
inline |
Finds the position of the given node.
| [in] | id | node whose position is to be found |
|
inline |
Finds the degree of the given node (i.e. count of all in- & outgoing edges).
| [in] | id | node whose degree is to be found |
|
inline |
Gets the in-degree of a node (i.e. count of all incoming edges).
|
inline |
Gets the in-degree of a node (i.e. count of all outgoing edges).
|
inline |
Updates node positions in the format "<id> <x-coord> <y-coord>" found in inFile.
| [in] | inFile | file name of input file |
|
inline |
NodeIterator to the first node.
|
inline |
NodeIterator to behind the last node.
|
inline |
ConstNodeIterator to the first node.
|
inline |
ConstNodeIterator to behind the last node.
|
inline |
Only one index that gets range checked.
| [in] | idx1 | Index that will be range checked |
|
inline |
Two indices ("edge") that get range checked.
| [in] | idx1 | First index that will be range checked |
| [in] | idx2 | Second index that will be range checked. |
|
inline |
|
inline |
|
inlineprivate |
Auxiliary function. Creates an empty Graph using the deduced storage format.
|
protected |
Stores various properties of the Graph.
|
protected |
Stores information about all nodes in the Graph.
|
protected |
Stores information about all edges in the Graph.