discrete-modulus (C++)
Reference implementations of discrete modulus algorithms (C++)
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Functions
discrete_modulus Namespace Reference

Namespaces

namespace  detail
 

Classes

struct  FlowContext
 The reusable max-flow network for cunningham_min / graph_vulnerability / spanning_tree_modulus, built once per graph by create_flow_graph. More...
 
struct  NonCriticalEdge
 Edge filter selecting edges not in a given critical/tight set. More...
 
struct  SolverTrace
 The full recorded trace of a spanning_tree_modulus run. More...
 
struct  TraceRound
 One round of spanning_tree_modulus's main loop: the component it was carved from, the edge set dispatched at eta* = theta, and theta itself. More...
 

Typedefs

using Traits = adjacency_list_traits< vecS, vecS, undirectedS >
 Traits for Graph.
 
using Graph = adjacency_list< vecS, vecS, undirectedS, property< vertex_name_t, Traits::vertex_descriptor >, property< edge_index_t, int, property< edge_weight_t, long > > >
 The undirected graph type used throughout this library.
 
using Vertex = graph_traits< Graph >::vertex_descriptor
 
using Edge = graph_traits< Graph >::edge_descriptor
 
using VertexIterator = graph_traits< Graph >::vertex_iterator
 
using EdgeIterator = graph_traits< Graph >::edge_iterator
 
using FlowTraits = adjacency_list_traits< vecS, vecS, directedS >
 Traits for FlowGraph.
 
using FlowVertex = FlowTraits::vertex_descriptor
 
using FlowEdge = FlowTraits::edge_descriptor
 
using FlowGraph = adjacency_list< vecS, vecS, directedS, no_property, property< edge_capacity_t, long, property< edge_residual_capacity_t, long, property< edge_reverse_t, FlowTraits::edge_descriptor > > > >
 The directed, capacitated graph type used for the max-flow subproblem in Cunningham's algorithm (see create_flow_graph in cunningham.hpp). edge_reverse records, for every directed edge, its paired reverse-residual edge, as required by boost::push_relabel_max_flow.
 

Functions

FlowContext create_flow_graph (Graph &g)
 Builds the reusable max-flow network for g.
 
std::pair< long, std::set< Edge > > cunningham_min (Graph &g, FlowContext &ctx, long p, long q)
 Finds a P(qf)-basis for the constant function p, along with a tight set, using Cunningham's greedy algorithm.
 
std::pair< rational< long >, std::set< Edge > > graph_vulnerability (Graph &g, FlowContext &ctx, rational< long > ubound=rational< long >(1, 1))
 Finds the vulnerability theta(G) of a graph by binary search, along with an optimal tight set.
 
std::map< Edge, rational< long > > spanning_tree_modulus (Graph &g, bool verbose=false, SolverTrace *trace=nullptr)
 Computes the exact spanning tree modulus of g using Cunningham's algorithm.
 
template<typename G >
Graph subgraph (const G &g, std::vector< Vertex > v)
 Builds the subgraph of g induced by the given vertices.
 
template<typename G >
std::vector< Graphconnected_component_graphs (const G &g)
 Splits g into one Graph per connected component.
 
std::vector< Graphinduced_components (Graph &g, const std::set< Edge > &A)
 Splits g into connected components after removing the critical edge set A.
 
template<typename G >
bool is_simple_graph (const G &g)
 Checks whether g is a simple graph: no self-loops, no parallel edges between the same pair of vertices.
 
Graph cycle_plus_triangle (int n)
 A cycle on n vertices plus one extra chord (between vertices 1 and n-1).
 
Graph complete_graph (int n)
 The complete graph on n vertices.
 
Graph wheel_graph (int n)
 The wheel graph: a cycle on n-1 vertices plus one hub vertex n-1.
 
Graph growing_multipartite (int n_layers)
 A multipartite graph with growing layer sizes (1, 2, ..., n_layers) and complete bipartite connections between consecutive layers.
 
Graph complete_plus_triangle (int n)
 The complete graph on n-1 vertices, plus one extra vertex attached to two of them.
 
Graph permuted_graph (const Graph &g, const std::vector< int > &perm)
 g with vertices relabeled according to perm.
 
Graph disconnected_graph ()
 Two disjoint triangles: a minimal example of a disconnected graph.
 
Graph random_gnp_graph (int n, double p, int seed)
 An Erdos-Renyi G(n,p) random graph.
 
Graph random_geometric_graph (int n, double r, int seed=381928)
 A random geometric graph: n uniform points in the unit square, connected within radius r.
 
void write_trace_json (std::ostream &os, const SolverTrace &trace)
 Writes trace to os as versioned JSON ("version": 1).
 

Typedef Documentation

◆ Edge

using discrete_modulus::Edge = typedef graph_traits<Graph>::edge_descriptor

◆ EdgeIterator

using discrete_modulus::EdgeIterator = typedef graph_traits<Graph>::edge_iterator

◆ FlowEdge

using discrete_modulus::FlowEdge = typedef FlowTraits::edge_descriptor

◆ FlowGraph

using discrete_modulus::FlowGraph = typedef adjacency_list< vecS, vecS, directedS, no_property, property<edge_capacity_t, long, property<edge_residual_capacity_t, long, property<edge_reverse_t, FlowTraits::edge_descriptor> >> >

The directed, capacitated graph type used for the max-flow subproblem in Cunningham's algorithm (see create_flow_graph in cunningham.hpp). edge_reverse records, for every directed edge, its paired reverse-residual edge, as required by boost::push_relabel_max_flow.

◆ FlowTraits

using discrete_modulus::FlowTraits = typedef adjacency_list_traits<vecS, vecS, directedS>

Traits for FlowGraph.

◆ FlowVertex

using discrete_modulus::FlowVertex = typedef FlowTraits::vertex_descriptor

◆ Graph

using discrete_modulus::Graph = typedef adjacency_list< vecS, vecS, undirectedS, property<vertex_name_t, Traits::vertex_descriptor>, property<edge_index_t, int, property<edge_weight_t, long> >>

The undirected graph type used throughout this library.

Vertices carry a vertex_name property (used to map a component's local vertex descriptors back to the original graph's vertex descriptors after splitting into connected components; see subgraph). Edges carry an edge_index (a stable 0..m-1 numbering) and an edge_weight (used as the current point x in Cunningham's algorithm; see cunningham.hpp).

◆ Traits

using discrete_modulus::Traits = typedef adjacency_list_traits<vecS, vecS, undirectedS>

Traits for Graph.

◆ Vertex

using discrete_modulus::Vertex = typedef graph_traits<Graph>::vertex_descriptor

◆ VertexIterator

using discrete_modulus::VertexIterator = typedef graph_traits<Graph>::vertex_iterator

Function Documentation

◆ complete_graph()

Graph discrete_modulus::complete_graph ( int  n)
inline

The complete graph on n vertices.

◆ complete_plus_triangle()

Graph discrete_modulus::complete_plus_triangle ( int  n)
inline

The complete graph on n-1 vertices, plus one extra vertex attached to two of them.

◆ connected_component_graphs()

template<typename G >
std::vector< Graph > discrete_modulus::connected_component_graphs ( const G &  g)

Splits g into one Graph per connected component.

◆ create_flow_graph()

FlowContext discrete_modulus::create_flow_graph ( Graph g)
inline

Builds the reusable max-flow network for g.

Precondition
g outlives, and is not modified (beyond its edge_weight property, which cunningham_min manages) for the lifetime of, the returned FlowContext – it assigns and relies on a stable edge_index numbering of g's edges.

◆ cunningham_min()

std::pair< long, std::set< Edge > > discrete_modulus::cunningham_min ( Graph g,
FlowContext ctx,
long  p,
long  q 
)
inline

Finds a P(qf)-basis for the constant function p, along with a tight set, using Cunningham's greedy algorithm.

Parameters
gGraph to compute on; its edge_weight property map is used to store the current point x and is reset to zero at the start of this call.
ctxReusable flow network for g, from create_flow_graph.
p,qTogether, p/q is the rational constant whose P(f)-basis is being sought.
Returns
{x(E), A}: the total weight of the P(qf)-basis found (x itself is left in g's edge_weight property map), and a tight set A for it (i.e. x(A) == q * f(A)).

◆ cycle_plus_triangle()

Graph discrete_modulus::cycle_plus_triangle ( int  n)
inline

A cycle on n vertices plus one extra chord (between vertices 1 and n-1).

◆ disconnected_graph()

Graph discrete_modulus::disconnected_graph ( )
inline

Two disjoint triangles: a minimal example of a disconnected graph.

◆ graph_vulnerability()

std::pair< rational< long >, std::set< Edge > > discrete_modulus::graph_vulnerability ( Graph g,
FlowContext ctx,
rational< long >  ubound = rational<long>(1, 1) 
)
inline

Finds the vulnerability theta(G) of a graph by binary search, along with an optimal tight set.

Parameters
gGraph to compute on.
ctxReusable flow network for g, from create_flow_graph.
uboundAn upper bound on theta(G), when known (e.g. the parent component's own theta, during spanning_tree_modulus's recursive decomposition) – restricts the binary search range. Defaults to 1, theta's global maximum possible value.
Returns
{theta, J}: the vulnerability of g, and a tight edge set achieving it.

◆ growing_multipartite()

Graph discrete_modulus::growing_multipartite ( int  n_layers)
inline

A multipartite graph with growing layer sizes (1, 2, ..., n_layers) and complete bipartite connections between consecutive layers.

◆ induced_components()

std::vector< Graph > discrete_modulus::induced_components ( Graph g,
const std::set< Edge > &  A 
)
inline

Splits g into connected components after removing the critical edge set A.

◆ is_simple_graph()

template<typename G >
bool discrete_modulus::is_simple_graph ( const G &  g)

Checks whether g is a simple graph: no self-loops, no parallel edges between the same pair of vertices.

spanning_tree_modulus assumes this. It's not just a matter of degree: eta_star's own construction looks up edge(u, v, g), which identifies an edge by its endpoint pair alone – unambiguous only when g is simple. Fed a multigraph, that lookup would silently return an arbitrary one of several parallel edges and mis-assign its eta*, not fail loudly. (The spanning-tree-modulus solver was never designed to handle multigraph inputs – the shrunk multigraphs that show up in deflation/certification, e.g. Multigraph in the Lean verifier or the networkx multigraphs pmf_construction.py builds, are a separate, purely conceptual construction the certificate builder reasons about after the fact; the solver itself only ever recurses on vertex-induced subgraphs of the original input, so it never needs to represent one internally.)

◆ permuted_graph()

Graph discrete_modulus::permuted_graph ( const Graph g,
const std::vector< int > &  perm 
)
inline

g with vertices relabeled according to perm.

◆ random_geometric_graph()

Graph discrete_modulus::random_geometric_graph ( int  n,
double  r,
int  seed = 381928 
)
inline

A random geometric graph: n uniform points in the unit square, connected within radius r.

◆ random_gnp_graph()

Graph discrete_modulus::random_gnp_graph ( int  n,
double  p,
int  seed 
)
inline

An Erdos-Renyi G(n,p) random graph.

◆ spanning_tree_modulus()

std::map< Edge, rational< long > > discrete_modulus::spanning_tree_modulus ( Graph g,
bool  verbose = false,
SolverTrace trace = nullptr 
)
inline

Computes the exact spanning tree modulus of g using Cunningham's algorithm.

Parameters
gGraph to compute on.
verboseIf true, prints a progress table to stdout as edges are assigned their eta* value.
traceIf non-null, appends one TraceRound per round of the main loop below (opt-in; leaving this null, the default, reproduces the exact behavior of every existing caller).
Returns
eta*: the exact spanning tree modulus edge weighting, whose blocking dual is Chopra's family of feasible partitions (see the companion book's "Exact Spanning Tree Modulus" chapter).

◆ subgraph()

template<typename G >
Graph discrete_modulus::subgraph ( const G &  g,
std::vector< Vertex v 
)

Builds the subgraph of g induced by the given vertices.

The returned graph's vertex_name property maps each of its (local) vertices back to the corresponding vertex descriptor in g, so that results computed on the subgraph can be mapped back to g.

◆ wheel_graph()

Graph discrete_modulus::wheel_graph ( int  n)
inline

The wheel graph: a cycle on n-1 vertices plus one hub vertex n-1.

◆ write_trace_json()

void discrete_modulus::write_trace_json ( std::ostream &  os,
const SolverTrace trace 
)
inline

Writes trace to os as versioned JSON ("version": 1).

Every value is either an integer or an array of them, so this is a plain hand-written emitter – no JSON library dependency, no escaping concerns (there are no free-form strings in the schema).