@@ -17,18 +17,20 @@ Documentation for this package is available [here](https://juliagraphs.github.io
1717### Maxflow
1818
1919``` julia
20- julia> flow_graph = lg. DiGraph (8 ) # Create a flow-graph
20+ julia> using LightGraphs, LightGraphsFlows
21+ julia> const LG = LightGraphs
22+ julia> flow_graph = LG. DiGraph (8 ) # Create a flow graph
2123julia> flow_edges = [
22- (1 ,2 ,10 ),(1 ,3 ,5 ),(1 ,4 ,15 ),(2 ,3 ,4 ),(2 ,5 ,9 ),
23- (2 ,6 ,15 ),(3 ,4 ,4 ),(3 ,6 ,8 ),(4 ,7 ,16 ),(5 ,6 ,15 ),
24- (5 ,8 ,10 ),(6 ,7 ,15 ),(6 ,8 ,10 ),(7 ,3 ,6 ),(7 ,8 ,10 )
24+ (1 ,2 ,10 ),(1 ,3 ,5 ),(1 ,4 ,15 ),(2 ,3 ,4 ),(2 ,5 ,9 ),
25+ (2 ,6 ,15 ),(3 ,4 ,4 ),(3 ,6 ,8 ),(4 ,7 ,16 ),(5 ,6 ,15 ),
26+ (5 ,8 ,10 ),(6 ,7 ,15 ),(6 ,8 ,10 ),(7 ,3 ,6 ),(7 ,8 ,10 )
2527]
2628
2729julia> capacity_matrix = zeros (Int, 8 , 8 ) # Create a capacity matrix
2830
2931julia> for e in flow_edges
3032 u, v, f = e
31- lg . add_edge! (flow_graph, u, v)
33+ LG . add_edge! (flow_graph, u, v)
3234 capacity_matrix[u,v] = f
3335end
3436
@@ -46,7 +48,10 @@ julia> f, F, labels = maximum_flow(flow_graph, 1, 8, capacity_matrix, algorithm=
4648### Multi-route flow
4749
4850``` julia
49- julia> flow_graph = lg. DiGraph (8 ) # Create a flow graph
51+ julia> using LightGraphs, LightGraphsFlows
52+ julia> const LG = LightGraphs
53+
54+ julia> flow_graph = LG. DiGraph (8 ) # Create a flow graph
5055
5156julia> flow_edges = [
5257(1 , 2 , 10 ), (1 , 3 , 5 ), (1 , 4 , 15 ), (2 , 3 , 4 ), (2 , 5 , 9 ),
@@ -58,7 +63,7 @@ julia> capacity_matrix = zeros(Int, 8, 8) # Create a capacity matrix
5863
5964julia> for e in flow_edges
6065 u, v, f = e
61- add_edge! (flow_graph, u, v)
66+ LG . add_edge! (flow_graph, u, v)
6267 capacity_matrix[u, v] = f
6368end
6469
@@ -70,9 +75,7 @@ julia> points = multiroute_flow(flow_graph, 1, 8, capacity_matrix) # Run default
7075
7176julia> f, F = multiroute_flow (points, 1.5 ) # Then run multiroute flow algorithm for any positive number of routes
7277
73- julia> f = multiroute_flow (points, 1.5 , valueonly = true )
74-
75- julia> f, F, labels = multiroute_flow (flow_graph, 1 , 8 , capacity_matrix, algorithm = BoykovKolmogorovAlgorithm (), routes = 2 ) # Run multiroute flow algorithm using Boykov-Kolmogorov algorithm as maximum_flow routine
78+ julia> f, F, labels = multiroute_flow (flow_graph, 1 , 8 , capacity_matrix, flow_algorithm = BoykovKolmogorovAlgorithm (), routes = 2 ) # Run multiroute flow algorithm using Boykov-Kolmogorov algorithm as maximum_flow routine
7679```
7780
7881## Mincost flow
@@ -81,29 +84,34 @@ Mincost flow is solving a linear optimization problem and thus requires a LP opt
8184defined by [ MathOptInterface.jl] ( https://www.juliaopt.org/MathOptInterface.jl/stable/ ) .
8285
8386``` julia
84- using SparseArrays: spzeros
85- import Clp
86-
87- g = lg. DiGraph (6 )
88- lg. add_edge! (g, 5 , 1 )
89- lg. add_edge! (g, 5 , 2 )
90- lg. add_edge! (g, 3 , 6 )
91- lg. add_edge! (g, 4 , 6 )
92- lg. add_edge! (g, 1 , 3 )
93- lg. add_edge! (g, 1 , 4 )
94- lg. add_edge! (g, 2 , 3 )
95- lg. add_edge! (g, 2 , 4 )
96- cost = zeros (6 ,6 )
97- cost[1 ,3 ] = 10.
98- cost[1 ,4 ] = 5.
99- cost[2 ,3 ] = 2.
100- cost[2 ,4 ] = 2.
101- # v2 -> sink have demand of one
102- demand = spzeros (6 ,6 )
103- demand[3 ,6 ] = 1
104- demand[4 ,6 ] = 1
105- node_demand = spzeros (6 )
106- capacity = ones (6 ,6 )
87+ julia> using SparseArrays: spzeros
88+ julia> import Clp
89+
90+ julia> using LightGraphs, LightGraphsFlows
91+ julia> const LG = LightGraphs
92+
93+ julia> g = LG. DiGraph (6 )
94+ julia> LG. add_edge! (g, 5 , 1 )
95+ julia> LG. add_edge! (g, 5 , 2 )
96+ julia> LG. add_edge! (g, 3 , 6 )
97+ julia> LG. add_edge! (g, 4 , 6 )
98+ julia> LG. add_edge! (g, 1 , 3 )
99+ julia> LG. add_edge! (g, 1 , 4 )
100+ julia> LG. add_edge! (g, 2 , 3 )
101+ julia> LG. add_edge! (g, 2 , 4 )
102+ julia> cost = zeros (6 ,6 )
103+ julia> cost[1 ,3 ] = 10.
104+ julia> cost[1 ,4 ] = 5.
105+ julia> cost[2 ,3 ] = 2.
106+ julia> cost[2 ,4 ] = 2.
107107
108- flow = mincost_flow (g, node_demand, capacity, cost, Clp. Optimizer, edge_demand= demand, source_nodes= [5 ], sink_nodes= [6 ])
108+ # v2 -> sink have demand of one
109+ julia> demand = spzeros (6 ,6 )
110+ julia> demand[3 ,6 ] = 1
111+ julia> demand[4 ,6 ] = 1
112+ julia> node_demand = spzeros (6 )
113+ julia> capacity = ones (6 ,6 )
114+
115+ # returns the sparse flow matrix
116+ julia> flow = mincost_flow (g, node_demand, capacity, cost, Clp. Optimizer, edge_demand= demand, source_nodes= [5 ], sink_nodes= [6 ])
109117```
0 commit comments