DG-CPP 0.1.0
Directed Graph in C++
dg::DGraph< NodeT, EdgeT, IDT > Class Template Reference

Directed graph class. More...

#include <core.hpp>

Inheritance diagram for dg::DGraph< NodeT, EdgeT, IDT >:
[legend]
Collaboration diagram for dg::DGraph< NodeT, EdgeT, IDT >:
[legend]

Public Member Functions

NodeT node (IDT id) const
 
NodeT & node (IDT id)
 
bool strictCheck () const
 
void insertNode (IDT id, const NodeT &data)
 
void insertNode (IDT id, const NodeT &data, const _CN &cn)
 
void removeNode (IDT id, bool keep_edge=false)
 
void insertEdge (IDT from_id, IDT to_id, bool to_exists=true)
 
void insertEdge (IDT from_id, IDT to_id, EdgeT_CR data, bool to_exists=true)
 
NodeT operator[] (IDT id) const
 
NodeT & operator[] (IDT id)
 
bool operator== (const DGraph &dg) const
 
bool operator!= (const DGraph &dg) const
 
- Public Member Functions inherited from dg::DGraphBase< void, std::string >
 DGraphBase ()=default
 Construct a new DGraphBase object. More...
 
bool hasNode (IDT id) const noexcept
 Check if the graph has a node with id. More...
 
bool hasEdge (IDT from_id, IDT to_id) const noexcept
 Check if the graph has an edge linking from_id and to_id. More...
 
size_t numNodes () const noexcept
 The total number of nodes in the graph. More...
 
size_t numEdges () const noexcept
 The total number of edges in the graph. More...
 
size_t size () const noexcept
 The total number of nodes in the graph. More...
 
void edge (IDT from_id, IDT to_id) const
 Get the edge data between two nodes. More...
 
EdgeT_R edge (IDT from_id, IDT to_id)
 Get the edge data reference between two nodes. More...
 
Ret edge (IDT from_id, IDT to_id, Fn func, Args... args) const
 Get the edge data after processing with a Lambda expression. More...
 
Ret edge (IDT from_id, IDT to_id, std::function< Ret(EdgeT_, Args...)> func, Args... args) const
 Get the edge data after processing with a std::function. More...
 
bool strictCheck () const
 Check if the graph is strictly valid. More...
 
std::vector< IDT > nodesID () const
 Get all nodes IS in the graph. More...
 
std::vector< std::pair< IDT, IDT > > edges () const
 Get all edge connections in the graph. More...
 
void insertNode (IDT id)
 Insert a node. More...
 
void insertNode (IDT id, const std::map< IDT, void > &map, bool nodes_exist=false)
 Insert a node with edge data. More...
 
void removeNode (IDT id, bool keep_edge=false)
 Remove the node from the graph. More...
 
void removeNodeIfExists (IDT id, bool keep_edge=false)
 Remove the node from the graph if it exists. More...
 
void insertEdgeToExists (IDT from_id, IDT to_id)
 
void insertEdgeToExists (IDT from_id, IDT to_id, EdgeT_CR data)
 
void insertEdge (IDT from_id, IDT to_id, bool to_exists=false)
 Insert an edge to the graph without data. More...
 
void insertEdge (IDT from_id, IDT to_id, EdgeT_CR data, bool to_exists=false)
 Insert an edge to the graph with data. More...
 
bool isConnected (IDT from_id, IDT to_id) const
 Check whether to node are connected. More...
 
std::pair< EdgeT_, std::vector< IDT > > maxWeightPath (IDT from_id, IDT to_id) const
 Obtain the maximum weight and its corresponding path between two nodes. More...
 
std::pair< Ret, std::vector< IDT > > maxWeightPath (IDT from_id, IDT to_id, Fn func, Args... args) const
 Obtain the maximum weight and its corresponding path between two nodes. More...
 
std::pair< Ret, std::vector< IDT > > maxWeightPath (IDT from_id, IDT to_id, std::function< Ret(EdgeT_, Args...)> func, Args... args) const
 Obtain the maximum weight and its corresponding path between two nodes. More...
 
std::pair< EdgeT_, std::vector< IDT > > minWeightPath (IDT from_id, IDT to_id) const
 Obtain the minimum weight and its corresponding path between two nodes. More...
 
std::pair< Ret, std::vector< IDT > > minWeightPath (IDT from_id, IDT to_id, Fn func, Args... args) const
 Obtain the minimum weight and its corresponding path between two nodes. More...
 
std::pair< Ret, std::vector< IDT > > minWeightPath (IDT from_id, IDT to_id, std::function< Ret(EdgeT_, Args...)> func, Args... args) const
 Obtain the minimum weight and its corresponding path between two nodes. More...
 
void insertSubGraph (const DGraphBase< void, IDT > &dg)
 Insert subgraph into the main graph. More...
 
void insertSubGraph (const DGraphBase< void, IDT > &dg, IDT id)
 Insert a subgraph at a node. More...
 
void merge (const DGraphBase< void, IDT > &dg)
 Merge a graph into the main graph. More...
 
void clear ()
 Clear the whole graph. More...
 
void clearEdges ()
 Clear all edges of the graph. More...
 
bool operator== (const DGraphBase< void, IDT > &dg) const
 Check if two graphs are identical. More...
 
bool operator!= (const DGraphBase< void, IDT > &dg) const
 Check if two graphs are different. More...
 
DGraphBaseoperator+= (const DGraphBase< void, IDT > &dg)
 Merge two graphs. More...
 
void operator() (IDT from_id, IDT to_id) const
 Get the edge data between two nodes. More...
 
EdgeT_R operator() (IDT from_id, IDT to_id)
 Get the edge data reference between two nodes. More...
 

Protected Types

using _CN = typename DGraphBase< EdgeT, IDT >::_CN
 
using EdgeT_CR = typename DGraphBase< EdgeT, IDT >::EdgeT_CR
 
- Protected Types inherited from dg::DGraphBase< void, std::string >
using _ET = Edge< void >
 
using _CN = std::map< IDT, _ET >
 
using EdgeT__ = typename std::conditional< std::is_void_v< T >, int, T >::type
 Edge type that avoids void. More...
 
using EdgeT_R_ = typename std::conditional< std::is_void_v< T >, int, T >::type &
 Reference to edge type that avoids void. More...
 
using EdgeT_CR_ = const typename std::conditional< std::is_void_v< T >, int, T >::type &
 Const reference to edge type that avoids void. More...
 
using EdgeT_ = EdgeT__<>
 
using EdgeT_R = EdgeT_R_<>
 
using EdgeT_CR = EdgeT_CR_<>
 

Private Attributes

std::map< IDT, NodeT > node_data
 

Additional Inherited Members

- Protected Member Functions inherited from dg::DGraphBase< void, std::string >
void insertNode (IDT id, const _CN &cn, bool nodes_exist=false)
 Insert a node. More...
 
const std::map< IDT, _CN > & graph () const
 Return the const reference to the graph map. More...
 
std::map< IDT, _CN > & graph ()
 Return the reference to the graph map. More...
 

Detailed Description

template<typename NodeT, typename EdgeT = void, typename IDT = std::string>
class dg::DGraph< NodeT, EdgeT, IDT >

Directed graph class.

Template Parameters
NodeTNode type.
EdgeTEdge type.
IDTID type (should not be void and should be comparable).

Member Typedef Documentation

◆ _CN

template<typename NodeT , typename EdgeT = void, typename IDT = std::string>
using dg::DGraph< NodeT, EdgeT, IDT >::_CN = typename DGraphBase<EdgeT, IDT>::_CN
protected

◆ EdgeT_CR

template<typename NodeT , typename EdgeT = void, typename IDT = std::string>
using dg::DGraph< NodeT, EdgeT, IDT >::EdgeT_CR = typename DGraphBase<EdgeT, IDT>::EdgeT_CR
protected

Member Function Documentation

◆ insertEdge() [1/2]

template<typename NodeT , typename EdgeT , typename IDT >
requires std::is_void_v<EdgeT>
void dg::DGraph< NodeT, EdgeT, IDT >::insertEdge ( IDT  from_id,
IDT  to_id,
bool  to_exists = true 
)
inline
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insertEdge() [2/2]

template<typename NodeT , typename EdgeT , typename IDT >
requires EdgeVT<EdgeT>
void dg::DGraph< NodeT, EdgeT, IDT >::insertEdge ( IDT  from_id,
IDT  to_id,
EdgeT_CR  data,
bool  to_exists = true 
)
inline
Here is the call graph for this function:

◆ insertNode() [1/2]

template<typename NodeT , typename EdgeT , typename IDT >
void dg::DGraph< NodeT, EdgeT, IDT >::insertNode ( IDT  id,
const NodeT &  data 
)
inline
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insertNode() [2/2]

template<typename NodeT , typename EdgeT , typename IDT >
void dg::DGraph< NodeT, EdgeT, IDT >::insertNode ( IDT  id,
const NodeT &  data,
const _CN cn 
)
inline
Here is the call graph for this function:

◆ node() [1/2]

template<typename NodeT , typename EdgeT , typename IDT >
NodeT & dg::DGraph< NodeT, EdgeT, IDT >::node ( IDT  id)
inline

◆ node() [2/2]

template<typename NodeT , typename EdgeT , typename IDT >
NodeT dg::DGraph< NodeT, EdgeT, IDT >::node ( IDT  id) const
inline
Here is the caller graph for this function:

◆ operator!=()

template<typename NodeT , typename EdgeT , typename IDT >
bool dg::DGraph< NodeT, EdgeT, IDT >::operator!= ( const DGraph< NodeT, EdgeT, IDT > &  dg) const
inline
Here is the call graph for this function:

◆ operator==()

template<typename NodeT , typename EdgeT , typename IDT >
bool dg::DGraph< NodeT, EdgeT, IDT >::operator== ( const DGraph< NodeT, EdgeT, IDT > &  dg) const
inline
Here is the call graph for this function:

◆ operator[]() [1/2]

template<typename NodeT , typename EdgeT , typename IDT >
NodeT & dg::DGraph< NodeT, EdgeT, IDT >::operator[] ( IDT  id)
inline
Here is the call graph for this function:

◆ operator[]() [2/2]

template<typename NodeT , typename EdgeT , typename IDT >
NodeT dg::DGraph< NodeT, EdgeT, IDT >::operator[] ( IDT  id) const
inline
Here is the call graph for this function:

◆ removeNode()

template<typename NodeT , typename EdgeT , typename IDT >
void dg::DGraph< NodeT, EdgeT, IDT >::removeNode ( IDT  id,
bool  keep_edge = false 
)
inline
Here is the call graph for this function:
Here is the caller graph for this function:

◆ strictCheck()

template<typename NodeT , typename EdgeT , typename IDT >
bool dg::DGraph< NodeT, EdgeT, IDT >::strictCheck
inline
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ node_data

template<typename NodeT , typename EdgeT = void, typename IDT = std::string>
std::map<IDT, NodeT> dg::DGraph< NodeT, EdgeT, IDT >::node_data
private

node data


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