|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Advanced Maximum Flow Algorithms Comparison. More...
#include <iostream>#include <iomanip>#include <chrono>#include <vector>#include <string>#include <cstring>#include <tpl_net.H>#include <tpl_maxflow.H>Go to the source code of this file.
Typedefs | |
| using | FlowType = double |
| using | Net = Net_Graph< Net_Node< string >, Net_Arc< Empty_Class, FlowType > > |
| using | Node = Net::Node |
Functions | |
| static void | usage (const char *prog) |
| static bool | has_flag (int argc, char *argv[], const char *flag) |
| static const char * | get_opt_value (int argc, char *argv[], const char *opt) |
| Net | build_supply_chain () |
| Build a supply chain network. | |
| Net | build_grid_network (int rows, int cols, FlowType base_cap=10.0) |
| Build a grid network for stress testing. | |
| template<typename Algorithm > | |
| pair< FlowType, double > | time_algorithm (Net net) |
| Time a max-flow algorithm execution. | |
| void | print_flow_stats (Net &net, const string &title) |
| Print network flow statistics. | |
| void | demonstrate_flow_decomposition (Net &net) |
| Demonstrate flow decomposition into paths. | |
| void | compare_algorithms (int grid_size) |
| Compare all algorithms on the same network. | |
| void | demonstrate_min_cut (Net &net) |
| Demonstrate min-cut duality. | |
| int | main (int argc, char *argv[]) |
Advanced Maximum Flow Algorithms Comparison.
This example demonstrates and compares different maximum flow algorithms available in Aleph-w. While basic Ford-Fulkerson/Edmonds-Karp works well for many cases, advanced algorithms offer better performance for specific graph types and scenarios.
Different max-flow algorithms excel in different scenarios:
Strategy: Use BFS to find shortest augmenting paths
Complexity: O(V × E²)
Pros:
Cons:
Strategy: Use level graphs and blocking flows
How it works:
Complexity: O(V² × E)
Pros:
Cons:
Strategy: Process edges in rounds by capacity threshold
How it works:
Complexity: O(V × E × log U)
Pros:
Cons:
Strategy: Push-relabel with highest label selection
How it works:
Complexity: O(V² × √E)
Pros:
Cons:
| Algorithm | Time Complexity | Best For |
|---|---|---|
| Edmonds-Karp | O(V × E²) | Sparse graphs, simplicity |
| Dinic | O(V² × E) | General purpose |
| Capacity Scaling | O(V × E × log U) | Large capacities |
| HLPP | O(V² × √E) | Dense graphs |
Note: Actual performance depends heavily on graph structure!
| Algorithm | Complexity | Relative Speed |
|---|---|---|
| Edmonds-Karp | O(V³) | 1× |
| Dinic | O(V³) | 2-5× faster |
| HLPP | O(V².5) | 3-10× faster |
| Algorithm | Complexity | Relative Speed |
|---|---|---|
| Edmonds-Karp | O(V⁵) | 1× |
| Dinic | O(V⁴) | 10-100× faster |
| HLPP | O(V³) | 100-1000× faster |
Definition in file maxflow_advanced_example.cc.
| using FlowType = double |
Definition at line 270 of file maxflow_advanced_example.cc.
Definition at line 271 of file maxflow_advanced_example.cc.
Definition at line 272 of file maxflow_advanced_example.cc.
Build a grid network for stress testing.
Creates a rows x cols grid with right and down connections. Source is automatically detected as the top-left corner, and sink as the bottom-right corner.
Definition at line 326 of file maxflow_advanced_example.cc.
References Aleph::Net_Graph< NodeT, ArcT >::insert_arc(), Aleph::Net_Graph< NodeT, ArcT >::insert_node(), Aleph::maps(), nodes, and Aleph::to_string().
Referenced by compare_algorithms(), main(), TEST(), TEST(), and TEST().
| Net build_supply_chain | ( | ) |
Build a supply chain network.
[Factory1]----10---->[Warehouse1]----8----+
| | |
12 5 |
| v v
[Source] [Hub]---------->[Sink]
| ^ ^
15 6 |
| | |
[Factory2]----12---->[Warehouse2]----9---+
Definition at line 287 of file maxflow_advanced_example.cc.
References Aleph::Net_Graph< NodeT, ArcT >::insert_arc(), Aleph::Net_Graph< NodeT, ArcT >::insert_node(), and Aleph::maps().
Referenced by main().
| void compare_algorithms | ( | int | grid_size | ) |
Compare all algorithms on the same network.
Definition at line 438 of file maxflow_advanced_example.cc.
References build_grid_network(), GraphCommon< GT, Node, Arc >::get_num_arcs(), GraphCommon< GT, Node, Arc >::get_num_nodes(), and Aleph::maps().
Referenced by main().
| void demonstrate_flow_decomposition | ( | Net & | net | ) |
Demonstrate flow decomposition into paths.
Definition at line 405 of file maxflow_advanced_example.cc.
References Aleph::decompose_flow(), LocateFunctions< Container, Type >::get_it(), Aleph::Net_Graph< NodeT, ArcT >::get_source(), GraphCommon< GT, Node, Arc >::get_tgt_node(), and Aleph::maps().
Referenced by main().
| void demonstrate_min_cut | ( | Net & | net | ) |
Demonstrate min-cut duality.
Definition at line 499 of file maxflow_advanced_example.cc.
References GraphCommon< GT, Node, Arc >::get_arc_it(), GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), and Aleph::maps().
Referenced by main().
|
static |
Definition at line 261 of file maxflow_advanced_example.cc.
References Aleph::maps().
Referenced by main().
|
static |
Definition at line 253 of file maxflow_advanced_example.cc.
References Aleph::maps().
Referenced by main().
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 526 of file maxflow_advanced_example.cc.
References build_grid_network(), build_supply_chain(), Aleph::capacity_scaling_maximum_flow(), compare_algorithms(), demonstrate_flow_decomposition(), demonstrate_min_cut(), Aleph::dinic_maximum_flow(), Aleph::edmonds_karp_maximum_flow(), get_opt_value(), has_flag(), Aleph::hlpp_maximum_flow(), Aleph::maps(), print_flow_stats(), and usage().
| void print_flow_stats | ( | Net & | net, |
| const string & | title | ||
| ) |
Print network flow statistics.
Definition at line 377 of file maxflow_advanced_example.cc.
References Aleph::Net_Graph< NodeT, ArcT >::flow_value(), GraphCommon< GT, Node, Arc >::get_arc_it(), and Aleph::maps().
Referenced by main().
Time a max-flow algorithm execution.
Definition at line 359 of file maxflow_advanced_example.cc.
References GraphCommon< GT, Node, Arc >::get_arc_it(), and Aleph::maps().
|
static |
Definition at line 242 of file maxflow_advanced_example.cc.
References Aleph::maps().
Referenced by main().