29#ifndef __ADS_ArrayGraph
30 #define __ADS_ArrayGraph
60template<
class W = std::monostate >
69 static constexpr bool weighted = ! std::is_same_v< W , std::monostate >;
94 ArrayGraph(
int n ,
const std::vector< std::tuple< int , int , W > > & E ,
104 [[nodiscard]]
bool directed(
void )
const {
return( f_directed ); }
107 [[nodiscard]]
int n(
void )
const {
return(
int( f_off.size() ) - 1 ); }
110 [[nodiscard]]
int m(
void )
const {
return( f_m ); }
114 [[nodiscard]]
int arcs(
void )
const {
return(
int( f_to.size() ) ); }
117 [[nodiscard]]
int bound(
void )
const {
return(
n() ); }
123 [[nodiscard]] std::vector< int >
V(
void )
const;
126 [[nodiscard]] std::vector< int >
adj(
int u )
const;
138 [[nodiscard]] std::optional< W >
weight(
int u ,
int v )
const;
149 [[nodiscard]]
auto nodes(
void )
const {
150 return( std::views::iota( 0 ,
n() ) );
155 [[nodiscard]] std::span< const int >
neighbors(
int u )
const;
161 [[nodiscard]]
const int *
offsets(
void )
const {
return( f_off.data() ); }
164 [[nodiscard]]
const int *
heads(
void )
const {
return( f_to.data() ); }
167 [[nodiscard]]
const W *
weightData(
void )
const {
return( f_w.data() ); }
183 static std::vector< std::tuple< int , int , W > >
edges(
const G & g );
187 [[nodiscard]]
bool consistent(
void )
const;
190 std::vector< int > f_off;
191 std::vector< int > f_to;
192 std::vector< W > f_w;
205#include "ADS/graph/impl/ArrayGraph.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
ArrayGraph(int n, const std::vector< std::tuple< int, int, W > > &E, bool directed=true)
the graph of the nodes and of the given edges; an unoriented edge is given once
std::vector< int > adj(int u) const
const W * arcWeights(void) const
the weights of all the arcs read in place, weightData(), as in StaticGraph
Definition ArrayGraph.h:174
int arcs(void) const
the number of arcs, 2 m() if the graph is unoriented, as in StaticGraph
Definition ArrayGraph.h:114
std::span< const int > neighbors(int u) const
the nodes adjacent to , contiguous in the array of the edges
ArrayGraph(const G &g)
the copy of any graph, with the nodes 0 , ... , g.bound() - 1: the names that are not nodes of g,...
std::vector< int > V(void) const
the set of the nodes, in increasing order
void forEachEdge(int u, F &&f) const
bool setWeight(int u, int v, const W &w)
the weight of set to (of both its arcs if unoriented), in ; false if there is no such edge
const int * heads(void) const
the adjacent nodes, row by row
Definition ArrayGraph.h:164
bool directed(void) const
whether the graph is oriented
Definition ArrayGraph.h:104
int m(void) const
the number of edges, an unoriented one counted once
Definition ArrayGraph.h:110
const int * offsets(void) const
the offsets of the rows, of them: the adjacent nodes of are the places from offsets()[ u ] to offse...
Definition ArrayGraph.h:161
void forEachAdj(int u, F &&f) const
static constexpr bool weighted
whether the arcs have a weight, as in StaticGraph
Definition ArrayGraph.h:69
auto nodes(void) const
the nodes, , random access
Definition ArrayGraph.h:149
std::optional< W > weight(int u, int v) const
the weight of , nothing if there is no such edge, in
const int * arcHeads(void) const
the heads of all the arcs read in place, heads(), as in StaticGraph
Definition ArrayGraph.h:170
const W * weightData(void) const
the weights, in the places of heads()
Definition ArrayGraph.h:167
bool hasNode(int u) const
whether is a node
int bound(void) const
the names of the nodes,
Definition ArrayGraph.h:117
W Weight
the type of the weights
Definition ArrayGraph.h:66
int n(void) const
the number of nodes
Definition ArrayGraph.h:107
The GRAPH of chapter 9 and its realizations.
std::vector< WeightedEdge< typename G::Weight > > edges(const G &g)
the edges of an unoriented graph, each once, from its smaller end