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

Answers computed from a Spec of graph_harness.H, without Aleph. More...

#include <algorithm>
#include <limits>
#include <numeric>
#include <set>
#include <vector>
#include "graph_harness.H"
Include dependency graph for graph_oracles.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

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

Namespaces

namespace  graph_oracles
 

Enumerations

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

Functions

int graph_oracles::degree (const Spec &s, int x)
 The degree of x: a loop counts 2.
 
std::vector< int > graph_oracles::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 graph_oracles::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 > graph_oracles::cut_nodes (const Spec &s)
 The nodes whose removal splits their component.
 
std::set< int > graph_oracles::cut_nodes (const Spec &s, int start)
 The cut nodes of the component of start.
 
std::set< int > graph_oracles::bridges (const Spec &s)
 The arcs, by number, whose removal splits their component.
 
bool graph_oracles::has_cycle (const Spec &s)
 Whether the multigraph, not directed, has a cycle.
 
bool graph_oracles::on_cycle (const Spec &s, int x)
 Whether the node x lies on a cycle of the multigraph, not directed.
 
bool graph_oracles::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 graph_oracles::max_matching (const Spec &s)
 The size of a maximum matching, by brute force over the subsets of the arcs; loops never match.
 
bool graph_oracles::is_matching (const Spec &s, const std::vector< int > &arcs)
 Whether the arcs, by number, form a matching of s.
 
long long graph_oracles::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 > > graph_oracles::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 graph_oracles::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 > graph_oracles::scc_partition (const Spec &s)
 The strongly connected components, as the smallest node of the component of each node.
 
bool graph_oracles::is_dag (const Spec &s)
 Whether the digraph has no directed cycle (a loop is one)
 
bool graph_oracles::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 > > graph_oracles::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 graph_oracles::reversed (const Spec &s)
 The spec with each arc reversed; the arcs keep their numbers.
 
Spec graph_oracles::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 > graph_oracles::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 > > graph_oracles::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 > graph_oracles::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 > > graph_oracles::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 graph_oracles::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 graph_oracles::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 graph_oracles::saturated_add (long long a, long long b)
 a + b, kept within the range of long long
 
std::vector< std::vector< long long > > graph_oracles::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 graph_oracles::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 graph_oracles::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 graph_oracles::Inf = std::numeric_limits<long long>::max()
 No distance, in the matrices of the oracles.
 

Detailed Description

Answers computed from a Spec of graph_harness.H, without Aleph.

Each oracle works on the list of arcs of a Spec with the standard library only, by brute force or by the simplest algorithm that is plainly right, so that it shares no code with what it checks. They are meant for the small graphs of the harness: several of them are exponential.

In a multigraph that is not directed, a loop is a cycle, two parallel arcs make a cycle, and a loop adds 2 to the degree of its node.

Definition in file graph_oracles.H.