Skip to content

Commit 17a8fd6

Browse files
authored
Docs (#8)
* added docs * approx for float comparison * readme * skipped line ignore * updated packages, no patch specification
1 parent 6765fbf commit 17a8fd6

File tree

6 files changed

+88
-17
lines changed

6 files changed

+88
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.jl.cov
22
*.jl.*.cov
33
*.jl.mem
4+
docs/build

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,47 @@
66

77
[![codecov](https://codecov.io/gh/JuliaGraphs/LightGraphsMatching.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaGraphs/LightGraphsMatching.jl)
88

9+
Matching algorithms on top of [LightGraphs](https://github.com/JuliaGraphs/LightGraphs).
10+
11+
## Usage
12+
13+
The results of any matching is returned as a `MatchingResult` struct
14+
containing the `mate` and `weight` fields.
15+
16+
### Perfect matching
17+
18+
```julia
19+
g =CompleteGraph(4)
20+
w =Dict{Edge,Float64}()
21+
w[Edge(1,3)] = 10
22+
w[Edge(1,4)] = 0.5
23+
w[Edge(2,3)] = 11
24+
w[Edge(2,4)] = 2
25+
w[Edge(1,2)] = 100
26+
27+
# find the perfect matching of minimum weight
28+
match = minimum_weight_perfect_matching(g, w, 50)
29+
# match.mate[1] == 4
30+
# match.mate[4] == 1
31+
# match.mate[2] == 3
32+
# match.mate[3] == 2
33+
# match.weight ≈ 11.5
34+
```
35+
36+
### Maximum weight matching
37+
38+
A maximum weight matching is solved as a Linear Programming
39+
problem and requires a LP solver respecting the [MathProgBase](https://github.com/JuliaOpt/MathProgBase.jl) solver
40+
interface. See MathProgBase
41+
[documentation](http://mathprogbasejl.readthedocs.io/en/latest/solvers.html) for more details.
42+
43+
```julia
44+
using Cbc: CbcSolver #import a LP solver
45+
g = CompleteGraph(3)
46+
w = zeros(3,3)
47+
w[1,2] = 1
48+
w[3,2] = 1
49+
w[1,3] = 1
50+
match = maximum_weight_matching(g,CbcSolver(),w)
51+
# match.weight ≈ 1
52+
```

REQUIRE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
julia 0.6
2-
LightGraphs 0.9.0
3-
JuMP 0.13.2
2+
LightGraphs 0.12
3+
JuMP 0.13
44
MatrixDepot
5-
BlossomV 0.1
5+
BlossomV 0.3

docs/make.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Documenter
2+
using LightGraphsMatching
3+
import LightGraphs; const lg = LightGraphs
4+
5+
makedocs(
6+
modules = [LightGraphsMatching],
7+
format = :html,
8+
sitename = "LightGraphsMatching",
9+
pages = Any[
10+
"Getting started" => "index.md",
11+
]
12+
)

docs/src/index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
```@meta
2+
CurrentModule = LightGraphsMatching
3+
DocTestSetup = quote
4+
using LightGraphsMatching
5+
import LightGraphs
6+
const lg = LightGraphs
7+
end
8+
```
9+
10+
```@autodocs
11+
Modules = [LightGraphsMatching]
12+
Pages = ["LightGraphsMatching.jl", "maximum_weight_matching.jl", "lp.jl", "blossomv.jl"]
13+
Order = [:function, :type]
14+
```

test/runtests.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ w = [
2626
]
2727
match = maximum_weight_matching(g, CbcSolver(), w)
2828
@test match.mate[1] == 3
29-
@test match.weight == 3
29+
@test match.weight 3
3030

3131
g = CompleteBipartiteGraph(2,2)
3232
w = zeros(4,4)
@@ -35,7 +35,7 @@ w[1,4] = 1.
3535
w[2,3] = 2.
3636
w[2,4] = 11.
3737
match = maximum_weight_maximal_matching(g, CbcSolver(), w)
38-
@test match.weight == 21
38+
@test match.weight 21
3939
@test match.mate[1] == 3
4040
@test match.mate[3] == 1
4141
@test match.mate[2] == 4
@@ -48,7 +48,7 @@ w[1,4] = 0.5
4848
w[2,3] = 11
4949
w[2,4] = 1
5050
match = maximum_weight_maximal_matching(g, CbcSolver(), w)
51-
@test match.weight == 11.5
51+
@test match.weight 11.5
5252
@test match.mate[1] == 4
5353
@test match.mate[4] == 1
5454
@test match.mate[2] == 3
@@ -63,7 +63,7 @@ w[2,4] = 1
6363
w[2,5] = -1
6464
w[2,6] = -1
6565
match = maximum_weight_maximal_matching(g,CbcSolver(),w,0)
66-
@test match.weight == 11.5
66+
@test match.weight 11.5
6767
@test match.mate[1] == 4
6868
@test match.mate[4] == 1
6969
@test match.mate[2] == 3
@@ -78,7 +78,7 @@ w[1,6] = 1
7878
w[1,5] = -1
7979

8080
match = maximum_weight_maximal_matching(g,CbcSolver(),w,0)
81-
@test match.weight == 12
81+
@test match.weight 12
8282
@test match.mate[1] == 6
8383
@test match.mate[2] == 5
8484
@test match.mate[3] == -1
@@ -92,7 +92,7 @@ w[1,2] = 1
9292
w[3,2] = 1
9393
w[1,3] = 1
9494
match = maximum_weight_matching(g,CbcSolver(),w)
95-
@test match.weight == 1
95+
@test match.weight 1
9696

9797

9898
g = Graph(4)
@@ -106,7 +106,7 @@ w[1,4] = 3
106106
w[2,4] = 1
107107

108108
match = maximum_weight_matching(g,CbcSolver(),w)
109-
@test match.weight == 3
109+
@test match.weight 3
110110
@test match.mate[1] == 4
111111
@test match.mate[2] == -1
112112
@test match.mate[3] == -1
@@ -118,7 +118,7 @@ add_edge!(g, 2,3)
118118
add_edge!(g, 3,1)
119119
add_edge!(g, 3,4)
120120
match = maximum_weight_matching(g,CbcSolver())
121-
@test match.weight == 2
121+
@test match.weight 2
122122
@test match.mate[1] == 2
123123
@test match.mate[2] == 1
124124
@test match.mate[3] == 4
@@ -131,7 +131,7 @@ w[1,3] = 1
131131
w[3,4] = 1
132132

133133
match = maximum_weight_matching(g,CbcSolver(), w)
134-
@test match.weight == 2
134+
@test match.weight 2
135135
@test match.mate[1] == 2
136136
@test match.mate[2] == 1
137137
@test match.mate[3] == 4
@@ -144,7 +144,7 @@ w[1,3] = 5
144144
w[3,4] = 1
145145

146146
match = maximum_weight_matching(g,CbcSolver(),w)
147-
@test match.weight == 5
147+
@test match.weight 5
148148
@test match.mate[1] == 3
149149
@test match.mate[2] == -1
150150
@test match.mate[3] == 1
@@ -169,7 +169,7 @@ match = minimum_weight_perfect_matching(g, w)
169169
@test match.mate[2] == 1
170170
@test match.mate[3] == 4
171171
@test match.mate[4] == 3
172-
@test match.weight == 600
172+
@test match.weight 600
173173

174174
w = Dict(
175175
Edge(1, 2) => 500,
@@ -184,7 +184,7 @@ match = minimum_weight_perfect_matching(g, w)
184184
@test match.mate[2] == 4
185185
@test match.mate[3] == 1
186186
@test match.mate[4] == 2
187-
@test match.weight == 1400
187+
@test match.weight 1400
188188

189189
g =CompleteBipartiteGraph(2,2)
190190
w =Dict{Edge,Float64}()
@@ -198,7 +198,7 @@ match = minimum_weight_perfect_matching(g, w)
198198
@test match.mate[4] == 1
199199
@test match.mate[2] == 3
200200
@test match.mate[3] == 2
201-
@test match.weight == -11.5
201+
@test match.weight -11.5
202202

203203

204204
g =CompleteGraph(4)
@@ -214,4 +214,4 @@ match = minimum_weight_perfect_matching(g, w, 50)
214214
@test match.mate[4] == 1
215215
@test match.mate[2] == 3
216216
@test match.mate[3] == 2
217-
@test match.weight == 11.5
217+
@test match.weight 11.5

0 commit comments

Comments
 (0)