Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
graph_oracles Namespace Reference

Classes

struct  Union_Find
 Union-find over the nodes 0 .. n - 1. More...
 

Enumerations

enum class  Euler { None , Path , Cycle }
 What kind of Eulerian walk the multigraph has. More...
 

Functions

int degree (const Spec &s, int x)
 The degree of x: a loop counts 2.
 
std::vector< int > component_of (const Spec &s, int skip_node=-1, int skip_arc=-1)
 The number of the component of each node, as that of its root, of the graph without the node skip_node and the arc skip_arc (-1: none)
 
int components (const Spec &s, int skip_node=-1, int skip_arc=-1)
 The number of components, without the node skip_node and the arc skip_arc.
 
std::set< int > cut_nodes (const Spec &s)
 The nodes whose removal splits their component.
 
std::set< int > cut_nodes (const Spec &s, int start)
 The cut nodes of the component of start.
 
std::set< int > bridges (const Spec &s)
 The arcs, by number, whose removal splits their component.
 
bool has_cycle (const Spec &s)
 Whether the multigraph, not directed, has a cycle.
 
bool on_cycle (const Spec &s, int x)
 Whether the node x lies on a cycle of the multigraph, not directed.
 
bool is_bipartite (const Spec &s)
 Whether the multigraph, not directed, has two colors with no arc inside one (a loop is an odd cycle)
 
int max_matching (const Spec &s)
 The size of a maximum matching, by brute force over the subsets of the arcs; loops never match.
 
bool is_matching (const Spec &s, const std::vector< int > &arcs)
 Whether the arcs, by number, form a matching of s.
 
long long min_spanning_forest_weight (const Spec &s)
 The weight of a minimum spanning forest: Kruskal on the list of arcs.
 
std::vector< std::vector< bool > > closure (const Spec &s, bool directed)
 reach[u][v]: v is reached from u by a directed path of one arc or more (in a graph that is not directed, give directed = false)
 
bool reaches (const std::vector< std::vector< bool > > &r, int u, int v)
 Whether there is a path, of zero arcs or more, from u to v.
 
std::vector< int > scc_partition (const Spec &s)
 The strongly connected components, as the smallest node of the component of each node.
 
bool is_dag (const Spec &s)
 Whether the digraph has no directed cycle (a loop is one)
 
bool is_topological_order (const Spec &s, const std::vector< int > &order)
 Whether order, a sequence of all the nodes, is a topological order.
 
std::vector< std::vector< int > > hops (const Spec &s, bool directed)
 hops[u][v]: the least number of arcs of a path from u to v, 0 from u to itself and -1 if there is no path
 
Spec reversed (const Spec &s)
 The spec with each arc reversed; the arcs keep their numbers.
 
Spec without (const Spec &s, unsigned long hidden, std::vector< int > &orig)
 The spec without the arcs whose numbers are set in hidden, with orig[i] the number in s of its i-th arc.
 
std::vector< int > kahn_ranks (const Spec &s)
 The rank that Kahn's algorithm gives each node of a digraph: 0 for a node without arcs in, else 1 + the largest rank of its predecessors.
 
std::vector< std::vector< bool > > dominators (const Spec &s, int root)
 dom[d][v]: d dominates v from root in a digraph, that is, v is reached from root and every path from root to v goes through d.
 
std::vector< int > immediate_dominators (const Spec &s, int root)
 The immediate dominator of each node from root: the strict dominator that all the others dominate; -1 for root and the nodes not reached.
 
std::vector< std::set< int > > dominance_frontiers (const Spec &s, int root)
 The dominance frontier of each node from root: y is in that of x if x dominates a predecessor of y and does not strictly dominate y.
 
bool is_euler_walk (const Spec &s, const std::vector< int > &arcs, bool directed, bool closed)
 Whether arcs, by number, walk every arc of s once, each from the node where the one before ended (from either end if not directed), back to where they began if closed.
 
Euler euler_class (const Spec &s, bool directed)
 The Eulerian class of s: the arcs must be in one component (weakly, in a digraph), and the degrees even, or balanced, everywhere but at the two ends of a path.
 
long long saturated_add (long long a, long long b)
 a + b, kept within the range of long long
 
std::vector< std::vector< long long > > shortest_distances (const Spec &s, bool directed, bool &neg)
 Floyd on a matrix of long long: the shortest distances, Inf where there is no path, and neg set if there is a negative cycle; in a graph that is not directed each arc goes both ways.
 
bool is_negative_cycle (const Spec &s, const std::vector< int > &arcs, bool directed)
 Whether the arcs, by number, form a closed walk of s whose weights add up to less than zero; in a graph that is not directed each arc may be walked either way.
 
long long max_flow (const Spec &s, int src, int snk)
 The maximum flow from src to snk, by Edmonds-Karp on the matrix of the capacities w (loops carry nothing)
 

Variables

constexpr long long Inf = std::numeric_limits<long long>::max()
 No distance, in the matrices of the oracles.
 

Enumeration Type Documentation

◆ Euler

enum class graph_oracles::Euler
strong

What kind of Eulerian walk the multigraph has.

Enumerator
None 
Path 
Cycle 

Definition at line 539 of file graph_oracles.H.

Function Documentation

◆ bridges()

std::set< int > graph_oracles::bridges ( const Spec &  s)
inline

The arcs, by number, whose removal splits their component.

Definition at line 152 of file graph_oracles.H.

References graph_harness::Spec::arcs, components(), and r.

Referenced by TYPED_TEST().

◆ closure()

std::vector< std::vector< bool > > graph_oracles::closure ( const Spec &  s,
bool  directed 
)
inline

reach[u][v]: v is reached from u by a directed path of one arc or more (in a graph that is not directed, give directed = false)

Definition at line 282 of file graph_oracles.H.

References graph_harness::Spec::arcs, k, graph_harness::Spec::n, and r.

Referenced by is_dag(), kahn_ranks(), scc_partition(), TYPED_TEST(), and TYPED_TEST().

◆ component_of()

std::vector< int > graph_oracles::component_of ( const Spec &  s,
int  skip_node = -1,
int  skip_arc = -1 
)
inline

The number of the component of each node, as that of its root, of the graph without the node skip_node and the arc skip_arc (-1: none)

Definition at line 100 of file graph_oracles.H.

References graph_harness::Spec::arcs, graph_oracles::Union_Find::find(), graph_oracles::Union_Find::join(), and graph_harness::Spec::n.

Referenced by components(), cut_nodes(), on_cycle(), TYPED_TEST(), and TYPED_TEST().

◆ components()

int graph_oracles::components ( const Spec &  s,
int  skip_node = -1,
int  skip_arc = -1 
)
inline

The number of components, without the node skip_node and the arc skip_arc.

Definition at line 119 of file graph_oracles.H.

References component_of(), and graph_harness::Spec::n.

Referenced by bridges(), cut_nodes(), TYPED_TEST(), and TYPED_TEST().

◆ cut_nodes() [1/2]

std::set< int > graph_oracles::cut_nodes ( const Spec &  s)
inline

The nodes whose removal splits their component.

Definition at line 130 of file graph_oracles.H.

References components(), graph_harness::Spec::n, and r.

Referenced by cut_nodes(), and TYPED_TEST().

◆ cut_nodes() [2/2]

std::set< int > graph_oracles::cut_nodes ( const Spec &  s,
int  start 
)
inline

The cut nodes of the component of start.

Definition at line 141 of file graph_oracles.H.

References component_of(), cut_nodes(), and r.

◆ degree()

int graph_oracles::degree ( const Spec &  s,
int  x 
)
inline

The degree of x: a loop counts 2.

Definition at line 90 of file graph_oracles.H.

References graph_harness::Spec::arcs.

Referenced by euler_class().

◆ dominance_frontiers()

std::vector< std::set< int > > graph_oracles::dominance_frontiers ( const Spec &  s,
int  root 
)
inline

The dominance frontier of each node from root: y is in that of x if x dominates a predecessor of y and does not strictly dominate y.

Definition at line 484 of file graph_oracles.H.

References Aleph::and, graph_harness::Spec::arcs, Aleph::df(), dominators(), graph_harness::Spec::n, and root().

Referenced by TYPED_TEST().

◆ dominators()

std::vector< std::vector< bool > > graph_oracles::dominators ( const Spec &  s,
int  root 
)
inline

dom[d][v]: d dominates v from root in a digraph, that is, v is reached from root and every path from root to v goes through d.

A node that is reached dominates itself.

Definition at line 426 of file graph_oracles.H.

References Aleph::all(), Aleph::and, graph_harness::Spec::arcs, graph_harness::Spec::n, and root().

Referenced by dominance_frontiers(), immediate_dominators(), and TYPED_TEST().

◆ euler_class()

Euler graph_oracles::euler_class ( const Spec &  s,
bool  directed 
)
inline

The Eulerian class of s: the arcs must be in one component (weakly, in a digraph), and the degrees even, or balanced, everywhere but at the two ends of a path.

Without arcs, the empty walk is a cycle.

Definition at line 544 of file graph_oracles.H.

References Aleph::and, graph_harness::Spec::arcs, Cycle, degree(), graph_oracles::Union_Find::find(), graph_oracles::Union_Find::join(), graph_harness::Spec::n, None, out, and Path.

Referenced by TYPED_TEST(), and TYPED_TEST().

◆ has_cycle()

bool graph_oracles::has_cycle ( const Spec &  s)
inline

Whether the multigraph, not directed, has a cycle.

Definition at line 163 of file graph_oracles.H.

References graph_harness::Spec::arcs, graph_oracles::Union_Find::join(), and graph_harness::Spec::n.

Referenced by TYPED_TEST(), and TYPED_TEST().

◆ hops()

std::vector< std::vector< int > > graph_oracles::hops ( const Spec &  s,
bool  directed 
)
inline

hops[u][v]: the least number of arcs of a path from u to v, 0 from u to itself and -1 if there is no path

Definition at line 355 of file graph_oracles.H.

References Aleph::and, graph_harness::Spec::arcs, h, k, and graph_harness::Spec::n.

◆ immediate_dominators()

std::vector< int > graph_oracles::immediate_dominators ( const Spec &  s,
int  root 
)
inline

The immediate dominator of each node from root: the strict dominator that all the others dominate; -1 for root and the nodes not reached.

Definition at line 463 of file graph_oracles.H.

References Aleph::and, dominators(), graph_harness::Spec::n, and root().

Referenced by TYPED_TEST().

◆ is_bipartite()

bool graph_oracles::is_bipartite ( const Spec &  s)
inline

Whether the multigraph, not directed, has two colors with no arc inside one (a loop is an odd cycle)

Definition at line 191 of file graph_oracles.H.

References graph_harness::Spec::arcs, Aleph::color(), k, graph_harness::Spec::n, root(), and y.

Referenced by TYPED_TEST().

◆ is_dag()

bool graph_oracles::is_dag ( const Spec &  s)
inline

Whether the digraph has no directed cycle (a loop is one)

Definition at line 326 of file graph_oracles.H.

References closure(), graph_harness::Spec::n, and r.

Referenced by TYPED_TEST(), and TYPED_TEST().

◆ is_euler_walk()

bool graph_oracles::is_euler_walk ( const Spec &  s,
const std::vector< int > &  arcs,
bool  directed,
bool  closed 
)
inline

Whether arcs, by number, walk every arc of s once, each from the node where the one before ended (from either end if not directed), back to where they began if closed.

Definition at line 499 of file graph_oracles.H.

References Aleph::and, arcs, and graph_harness::Spec::arcs.

Referenced by TYPED_TEST(), and TYPED_TEST().

◆ is_matching()

bool graph_oracles::is_matching ( const Spec &  s,
const std::vector< int > &  arcs 
)
inline

Whether the arcs, by number, form a matching of s.

Definition at line 252 of file graph_oracles.H.

References arcs, graph_harness::Spec::arcs, and graph_harness::Spec::n.

Referenced by TYPED_TEST().

◆ is_negative_cycle()

bool graph_oracles::is_negative_cycle ( const Spec &  s,
const std::vector< int > &  arcs,
bool  directed 
)
inline

Whether the arcs, by number, form a closed walk of s whose weights add up to less than zero; in a graph that is not directed each arc may be walked either way.

Definition at line 633 of file graph_oracles.H.

References Aleph::and, arcs, graph_harness::Spec::arcs, and graph_harness::Spec::w.

◆ is_topological_order()

bool graph_oracles::is_topological_order ( const Spec &  s,
const std::vector< int > &  order 
)
inline

Whether order, a sequence of all the nodes, is a topological order.

Definition at line 336 of file graph_oracles.H.

References graph_harness::Spec::arcs, and graph_harness::Spec::n.

Referenced by TYPED_TEST().

◆ kahn_ranks()

std::vector< int > graph_oracles::kahn_ranks ( const Spec &  s)
inline

The rank that Kahn's algorithm gives each node of a digraph: 0 for a node without arcs in, else 1 + the largest rank of its predecessors.

The nodes that a cycle reaches never come out, and have -1.

Definition at line 405 of file graph_oracles.H.

References Aleph::and, graph_harness::Spec::arcs, closure(), graph_harness::Spec::n, r, and reaches().

Referenced by TYPED_TEST().

◆ max_flow()

long long graph_oracles::max_flow ( const Spec &  s,
int  src,
int  snk 
)
inline

The maximum flow from src to snk, by Edmonds-Karp on the matrix of the capacities w (loops carry nothing)

Definition at line 670 of file graph_oracles.H.

References Aleph::and, graph_harness::Spec::arcs, h, Inf, graph_harness::Spec::n, and graph_harness::Spec::w.

◆ max_matching()

int graph_oracles::max_matching ( const Spec &  s)
inline

The size of a maximum matching, by brute force over the subsets of the arcs; loops never match.

Definition at line 224 of file graph_oracles.H.

References Aleph::and, graph_harness::Spec::arcs, m, graph_harness::Spec::n, and Aleph::size().

Referenced by TYPED_TEST().

◆ min_spanning_forest_weight()

long long graph_oracles::min_spanning_forest_weight ( const Spec &  s)
inline

The weight of a minimum spanning forest: Kruskal on the list of arcs.

Definition at line 266 of file graph_oracles.H.

References graph_harness::Spec::arcs, graph_oracles::Union_Find::join(), graph_harness::Spec::n, and graph_harness::Spec::w.

◆ on_cycle()

bool graph_oracles::on_cycle ( const Spec &  s,
int  x 
)
inline

Whether the node x lies on a cycle of the multigraph, not directed.

Definition at line 173 of file graph_oracles.H.

References Aleph::and, graph_harness::Spec::arcs, and component_of().

Referenced by TYPED_TEST().

◆ reaches()

bool graph_oracles::reaches ( const std::vector< std::vector< bool > > &  r,
int  u,
int  v 
)
inline

Whether there is a path, of zero arcs or more, from u to v.

Definition at line 301 of file graph_oracles.H.

References r.

Referenced by kahn_ranks(), and TYPED_TEST().

◆ reversed()

Spec graph_oracles::reversed ( const Spec &  s)
inline

The spec with each arc reversed; the arcs keep their numbers.

Definition at line 376 of file graph_oracles.H.

References r.

Referenced by TYPED_TEST().

◆ saturated_add()

long long graph_oracles::saturated_add ( long long  a,
long long  b 
)
inline

a + b, kept within the range of long long

Definition at line 592 of file graph_oracles.H.

References Aleph::and.

Referenced by shortest_distances().

◆ scc_partition()

std::vector< int > graph_oracles::scc_partition ( const Spec &  s)
inline

The strongly connected components, as the smallest node of the component of each node.

Definition at line 308 of file graph_oracles.H.

References Aleph::and, closure(), graph_harness::Spec::n, and r.

Referenced by TYPED_TEST().

◆ shortest_distances()

std::vector< std::vector< long long > > graph_oracles::shortest_distances ( const Spec &  s,
bool  directed,
bool &  neg 
)
inline

Floyd on a matrix of long long: the shortest distances, Inf where there is no path, and neg set if there is a negative cycle; in a graph that is not directed each arc goes both ways.

The sums are saturated, so weights up to 2^40 in absolute value are exact on the graphs of the harness, negative cycles included.

Definition at line 607 of file graph_oracles.H.

References Aleph::and, graph_harness::Spec::arcs, Inf, k, graph_harness::Spec::n, saturated_add(), and graph_harness::Spec::w.

Referenced by TEST().

◆ without()

Spec graph_oracles::without ( const Spec &  s,
unsigned long  hidden,
std::vector< int > &  orig 
)
inline

The spec without the arcs whose numbers are set in hidden, with orig[i] the number in s of its i-th arc.

Definition at line 386 of file graph_oracles.H.

References graph_harness::Spec::arcs, graph_harness::Spec::n, r, and graph_harness::Spec::w.

Referenced by TYPED_TEST().

Variable Documentation

◆ Inf

constexpr long long graph_oracles::Inf = std::numeric_limits<long long>::max()
constexpr

No distance, in the matrices of the oracles.

Definition at line 589 of file graph_oracles.H.

Referenced by max_flow(), shortest_distances(), and TEST().