Skip to content

num::graph

Defined in header <structures/graph/graph.hpp>

template <typename Weight, std::integral Index>
class graph;

Weighted graph \(G = (V, E, w)\), directed or undirected.

Members

member description
using weight_type = Weight
using index_type = Index
explicit graph(Index n = 0, bool directed = false) Construct a graph on n vertices with no edges.
void add_edge(Index u, Index v, Weight weight = Weight{1}) Add the undirected edge \(\{u, v\}\) with weight \(w > 0\).
void add_directed_edge(Index u, Index v, Weight weight = Weight{1}) Add the directed edge \(u \to v\) with weight \(w > 0\).
bool has_edge(Index u, Index v) const Test whether the edge \(u \to v\) exists.
Weight edge_weight(Index u, Index v) const Return the weight of \(u \to v\), or 0 if there is no such edge.
Index degree(Index u) const Return the degree: \(\deg(u)\).
Weight weighted_degree(Index u) const Return the weighted degree: \(\sum_v w_{uv}\).
view<const graph_edge> neighbors(Index u) const Return the edges at u.
Index n_vertices() const noexcept Return the number of vertices $\vert V\vert $.
Index n_edges() const noexcept Return the number of edges $\vert E\vert $.
bool is_directed() const noexcept Test whether the graph is directed.