GraphTool
 All Classes Files Functions Variables Typedefs
Public Member Functions | List of all members
Graph Class Reference

#include <Graph.h>

Public Member Functions

 Graph (vector< vector< int >> adjacencyMatrix)
 
 Graph (vector< vector< int >> adjacencyMatrix, vector< string > node_names)
 
 Graph (string matlabMatrix)
 
int getNumberOfNodes () const
 
int getNumberOfEdges ()
 
void exportFile (const string fileName, const string data) const
 
void exportAdjazenzmatrixFile (const string fileName) const
 
string graphToJson ()
 
bool hasCycle ()
 
bool hasEdge (const int from, const int to)
 
bool hasPath (const vector< int > path) const
 
const string getAdjacencyMatrixString () const
 
bool isDirected ()
 
int getInDeg (int vertexIndex)
 
int getOutDeg (int vertexIndex)
 
bool isFreeOfLoops ()
 
bool isMultigraph ()
 
bool isSimple ()
 
bool isComplete ()
 
bool isRegular ()
 
bool isForest ()
 
bool hasConnectivity (int s, int t)
 
string exportDot ()
 
bool areNeighbours (int from, int to)
 
string exportDot (vector< int > path)
 

Detailed Description

Represents a simple or directed graph. Has certain verifiable properties. Its edges are not weighted.

Constructor & Destructor Documentation

Graph::Graph ( vector< vector< int >>  adjacencyMatrix)
Graph::Graph ( vector< vector< int >>  adjacencyMatrix,
vector< string >  node_names 
)
Graph::Graph ( string  matlabMatrix)

Constructor for a Graph with a adjacency matrix given in Matlab notation (e.g. [0 0 1; 1 0 0; 1 1 0]).

Parameters
matlabMatrixthe matrix in matlab notation

Member Function Documentation

bool Graph::areNeighbours ( int  from,
int  to 
)

Returns true, if both given vertices are neighbours in the graph. The direction is only considered in digraphs.

Parameters
fromfirst vertice
tosecond vertice
Returns
true, if both vertices are neighbours in the graph
void Graph::exportAdjazenzmatrixFile ( const string  fileName) const

Export the adjazenmatrix to a file.

Parameters
fileNamestring file name.
string Graph::exportDot ( )

Exports the Graph to a dot file.

Returns
The string content for the dot file.
string Graph::exportDot ( vector< int >  path)

Exports the string for a dot file. Takes a path and marks it red in the result dot file.

Parameters
pathThe path to be colored.
Returns
The string for a dot file.
void Graph::exportFile ( const string  fileName,
const string  data 
) const

Export a given file with custom data.

Parameters
fileNamestring file name.
datastring of data.
const string Graph::getAdjacencyMatrixString ( ) const
int Graph::getInDeg ( int  vertexIndex)

Returns indegree indeg(v). Therefore it counts the ingoing edges. In undirected graphs loops are counted twice.

Parameters
vertexIndexthe index of the vertex v
Returns
indegree indeg(v)
int Graph::getNumberOfEdges ( )

Detect the number of edges of the given graph.

Returns
number of edges.
int Graph::getNumberOfNodes ( ) const

Detect the number of nodes of the given graph.

Returns
number of nodes.
int Graph::getOutDeg ( int  vertexIndex)

Returns outdegree outdeg(v). Therefore it counts the outgoing edges. In undirected graphs loops are counted twice.

Parameters
vertexIndexthe index of the vertex v
Returns
outdegree outdeg(v)
string Graph::graphToJson ( )

Return the graph in a json-format.

Returns
string json.

Transform the graph to json-format.

Returns
string json.
bool Graph::hasConnectivity ( int  s,
int  t 
)

Calculates if there is a path from s to t.

Parameters
snumber of node 1
tnumber of node 2
Returns
true, if there is a path from s to t.
bool Graph::hasCycle ( )

Checks the graph if a cycle exists. DFS.

Returns
true if a cycle exists, else false
bool Graph::hasEdge ( const int  from,
const int  to 
)

Checks if the graph contains the given edge.

Parameters
fromnode number
tonode number
Returns
true if the edge exists, else if not
bool Graph::hasPath ( const vector< int >  path) const

Checks, if the graph contains the given path.

Parameters
pathvector with path nodes.
Returns
true if graph contains the path, else false
bool Graph::isComplete ( )

Specifies whether the graph is a complete graph (simple graph "in which every pair of distinct vertices is connected by a unique edge."). Checks only undirected graphs! A complete graph is also called K_n.

Returns
true, if the graph is a complete graph.
bool Graph::isDirected ( )

Returns if the graph is a directed or undirected graph.

Returns
true, if directed
false, if undirected
bool Graph::isForest ( )

Specifies whether the graph is a directed forest ("A forest is a disjoint union of trees." ).

Returns
true, if the graph is a directed forest.
bool Graph::isFreeOfLoops ( )

Specifies whether the graph is free of loops. Loops are edges from and to the same vertex.

Returns
true, if there are no loops in the graph.
bool Graph::isMultigraph ( )

Specifies whether the graph is a multigraph (has multiple edges/has "two or more edged that connect the same two vertices")

Returns
true, if it is a multigraph
bool Graph::isRegular ( )

Specifies whether the graph is a regular graph ("is a graph where each vertex has the same number of neighbors" ).

Returns
true, if the graph is a regular graph.
bool Graph::isSimple ( )

Specifies whether the graph is a simple graph (undirected, no multiple edges, no loops) or not.

Returns
true, if the graph is a simple graph.

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