|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Cut nodes (articulation points) and biconnected components in Aleph-w. More...
#include <iostream>#include <iomanip>#include <string>#include <vector>#include <tpl_graph.H>#include <tpl_cut_nodes.H>#include <tclap/CmdLine.h>Go to the source code of this file.
Typedefs | |
| using | Node = Graph_Node< string > |
| using | Arc = Graph_Arc< int > |
| using | Graph = List_Graph< Node, Arc > |
Functions | |
| Graph | build_network_graph () |
| Build a network with clear cut nodes. | |
| Graph | build_cyclic_graph () |
| Build a cyclic graph with fewer cut nodes. | |
| Graph | build_computer_network () |
| Build a graph representing a computer network. | |
| Graph::Node * | find_node (Graph &g, const string &name) |
| Find a node by name. | |
| void | print_graph (Graph &g, const string &title) |
| Print graph structure. | |
| void | demo_cut_nodes (Graph &g, const string &description) |
| Demonstrate finding cut nodes. | |
| void | demo_network_vulnerability () |
| Practical example: Network vulnerability analysis. | |
| void | demo_biconnected_components () |
| Demonstrate biconnected components. | |
| void | demo_resilience_comparison () |
| Compare resilient vs fragile networks. | |
| void | demo_fixing_vulnerabilities () |
| Demonstrate fixing network vulnerabilities. | |
| int | main (int argc, char *argv[]) |
Cut nodes (articulation points) and biconnected components in Aleph-w.
This example demonstrates algorithms for analyzing connectivity in undirected graphs:
The implementation uses a DFS-based approach with discovery/low-link values (Tarjan-style).
Graph = List_Graph<Graph_Node<string>, Graph_Arc<int>>string)int) used by the demoThis example uses TCLAP. Options:
--basic / -b: basic cut nodes demo.--network / -n: network vulnerability analysis.--biconnected / -c: biconnected components demo.--resilience / -r: resilience comparison demo.--fix / -f: show how adding edges can remove articulation points.--all / -a: run all demos.--help: show help.Behavior:
The core idea is DFS with:
df[v]: discovery timelow[v]: smallest discovery time reachable from v via tree edges + at most one back edgeA vertex u is an articulation point if:
u is DFS root and has ≥ 2 childrenv with low[v] >= df[u]This example focuses on cut nodes and biconnected blocks (bridges are discussed conceptually but not printed as a primary output).
Let V be the number of vertices and E the number of edges.
O(V + E)O(V)tpl_cut_nodes.Hgraph_components_example.C (components)tarjan_example.C (DFS-based decomposition)Definition in file cut_nodes_example.C.
Definition at line 129 of file cut_nodes_example.C.
| using Graph = List_Graph<Node, Arc> |
Definition at line 130 of file cut_nodes_example.C.
| using Node = Graph_Node<string> |
Definition at line 128 of file cut_nodes_example.C.
| Graph build_computer_network | ( | ) |
Build a graph representing a computer network.
Server1 — Router1 — Switch1 — PC1 | | | Switch2 — PC2 | | Router2 — Switch3 — PC3 | Server2
Definition at line 223 of file cut_nodes_example.C.
References Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), and Aleph::maps().
Referenced by demo_network_vulnerability().
| Graph build_cyclic_graph | ( | ) |
Build a cyclic graph with fewer cut nodes.
A --- B
/| |\ / | | \ E | | C \ | | / | |/ D — F — G
Only F is a cut node (the cycle A-B-C-F-D-E makes others resilient)
Definition at line 182 of file cut_nodes_example.C.
References Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), and Aleph::maps().
Referenced by demo_resilience_comparison().
| Graph build_network_graph | ( | ) |
Build a network with clear cut nodes.
A --- B --- C
| |
D --- E --- F --- G
| |
+--H--+
Cut nodes: B, E, F (removing any disconnects the graph)
Definition at line 143 of file cut_nodes_example.C.
References h, Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), and Aleph::maps().
Referenced by demo_biconnected_components(), demo_fixing_vulnerabilities(), demo_resilience_comparison(), and main().
| void demo_biconnected_components | ( | ) |
Demonstrate biconnected components.
Definition at line 376 of file cut_nodes_example.C.
References build_network_graph(), Aleph::color(), GraphCommon< GT, Node, Arc >::get_counter(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::get_first_node(), LocateFunctions< Container, Type >::get_it(), GraphCommon< GT, Node, Arc >::get_node_it(), Aleph::maps(), Aleph::Compute_Cut_Nodes< GT, SA >::paint_subgraphs(), and print_graph().
Referenced by main().
| void demo_cut_nodes | ( | Graph & | g, |
| const string & | description | ||
| ) |
Demonstrate finding cut nodes.
Definition at line 294 of file cut_nodes_example.C.
References Aleph::List_Graph< _Graph_Node, _Graph_Arc >::get_first_node(), LocateFunctions< Container, Type >::get_it(), Aleph::Dlink::is_empty(), Aleph::maps(), and Aleph::DynDlist< T >::size().
Referenced by main().
| void demo_fixing_vulnerabilities | ( | ) |
Demonstrate fixing network vulnerabilities.
Definition at line 473 of file cut_nodes_example.C.
References build_network_graph(), find_node(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::get_first_node(), LocateFunctions< Container, Type >::get_it(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::Dlink::is_empty(), and Aleph::maps().
Referenced by main().
| void demo_network_vulnerability | ( | ) |
Practical example: Network vulnerability analysis.
Definition at line 329 of file cut_nodes_example.C.
References build_computer_network(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::get_first_node(), LocateFunctions< Container, Type >::get_it(), Aleph::Dlink::is_empty(), Aleph::maps(), and print_graph().
Referenced by main().
| void demo_resilience_comparison | ( | ) |
Compare resilient vs fragile networks.
Definition at line 427 of file cut_nodes_example.C.
References build_cyclic_graph(), build_network_graph(), Aleph::maps(), print_graph(), and Aleph::DynDlist< T >::size().
Referenced by main().
| Graph::Node * find_node | ( | Graph & | g, |
| const string & | name | ||
| ) |
Find a node by name.
Definition at line 255 of file cut_nodes_example.C.
References GraphCommon< GT, Node, Arc >::get_node_it().
Referenced by demo_fixing_vulnerabilities().
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 531 of file cut_nodes_example.C.
References build_network_graph(), demo_biconnected_components(), demo_cut_nodes(), demo_fixing_vulnerabilities(), demo_network_vulnerability(), demo_resilience_comparison(), Aleph::maps(), and print_graph().
| void print_graph | ( | Graph & | g, |
| const string & | title | ||
| ) |
Print graph structure.
Definition at line 266 of file cut_nodes_example.C.
References GraphCommon< GT, Node, Arc >::get_connected_node(), GraphCommon< GT, Node, Arc >::get_node_it(), GraphCommon< GT, Node, Arc >::get_num_arcs(), GraphCommon< GT, Node, Arc >::get_num_nodes(), and Aleph::maps().
Referenced by demo_biconnected_components(), demo_network_vulnerability(), demo_resilience_comparison(), and main().