CXXGraph  0.0.6
CXXGraph is a small library, header only, that manages the Graph and it's algorithm in C++
Public Types | Public Member Functions | Friends | List of all members
CXXGRAPH::Graph< T > Class Template Reference

Public Types

enum  E_OutputFormat { STANDARD , OUT_1 , OUT_2 }
 
typedef enum CXXGRAPH::Graph::E_OutputFormat OutputFormat
 

Public Member Functions

 Graph (const std::set< const Edge< T > * > &edgeSet)
 
const std::set< const Edge< T > * > & getEdgeSet () const
 
void setEdgeSet (std::set< const Edge< T > * > &edgeSet)
 
void addEdge (const Edge< T > &edge)
 
void removeEdge (unsigned long edgeId)
 
const std::set< const Node< T > * > getNodeSet () const
 
const std::optional< const Edge< T > * > getEdge (unsigned long edgeId) const
 
const AdjacencyMatrix< T > getAdjMatrix () const
 
const DijkstraResult dijkstra (const Node< T > &source, const Node< T > &target) const
 Function runs the dijkstra algorithm for some source node and target node in the graph and returns the shortest distance of target from the source. More...
 
const std::vector< Node< T > > breadth_first_search (const Node< T > &start) const
 Function performs the breadth first search algorithm over the graph. More...
 
const std::vector< Node< T > > depth_first_search (const Node< T > &start) const
 Function performs the depth first search algorithm over the graph. More...
 
const bool isCyclicDirectedGraphDFS () const
 This function uses DFS to check for cycle in the graph. Pay Attention, this function work only with directed Graph. More...
 
const bool isCyclicDirectedGraphBFS () const
 This function uses BFS to check for cycle in the graph. Pay Attention, this function work only with directed Graph. More...
 
const bool isDirectedGraph () const
 This function checks if a graph is directed. More...
 
int writeToFile (OutputFormat format=OutputFormat::STANDARD, std::string OFileName="graph.csv", bool compress=false, bool writeNodeFeat=false, bool writeEdgeWeight=false) const
 This function write the graph in an output file. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const Graph< T > &graph)
 
std::ostream & operator<< (std::ostream &os, const AdjacencyMatrix< T > &adj)
 

Member Function Documentation

◆ breadth_first_search()

template<typename T >
const std::vector< Node< T > > CXXGRAPH::Graph< T >::breadth_first_search ( const Node< T > &  start) const

Function performs the breadth first search algorithm over the graph.

Parameters
startNode from where traversing starts
Returns
a vector of Node indicating which Node were visited during the search.

◆ depth_first_search()

template<typename T >
const std::vector< Node< T > > CXXGRAPH::Graph< T >::depth_first_search ( const Node< T > &  start) const

Function performs the depth first search algorithm over the graph.

Parameters
startNode from where traversing starts
Returns
a vector of Node indicating which Node were visited during the search.

◆ dijkstra()

template<typename T >
const DijkstraResult CXXGRAPH::Graph< T >::dijkstra ( const Node< T > &  source,
const Node< T > &  target 
) const

Function runs the dijkstra algorithm for some source node and target node in the graph and returns the shortest distance of target from the source.

Parameters
sourcesource vertex
targettarget vertex
Returns
shortest distance if target is reachable from source else ERROR in case if target is not reachable from source or there is error in the computation.

◆ isCyclicDirectedGraphBFS()

template<typename T >
const bool CXXGRAPH::Graph< T >::isCyclicDirectedGraphBFS

This function uses BFS to check for cycle in the graph. Pay Attention, this function work only with directed Graph.

Returns
true if a cycle is detected, else false. ( false is returned also if the graph in indirected)

◆ isCyclicDirectedGraphDFS()

template<typename T >
const bool CXXGRAPH::Graph< T >::isCyclicDirectedGraphDFS

This function uses DFS to check for cycle in the graph. Pay Attention, this function work only with directed Graph.

Returns
true if a cycle is detected, else false. ( false is returned also if the graph in indirected)

◆ isDirectedGraph()

template<typename T >
const bool CXXGRAPH::Graph< T >::isDirectedGraph

This function checks if a graph is directed.

Returns
true if the graph is directed, else false.

◆ writeToFile()

template<typename T >
int CXXGRAPH::Graph< T >::writeToFile ( OutputFormat  format = OutputFormat::STANDARD,
std::string  OFileName = "graph.csv",
bool  compress = false,
bool  writeNodeFeat = false,
bool  writeEdgeWeight = false 
) const

This function write the graph in an output file.

Parameters
formatThe Output format of the file
OFileNameThe Output File Name ( )
compressIndicates if the output will be compressed
writeNodeFeatIndicates if export also Node Features
writeEdgeWeightIndicates if export also Edge Weights
Returns
0 if all OK, else return a negative value

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