Skip to content

Commit 9089262

Browse files
authored
Merge pull request #1 from JuliaGraphs/migrate-to-graphs.jl
2 parents 40cdca3 + 7c59235 commit 9089262

31 files changed

+250
-259
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The LightGraphsFlows.jl package is licensed under the Simplified "2-clause" BSD License:
1+
The GraphsFlows.jl package is licensed under the Simplified "2-clause" BSD License:
22

33
> Copyright (c) 2018: mbesancon.
44
> All rights reserved.

Project.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
name = "LightGraphsFlows"
2-
uuid = "2f5eb75a-258c-59e0-affc-f41c55f75335"
1+
name = "GraphsFlows"
2+
uuid = "06909019-6f44-4949-96fc-b9d9aaa02889"
33
authors = ["Mathieu Besançon <mathieu.besancon@gmail.com>"]
4-
version = "0.4.2"
4+
version = "0.1.0"
55

66
[deps]
7+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
78
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
8-
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
1111
SimpleTraits = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
1212
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1313

1414
[compat]
1515
JuMP = "0.21"
16-
LightGraphs = "1.3"
16+
Graphs = "1.4"
1717
SimpleTraits = "0.9"
1818
julia = "1.3"
1919

README.md

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
# LightGraphsFlows
1+
# GraphsFlows
22

3-
[![CI](https://github.com/JuliaGraphs/LightGraphsFlows.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/JuliaGraphs/LightGraphsFlows.jl/actions/workflows/ci.yml)
4-
[![codecov.io](http://codecov.io/github/JuliaGraphs/LightGraphsFlows.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaGraphs/LightGraphsFlows.jl?branch=master)
5-
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliagraphs.github.io/LightGraphsFlows.jl/stable/)
3+
[![CI](https://github.com/JuliaGraphs/GraphsFlows.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/JuliaGraphs/GraphsFlows.jl/actions/workflows/ci.yml)
4+
[![codecov.io](http://codecov.io/github/JuliaGraphs/GraphsFlows.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaGraphs/GraphsFlows.jl?branch=master)
5+
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliagraphs.github.io/GraphsFlows.jl/stable/)
66

7-
Flow algorithms on top of [LightGraphs.jl](https://github.com/JuliaGraphs/LightGraphs.jl),
7+
Flow algorithms on top of [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl),
88
including `maximum_flow`, `multiroute_flow` and `mincost_flow`.
99
See [Maximum flow problem](https://en.wikipedia.org/wiki/Maximum_flow_problem)
1010
for a detailed description of the problem.
1111

12-
Documentation for this package is available [here](https://juliagraphs.github.io/LightGraphsFlows.jl/latest/). For an overview of JuliaGraphs, see [this page](https://juliagraphs.github.io/).
12+
Documentation for this package is available [here](https://juliagraphs.github.io/GraphsFlows.jl/latest/). For an overview of JuliaGraphs, see [this page](https://juliagraphs.github.io/).
1313

1414
## Usage
1515

1616
### Maxflow
1717

1818
```julia
19-
julia> using LightGraphs, LightGraphsFlows
20-
julia> const LG = LightGraphs
21-
julia> flow_graph = LG.DiGraph(8) # Create a flow graph
19+
julia> using Graphs, GraphsFlows
20+
julia> flow_graph = Graphs.DiGraph(8) # Create a flow graph
2221
julia> flow_edges = [
2322
(1,2,10),(1,3,5),(1,4,15),(2,3,4),(2,5,9),
2423
(2,6,15),(3,4,4),(3,6,8),(4,7,16),(5,6,15),
@@ -29,7 +28,7 @@ julia> capacity_matrix = zeros(Int, 8, 8) # Create a capacity matrix
2928

3029
julia> for e in flow_edges
3130
u, v, f = e
32-
LG.add_edge!(flow_graph, u, v)
31+
Graphs.add_edge!(flow_graph, u, v)
3332
capacity_matrix[u,v] = f
3433
end
3534

@@ -47,10 +46,9 @@ julia> f, F, labels = maximum_flow(flow_graph, 1, 8, capacity_matrix, algorithm=
4746
### Multi-route flow
4847

4948
```julia
50-
julia> using LightGraphs, LightGraphsFlows
51-
julia> const LG = LightGraphs
49+
julia> using Graphs, GraphsFlows
5250

53-
julia> flow_graph = LG.DiGraph(8) # Create a flow graph
51+
julia> flow_graph = Graphs.DiGraph(8) # Create a flow graph
5452

5553
julia> flow_edges = [
5654
(1, 2, 10), (1, 3, 5), (1, 4, 15), (2, 3, 4), (2, 5, 9),
@@ -62,7 +60,7 @@ julia> capacity_matrix = zeros(Int, 8, 8) # Create a capacity matrix
6260

6361
julia> for e in flow_edges
6462
u, v, f = e
65-
LG.add_edge!(flow_graph, u, v)
63+
Graphs.add_edge!(flow_graph, u, v)
6664
capacity_matrix[u, v] = f
6765
end
6866

@@ -86,18 +84,17 @@ defined by [MathOptInterface.jl](https://www.juliaopt.org/MathOptInterface.jl/st
8684
julia> using SparseArrays: spzeros
8785
julia> import Clp
8886

89-
julia> using LightGraphs, LightGraphsFlows
90-
julia> const LG = LightGraphs
91-
92-
julia> g = LG.DiGraph(6)
93-
julia> LG.add_edge!(g, 5, 1)
94-
julia> LG.add_edge!(g, 5, 2)
95-
julia> LG.add_edge!(g, 3, 6)
96-
julia> LG.add_edge!(g, 4, 6)
97-
julia> LG.add_edge!(g, 1, 3)
98-
julia> LG.add_edge!(g, 1, 4)
99-
julia> LG.add_edge!(g, 2, 3)
100-
julia> LG.add_edge!(g, 2, 4)
87+
julia> using Graphs, GraphsFlows
88+
89+
julia> g = Graphs.DiGraph(6)
90+
julia> Graphs.add_edge!(g, 5, 1)
91+
julia> Graphs.add_edge!(g, 5, 2)
92+
julia> Graphs.add_edge!(g, 3, 6)
93+
julia> Graphs.add_edge!(g, 4, 6)
94+
julia> Graphs.add_edge!(g, 1, 3)
95+
julia> Graphs.add_edge!(g, 1, 4)
96+
julia> Graphs.add_edge!(g, 2, 3)
97+
julia> Graphs.add_edge!(g, 2, 4)
10198
julia> cost = zeros(6,6)
10299
julia> cost[1,3] = 10.
103100
julia> cost[1,4] = 5.

docs/Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3-
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
4-
LightGraphsFlows = "2f5eb75a-258c-59e0-affc-f41c55f75335"
3+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
4+
GraphsFlows = "06909019-6f44-4949-96fc-b9d9aaa02889"
5+

docs/make.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using Documenter
2-
using LightGraphsFlows
3-
using LightGraphs
4-
const lg = LightGraphs
2+
using GraphsFlows
3+
using Graphs
54

65
makedocs(
7-
modules = [LightGraphsFlows],
6+
modules = [GraphsFlows],
87
format = Documenter.HTML(),
9-
sitename = "LightGraphsFlows",
8+
sitename = "GraphsFlows",
109
pages = Any[
1110
"Getting started" => "index.md",
1211
"Maxflow algorithms" => "maxflow.md",
@@ -19,6 +18,6 @@ makedocs(
1918
deploydocs(
2019
deps = nothing,
2120
make = nothing,
22-
repo = "github.com/JuliaGraphs/LightGraphsFlows.jl.git",
21+
repo = "github.com/JuliaGraphs/GraphsFlows.jl.git",
2322
versions = ["stable" => "v^", "v#.#", "dev" => "master"],
2423
)

docs/mkdocs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
site_name: LightGraphsFlows.jl
2-
repo_url: https://github.com/JuliaGraphs/LightGraphsFlows.jl
3-
site_description: Documentation for LightGraphsFlows, the JuliaGraphs package for flow and cut problems
1+
site_name: GraphsFlows.jl
2+
repo_url: https://github.com/JuliaGraphs/GraphsFlows.jl
3+
site_description: Documentation for GraphsFlows, the JuliaGraphs package for flow and cut problems
44
site_author: JuliaGraphs
55

66
theme: material

docs/src/index.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
# LightGraphsFlows.jl: flow algorithms for LightGraphs
1+
# GraphsFlows.jl: flow algorithms for Graphs.jl
22

33
```@meta
4-
CurrentModule = LightGraphsFlows
4+
CurrentModule = GraphsFlows
55
DocTestSetup = quote
6-
using LightGraphsFlows
7-
import LightGraphs
8-
const lg = LightGraphs
6+
using GraphsFlows
7+
import Graphs
98
end
109
```
1110

1211
```@autodocs
13-
Modules = [LightGraphsFlows]
14-
Pages = ["LightGraphsFlows.jl"]
12+
Modules = [GraphsFlows]
13+
Pages = ["GraphsFlows.jl"]
1514
Order = [:function, :type]
1615
```
1716

18-
This is the documentation page for `LightGraphsFlows`. In all pages, we assume
19-
LightGraphsFlows has been imported into scope and that LightGraphs is
20-
available with the alias `lg`:
17+
This is the documentation page for `GraphsFlows`. In all pages, we assume
18+
GraphsFlows has been imported into scope and that Graphs.jl has been imported.
2119

2220
```julia
23-
using LightGraphsFlows
24-
import LightGraphs
25-
const lg = LightGraphs
21+
using GraphsFlows
22+
import Graphs
2623
```

docs/src/maxflow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Max flow algorithms
22

33
```@autodocs
4-
Modules = [LightGraphsFlows]
4+
Modules = [GraphsFlows]
55
Pages = ["maxflow.jl", "boykov_kolmogorov.jl", "push_relabel.jl", "dinic.jl", "edmonds_karp.jl"]
66
Order = [:function, :type]
77
```

docs/src/mincost.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Min-cost flow
22

33
```@autodocs
4-
Modules = [LightGraphsFlows]
4+
Modules = [GraphsFlows]
55
Pages = ["mincost.jl"]
66
Order = [:function, :type]
77
```

docs/src/mincut.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Min-cut
22

33
```@autodocs
4-
Modules = [LightGraphsFlows]
4+
Modules = [GraphsFlows]
55
Pages = ["mincut.jl"]
66
Order = [:function, :type]
77
```

docs/src/multiroute.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Multi-route flow
22

33
```@autodocs
4-
Modules = [LightGraphsFlows]
4+
Modules = [GraphsFlows]
55
Pages = ["multiroute_flow.jl", "ext_multiroute_flow.jl", "kishimoto.jl"]
66
Order = [:function, :type]
77
```

src/LightGraphsFlows.jl renamed to src/GraphsFlows.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
module LightGraphsFlows
1+
module GraphsFlows
22

3-
using LightGraphs
4-
const lg = LightGraphs
3+
using Graphs
54

65
using SimpleTraits: @traitfn, @traitimpl
76
import SimpleTraits

src/boykov_kolmogorov.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ Min-Cut/Max-Flow Algorithms for Energy Minimization in Vision.
1717
function boykov_kolmogorov_impl end
1818
# see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
1919
@traitfn function boykov_kolmogorov_impl(
20-
residual_graph::AG::lg.IsDirected, # the input graph
20+
residual_graph::AG::Graphs.IsDirected, # the input graph
2121
source::Integer, # the source vertex
2222
target::Integer, # the target vertex
2323
capacity_matrix::AbstractMatrix{T} # edge flow capacities
24-
) where {T, U, AG<:lg.AbstractGraph{U}}
25-
n = lg.nv(residual_graph)
24+
) where {T, U, AG<:Graphs.AbstractGraph{U}}
25+
n = Graphs.nv(residual_graph)
2626

2727
flow = 0
2828
flow_matrix = zeros(T, n, n)
@@ -54,20 +54,20 @@ end
5454

5555
# see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
5656
@traitfn function find_path!(
57-
residual_graph::AG::lg.IsDirected, # the input graph
57+
residual_graph::AG::Graphs.IsDirected, # the input graph
5858
source::Integer, # the source vertex
5959
target::Integer, # the target vertex
6060
flow_matrix::AbstractMatrix, # the current flow matrix
6161
capacity_matrix::AbstractMatrix, # edge flow capacities
6262
PARENT::Vector, # parent table
6363
TREE::Vector, # tree table
6464
A::Vector # active set
65-
) where {T, AG<:lg.AbstractGraph{T}}
65+
) where {T, AG<:Graphs.AbstractGraph{T}}
6666
tree_cap(p, q) = TREE[p] == one(T) ? capacity_matrix[p, q] - flow_matrix[p, q] :
6767
capacity_matrix[q, p] - flow_matrix[q, p]
6868
while !isempty(A)
6969
p = last(A)
70-
for q in lg.neighbors(residual_graph, p)
70+
for q in Graphs.neighbors(residual_graph, p)
7171
if tree_cap(p, q) > 0
7272
if TREE[q] == zero(T)
7373
TREE[q] = TREE[p]
@@ -147,7 +147,7 @@ function augment!(
147147
end
148148

149149
@traitfn function adopt!(
150-
residual_graph::AG::lg.IsDirected, # the input graph
150+
residual_graph::AG::Graphs.IsDirected, # the input graph
151151
source::Integer, # the source vertex
152152
target::Integer, # the target vertex
153153
flow_matrix::AbstractMatrix, # the current flow matrix
@@ -156,14 +156,14 @@ end
156156
TREE::Vector, # tree table
157157
A::Vector, # active set
158158
O::Vector # orphan set
159-
) where {T, AG<:lg.AbstractGraph{T}}
159+
) where {T, AG<:Graphs.AbstractGraph{T}}
160160
tree_cap(p, q) = TREE[p] == 1 ? capacity_matrix[p, q] - flow_matrix[p, q] :
161161
capacity_matrix[q, p] - flow_matrix[q, p]
162162
while !isempty(O)
163163
p = pop!(O)
164164
# try to find parent that is not an orphan
165165
parent_found = false
166-
for q in lg.neighbors(residual_graph, p)
166+
for q in Graphs.neighbors(residual_graph, p)
167167
if TREE[q] == TREE[p] && tree_cap(q, p) > 0
168168
# check if "origin" is either source or target
169169
o = q
@@ -180,7 +180,7 @@ end
180180

181181
if !parent_found
182182
# scan all neighbors and make the orphan a free node
183-
for q in lg.neighbors(residual_graph, p)
183+
for q in Graphs.neighbors(residual_graph, p)
184184
if TREE[q] == TREE[p]
185185
if tree_cap(q, p) > 0
186186
pushfirst!(A, q)

src/dinic.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ Return the value of the maximum flow as well as the final flow matrix.
88
"""
99
function dinic_impl end
1010
@traitfn function dinic_impl(
11-
residual_graph::::lg.IsDirected, # the input graph
11+
residual_graph::::Graphs.IsDirected, # the input graph
1212
source::Integer, # the source vertex
1313
target::Integer, # the target vertex
1414
capacity_matrix::AbstractMatrix{T} # edge flow capacities
1515
) where {T}
16-
n = lg.nv(residual_graph) # number of vertexes
16+
n = Graphs.nv(residual_graph) # number of vertexes
1717
flow_matrix = zeros(T, n, n) # initialize flow matrix
1818
P = zeros(Int, n) # Sharable parent vector
1919

@@ -37,14 +37,14 @@ Like `blocking_flow`, but requires a preallocated parent vector `P`.
3737
"""
3838
function blocking_flow! end
3939
@traitfn function blocking_flow!(
40-
residual_graph::::lg.IsDirected, # the input graph
40+
residual_graph::::Graphs.IsDirected, # the input graph
4141
source::Integer, # the source vertex
4242
target::Integer, # the target vertex
4343
capacity_matrix::AbstractMatrix{T}, # edge flow capacities
4444
flow_matrix::AbstractMatrix, # the current flow matrix
4545
P::AbstractVector{Int} # Parent vector to store Level Graph
4646
) where {T}
47-
n = lg.nv(residual_graph) # number of vertexes
47+
n = Graphs.nv(residual_graph) # number of vertexes
4848
fill!(P, -1)
4949
P[source] = -2
5050

@@ -53,7 +53,7 @@ function blocking_flow! end
5353

5454
while length(Q) > 0 # Construct the Level Graph using BFS
5555
u = pop!(Q)
56-
for v in lg.outneighbors(residual_graph, u)
56+
for v in Graphs.outneighbors(residual_graph, u)
5757
if P[v] == -1 && capacity_matrix[u, v] > flow_matrix[u, v]
5858
P[v] = u
5959
pushfirst!(Q, v)
@@ -65,7 +65,7 @@ function blocking_flow! end
6565

6666
total_flow = 0
6767

68-
for bv in lg.inneighbors(residual_graph, target) # Trace all possible routes to source
68+
for bv in Graphs.inneighbors(residual_graph, target) # Trace all possible routes to source
6969
flow = typemax(T)
7070
v = target
7171
u = bv
@@ -104,7 +104,7 @@ matrix `flow_matrix`and then backtrack from `target` to `source`,
104104
augmenting flow along all possible paths.
105105
"""
106106
blocking_flow(
107-
residual_graph::lg.AbstractGraph, # the input graph
107+
residual_graph::Graphs.AbstractGraph, # the input graph
108108
source::Integer, # the source vertex
109109
target::Integer, # the target vertex
110110
capacity_matrix::AbstractMatrix, # edge flow capacities
@@ -115,4 +115,4 @@ blocking_flow(
115115
target,
116116
capacity_matrix,
117117
flow_matrix,
118-
zeros(Int, lg.nv(residual_graph)))
118+
zeros(Int, Graphs.nv(residual_graph)))

0 commit comments

Comments
 (0)