CXXGraph  0.1.1
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_InputOutputFormat { STANDARD_CSV , STANDARD_TSV , OUT_1 , OUT_2 }
 Specify the Input/Output format of the Graph for Import/Export functions. More...
 
typedef enum CXXGRAPH::Graph::E_InputOutputFormat InputOutputFormat
 Specify the Input/Output format of the Graph for Import/Export functions.
 

Public Member Functions

 Graph (const std::list< const Edge< T > * > &edgeSet)
 
const std::list< const Edge< T > * > & getEdgeSet () const
 
void setEdgeSet (std::list< const Edge< T > * > &edgeSet)
 
void addEdge (const Edge< T > *edge)
 
void removeEdge (unsigned long edgeId)
 
const std::list< 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...
 
bool isCyclicDirectedGraphDFS () const
 This function uses DFS to check for cycle in the graph. Pay Attention, this function work only with directed Graph. More...
 
bool isCyclicDirectedGraphBFS () const
 This function uses BFS to check for cycle in the graph. Pay Attention, this function work only with directed Graph. More...
 
bool isDirectedGraph () const
 This function checks if a graph is directed. More...
 
int writeToFile (InputOutputFormat format=InputOutputFormat::STANDARD_CSV, const std::string &workingDir=".", const std::string &OFileName="graph", bool compress=false, bool writeNodeFeat=false, bool writeEdgeWeight=false) const
 This function write the graph in an output file. More...
 
int readFromFile (InputOutputFormat format=InputOutputFormat::STANDARD_CSV, const std::string &workingDir=".", const std::string &OFileName="graph", bool compress=false, bool readNodeFeat=false, bool readEdgeWeight=false)
 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 Enumeration Documentation

◆ E_InputOutputFormat

template<typename T >
enum CXXGRAPH::Graph::E_InputOutputFormat

Specify the Input/Output format of the Graph for Import/Export functions.

Enumerator
STANDARD_CSV 

A standard csv format.

STANDARD_TSV 

A standard tsv format.

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 >
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 >
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 >
bool CXXGRAPH::Graph< T >::isDirectedGraph

This function checks if a graph is directed.

Returns
true if the graph is directed, else false.

◆ readFromFile()

template<typename T >
int CXXGRAPH::Graph< T >::readFromFile ( InputOutputFormat  format = InputOutputFormat::STANDARD_CSV,
const std::string &  workingDir = ".",
const std::string &  OFileName = "graph",
bool  compress = false,
bool  readNodeFeat = false,
bool  readEdgeWeight = false 
)

This function write the graph in an output file.

Parameters
formatThe Input format of the file
workingDirThe path to the directory in which is placed the Input file
OFileNameThe Input File Name ( )
compressIndicates if the Input is compressed
writeNodeFeatIndicates if import also Node Features
writeEdgeWeightIndicates if import also Edge Weights
Returns
0 if all OK, else return a negative value

◆ writeToFile()

template<typename T >
int CXXGRAPH::Graph< T >::writeToFile ( InputOutputFormat  format = InputOutputFormat::STANDARD_CSV,
const std::string &  workingDir = ".",
const std::string &  OFileName = "graph",
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
workingDirThe path to the directory in which will be placed the output 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: