Skip to content

Commit 19f8954

Browse files
authored
Jump bump (#39)
* bump jump * update versions * fix readme
1 parent 33c0a2b commit 19f8954

File tree

5 files changed

+48
-42
lines changed

5 files changed

+48
-42
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
1212
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1313

1414
[compat]
15-
JuMP = "0.20"
16-
LightGraphs = "1"
15+
JuMP = "0.21"
16+
LightGraphs = "1.3"
1717
SimpleTraits = "0.9"
1818
julia = "1"
1919

README.md

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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
2123
julia> 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

2729
julia> capacity_matrix = zeros(Int, 8, 8) # Create a capacity matrix
2830

2931
julia> 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
3335
end
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

5156
julia> 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

5964
julia> 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
6368
end
6469

@@ -70,9 +75,7 @@ julia> points = multiroute_flow(flow_graph, 1, 8, capacity_matrix) # Run default
7075

7176
julia> 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
8184
defined 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
```

src/mincost.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Returns a sparse flow matrix, flow[i,j] corresponds to the flow on the (i,j) arc
2121
positive for sink nodes, and zero for all other nodes.
2222
- `edge_capacity::AbstractMatrix` sets an upper bound on the flow of each arc.
2323
- `edge_cost::AbstractMatrix` the cost per unit of flow on each arc.
24-
- `optimizer` is an optimizer factory as defined in JuMP, passed at the construction of the `JuMP.Model`.
24+
- `optimizer` is an optimizer constructor, like `Clp.Optimizer` or `() -> Clp.Optimizer()` passed at the construction of the `JuMP.Model`.
2525
2626
# Keyword arguments
2727
@@ -38,7 +38,6 @@ julia> import LightGraphs
3838
julia> const LG = LightGraphs
3939
julia> using LightGraphsFlows: mincost_flow
4040
julia> import Clp # use your favorite LP solver here
41-
julia> import JuMP
4241
julia> using SparseArrays: spzeros
4342
julia> g = LG.DiGraph(6) # Create a flow-graph
4443
julia> LG.add_edge!(g, 5, 1)
@@ -58,7 +57,7 @@ julia> demand = spzeros(6)
5857
julia> demand[5] = -2
5958
julia> demand[6] = 2
6059
julia> capacity = ones(6,6)
61-
julia> flow = mincost_flow(g, demand, capacity, cost, JuMP.with_optimizer(Clp.Optimizer))
60+
julia> flow = mincost_flow(g, demand, capacity, cost, Clp.Optimizer)
6261
```
6362
"""
6463
function mincost_flow end

test/mincost.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import GLPK
2-
using JuMP
32

43
using SparseArrays: spzeros
54

@@ -27,7 +26,7 @@ using SparseArrays: spzeros
2726
demand[4,6] = 1
2827
capacity = ones(6,6)
2928

30-
o = with_optimizer(GLPK.Optimizer)
29+
o = GLPK.Optimizer
3130
node_demand = spzeros(lg.nv(g))
3231
flow = mincost_flow(g, node_demand, capacity, cost, o, edge_demand=demand, source_nodes=[5], sink_nodes=[6])
3332
@test flow[5,1] 1

test/mincut.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@testset "Mincut" begin
22

3-
g = lg.CompleteDiGraph(5)
3+
g = lg.complete_digraph(5)
44
cap1 = [
55
0.0 2.0 2.0 0.0 0.0
66
0.0 0.0 0.0 0.0 3.0

0 commit comments

Comments
 (0)