Dynamical system model
Loading...
Searching...
No Matches
dsf::Network< node_t, edge_t > Class Template Referenceabstract

Public Member Functions

 Network ()=default
 Construct a new empty Network object.
auto const & nodes () const noexcept
 Get the nodes as an unordered map.
auto const & edges () const noexcept
 Get the edges as an unordered map.
auto nNodes () const noexcept
 Get the number of nodes.
auto nEdges () const noexcept
 Get the number of edges.
template<typename TNode = node_t, typename... TArgs>
void addNode (TArgs &&... args)
template<typename TNode = node_t>
void addNDefaultNodes (std::size_t const n)
template<typename TEdge = edge_t, typename... TArgs>
void addEdge (TArgs &&... args)
virtual void setEdgeWeight (std::string_view const strv_weight, std::optional< double > const threshold=std::nullopt)=0
const auto & node (Id const nodeId) const
 Get a node by id.
auto & node (Id const nodeId)
 Get a node by id.
const auto & edge (Id const edgeId) const
 Get an edge by id.
auto & edge (Id const edgeId)
 Get an edge by id.
edge_t & edge (Id const source, Id const target) const
template<typename TNode>
auto & node (Id const nodeId)
 Get a node by id and cast it to a derived type.
template<typename TEdge>
auto & edge (Id const edgeId)
 Get an edge by id and cast it to a derived type.
PathCollection allPathsTo (Id const targetId) const
 Perform a global Dijkstra search to a target node from all other nodes in the graph.
PathCollection shortestPath (Id const sourceId, Id const targetId) const
 Find the shortest path between two nodes using Dijkstra's algorithm.
void computeBetweennessCentralities ()
 Compute node weighted betweenness centralities using Brandes' algorithm.
void computeEdgeBetweennessCentralities ()
 Compute edge weighted betweenness centralities using Brandes' algorithm.

Protected Member Functions

constexpr auto m_cantorHash (Id u, Id v) const
constexpr auto m_cantorHash (std::pair< Id, Id > const &idPair) const

Protected Attributes

std::unordered_map< Id, std::unique_ptr< node_t > > m_nodes
std::unordered_map< Id, std::unique_ptr< edge_t > > m_edges
std::function< double(edge_t const &)> m_weightFunction
std::optional< double > m_weightThreshold = std::nullopt

Member Function Documentation

◆ allPathsTo()

template<typename node_t, typename edge_t>
PathCollection dsf::Network< node_t, edge_t >::allPathsTo ( Id const targetId) const
inline

Perform a global Dijkstra search to a target node from all other nodes in the graph.

Parameters
thresholdRelative tolerance on full path cost from each node to the target
Returns
A map where each key is a node id and the value is a vector of next hop node ids toward the target
Exceptions
std::out_of_rangeif the target node does not exist

Keeps only transitions that strictly decrease the precomputed shortest distance to target. This makes the hop graph acyclic, so PathCollection::explode remains finite.

◆ edge() [1/3]

template<typename node_t, typename edge_t>
template<typename TEdge>
auto & dsf::Network< node_t, edge_t >::edge ( Id const edgeId)
inline

Get an edge by id and cast it to a derived type.

Template Parameters
TEdgeThe expected type of the edge
Parameters
edgeIdThe id of the edge to get
Returns
TEdge& A reference to the edge with the given id, cast to the expected type

◆ edge() [2/3]

template<typename node_t, typename edge_t>
auto & dsf::Network< node_t, edge_t >::edge ( Id const edgeId)
inline

Get an edge by id.

Parameters
edgeIdThe id of the edge to get
Returns
edge_t& A reference to the edge with the given id

◆ edge() [3/3]

template<typename node_t, typename edge_t>
const auto & dsf::Network< node_t, edge_t >::edge ( Id const edgeId) const
inline

Get an edge by id.

Parameters
edgeIdThe id of the edge to get
Returns
const edge_t& A const reference to the edge with the given id

◆ node() [1/3]

template<typename node_t, typename edge_t>
template<typename TNode>
auto & dsf::Network< node_t, edge_t >::node ( Id const nodeId)
inline

Get a node by id and cast it to a derived type.

Template Parameters
TNodeThe expected type of the node
Parameters
nodeIdThe id of the node to get
Returns
TNode& A reference to the node with the given id, cast to the expected type

◆ node() [2/3]

template<typename node_t, typename edge_t>
auto & dsf::Network< node_t, edge_t >::node ( Id const nodeId)
inline

Get a node by id.

Parameters
nodeIdThe id of the node to get
Returns
node_t& A reference to the node with the given id

◆ node() [3/3]

template<typename node_t, typename edge_t>
const auto & dsf::Network< node_t, edge_t >::node ( Id const nodeId) const
inline

Get a node by id.

Parameters
nodeIdThe id of the node to get
Returns
const node_t& A const reference to the node with the given id

◆ setEdgeWeight()

template<typename node_t, typename edge_t>
virtual void dsf::Network< node_t, edge_t >::setEdgeWeight ( std::string_view const strv_weight,
std::optional< double > const threshold = std::nullopt )
pure virtual

Implemented in dsf::mobility::RoadNetwork.

◆ shortestPath()

template<typename node_t, typename edge_t>
PathCollection dsf::Network< node_t, edge_t >::shortestPath ( Id const sourceId,
Id const targetId ) const
inline

Find the shortest path between two nodes using Dijkstra's algorithm.

Parameters
sourceIdThe id of the source node
targetIdThe id of the target node
Returns
A map where each key is a node id and the value is a vector of next hop node ids toward the target. Returns an empty map if no path exists
Exceptions
std::out_of_rangeif the source or target node does not exist

Uses Dijkstra's algorithm to compute strict distances to target, then includes only transitions that both: (1) strictly decrease the target distance (acyclic), and (2) are consistent with shortest source-distance labels. The second constraint keeps the returned PathCollection sound when exploded, i.e. it avoids combining prefix-dependent hops into over-budget paths.

Member Data Documentation

◆ m_weightFunction

template<typename node_t, typename edge_t>
std::function<double(edge_t const&)> dsf::Network< node_t, edge_t >::m_weightFunction
protected
Initial value:
=
[]([[maybe_unused]] edge_t const& edge) {
return 1.0;
}
const auto & edge(Id const edgeId) const
Get an edge by id.
Definition Network.hpp:86

The documentation for this class was generated from the following file:
  • src/dsf/base/Network.hpp