|
XNetwork 1.7.5; VERSION ${PROJECT_VERSION}
|
Classes | |
| struct | DualEdge |
Functions | |
| template<typename Node , typename WeightFunc > | |
| auto | build_dual (const std::vector< std::vector< Node > > &faces, WeightFunc weight) -> std::vector< std::vector< DualEdge< Node > > > |
| template<typename Node > | |
| auto | dijkstra (const std::vector< std::vector< DualEdge< Node > > > &dual, int src) -> std::pair< std::vector< int >, std::vector< int > > |
| auto | reconstruct_path (const std::vector< int > &prev, int src, int dst) -> std::vector< int > |
| template<typename Node > | |
| auto | greedy_mwpm (const std::vector< int > &odd_faces, const std::vector< std::vector< int > > &dist) -> std::vector< std::pair< int, int > > |
| template<typename Node > | |
| auto | exact_mwpm (const std::vector< int > &odd_faces, const std::vector< std::vector< int > > &dist) -> std::vector< std::pair< int, int > > |
| template<typename Node > | |
| auto | min_weight_perfect_matching (const std::vector< int > &odd_faces, const std::vector< std::vector< int > > &dist) -> std::vector< std::pair< int, int > > |
| template<typename Graph > | |
| auto | biconnected_components (const Graph &G) -> std::vector< py::set< typename Graph::node_t > > |
| Decompose a graph into its biconnected components (blocks). | |
| template<typename Graph , typename WeightFunc > | |
| auto | solve_hadlock_component (const Graph &G, WeightFunc weight, const std::vector< std::vector< typename Graph::node_t > > &faces) -> py::set< std::pair< typename Graph::node_t, typename Graph::node_t > > |
| Solve MAX-CUT for a single planar biconnected component. | |
| template<typename Node , typename Validator > | |
| void | reverse_delete_cover (py::set< Node > &soln, const std::vector< Node > &added_order, Validator &&is_valid) |
| Reverse-delete post-processing step. | |
| template<typename Node , typename WeightFunc > | |
| auto | prim_mst (size_t n, WeightFunc &&weight) -> std::vector< std::pair< Node, Node > > |
| Prim's MST for dense (complete) graphs - O(n^2). | |
| template<typename Node > | |
| auto | find_odd_degree_nodes (const std::vector< std::pair< Node, Node > > &mst_edges, size_t n) -> std::vector< Node > |
| Collect vertices with odd degree in the MST. | |
| template<typename Node , typename WeightFunc > | |
| auto | greedy_min_weight_matching (const std::vector< Node > &odd_nodes, WeightFunc &&weight) -> std::vector< std::pair< Node, Node > > |
| Greedy minimum-weight perfect matching - O(k^2 log k). | |
| template<typename Node > | |
| auto | build_multigraph (size_t n, const std::vector< std::pair< Node, Node > > &mst_edges, const std::vector< std::pair< Node, Node > > &matching_edges) -> std::vector< std::multiset< Node > > |
| Build a multigraph adjacency list (MST + matching). | |
| template<typename Node > | |
| auto | hierholzer (std::vector< std::multiset< Node > > adj, Node start) -> std::vector< std::pair< Node, Node > > |
| Hierholzer's algorithm - find an Eulerian circuit. | |
| template<typename Node > | |
| auto | shortcut_eulerian (const std::vector< std::pair< Node, Node > > &eulerian_circuit) -> std::vector< Node > |
| Convert an Eulerian circuit to a Hamiltonian cycle by skipping repeated vertices (shortcut). | |
Variables | |
| constexpr int | INF = std::numeric_limits<int>::max() / 2 |
| auto detail::biconnected_components | ( | const Graph & | G | ) | -> std::vector< py::set< typename Graph::node_t > > |
Decompose a graph into its biconnected components (blocks).
MAX-CUT is additive over biconnected components because edges in different blocks share only articulation points and cannot form cycles together. Processing each block independently reduces the size of the dual-graph shortest-path and MWPM subproblems.
Uses a DFS-based algorithm (Tarjan) tracking discovery time and low-link values, pushing/poping edges onto a stack.
| Graph | Graph type (must provide node_t, operator[], begin/end) |
| G | The input graph. |
| auto detail::build_dual | ( | const std::vector< std::vector< Node > > & | faces, |
| WeightFunc | weight | ||
| ) | -> std::vector<std::vector<DualEdge<Node>>> |
| auto detail::build_multigraph | ( | size_t | n, |
| const std::vector< std::pair< Node, Node > > & | mst_edges, | ||
| const std::vector< std::pair< Node, Node > > & | matching_edges | ||
| ) | -> std::vector<std::multiset<Node>> |
Build a multigraph adjacency list (MST + matching).
Parallel edges are preserved via std::multiset so that the graph is Eulerian (all vertices have even degree).
| auto detail::dijkstra | ( | const std::vector< std::vector< DualEdge< Node > > > & | dual, |
| int | src | ||
| ) | -> std::pair< std::vector< int >, std::vector< int > > |
| auto detail::exact_mwpm | ( | const std::vector< int > & | odd_faces, |
| const std::vector< std::vector< int > > & | dist | ||
| ) | -> std::vector< std::pair< int, int > > |
Exact MWPM via DP over subsets (n <= 18, 2^18 = 262k states).
| auto detail::find_odd_degree_nodes | ( | const std::vector< std::pair< Node, Node > > & | mst_edges, |
| size_t | n | ||
| ) | -> std::vector<Node> |
Collect vertices with odd degree in the MST.
| auto detail::greedy_min_weight_matching | ( | const std::vector< Node > & | odd_nodes, |
| WeightFunc && | weight | ||
| ) | -> std::vector<std::pair<Node, Node>> |
Greedy minimum-weight perfect matching - O(k^2 log k).
Builds a sorted list of all candidate edges among odd_nodes and greedily picks the cheapest non-adjacent pair. This is a heuristic; for a provable 3/2 bound a blossom algorithm would be required.
| auto detail::greedy_mwpm | ( | const std::vector< int > & | odd_faces, |
| const std::vector< std::vector< int > > & | dist | ||
| ) | -> std::vector< std::pair< int, int > > |
Greedy 2-approximation for MWPM on a metric complete graph.
| auto detail::hierholzer | ( | std::vector< std::multiset< Node > > | adj, |
| Node | start | ||
| ) | -> std::vector< std::pair< Node, Node > > |
Hierholzer's algorithm - find an Eulerian circuit.
Assumes the graph is connected and every vertex has even degree.
| adj | adjacency (multiset per vertex) - consumed by the algorithm |
| start | start vertex |
(u, v) forming the circuit | auto detail::min_weight_perfect_matching | ( | const std::vector< int > & | odd_faces, |
| const std::vector< std::vector< int > > & | dist | ||
| ) | -> std::vector<std::pair<int, int>> |
Dispatch MWPM: exact DP for small n, greedy for large n.
| auto detail::prim_mst | ( | size_t | n, |
| WeightFunc && | weight | ||
| ) | -> std::vector<std::pair<Node, Node>> |
Prim's MST for dense (complete) graphs - O(n^2).
| Node | integral node type |
| WeightFunc | callable double(Node, Node) |
| n | number of vertices (assumed 0 .. n-1) |
| weight | edge-weight function |
|
inline |
| void detail::reverse_delete_cover | ( | py::set< Node > & | soln, |
| const std::vector< Node > & | added_order, | ||
| Validator && | is_valid | ||
| ) |
Reverse-delete post-processing step.
Iterates through vertices in reverse addition order. For each vertex, temporarily removes it; if the cover remains valid, the removal is kept (vertex was redundant). Otherwise the vertex is restored.
| Node | Vertex type |
| Validator | Callable that returns true if current cover is valid |
| soln | Mutable cover set (modified in place) |
| added_order | Vertices in order they were added |
| is_valid | Validation callable |
| auto detail::shortcut_eulerian | ( | const std::vector< std::pair< Node, Node > > & | eulerian_circuit | ) | -> std::vector<Node> |
Convert an Eulerian circuit to a Hamiltonian cycle by skipping repeated vertices (shortcut).
| auto detail::solve_hadlock_component | ( | const Graph & | G, |
| WeightFunc | weight, | ||
| const std::vector< std::vector< typename Graph::node_t > > & | faces | ||
| ) | -> py::set<std::pair<typename Graph::node_t, typename Graph::node_t>> |
Solve MAX-CUT for a single planar biconnected component.
This is the core Hadlock logic factored out so it can be called once per biconnected component. The existing 3-argument overload of solve_hadlock_max_cut delegates here.
| Graph | Graph type |
| WeightFunc | Callable (u, v) -> int |
| G | Planar graph (or subgraph) |
| weight | Edge weight function |
| faces | Face boundaries (cyclic node sequences) |