Skip to content

Commit 8f64632

Browse files
authored
removed GLPK dep, solver mandatory (#4)
1 parent ae1da32 commit 8f64632

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed

REQUIRE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ LightGraphs 0.9.0
33
JuMP 0.13.2
44
MatrixDepot
55
BlossomV 0.1
6-
GLPKMathProgInterface 0.3.2

src/LightGraphsMatching.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ end
2424
import BlossomV
2525
include("blossomv.jl")
2626

27-
using GLPKMathProgInterface: GLPKSolverMIP
28-
2927
using JuMP
28+
using MathProgBase: AbstractMathProgSolver
3029
include("lp.jl")
3130
include("maximum_weight_matching.jl")
3231

src/lp.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@ The returned object is of type `MatchingResult`.
2020
"""
2121
function maximum_weight_maximal_matching end
2222

23-
function maximum_weight_maximal_matching(g::Graph, w::Dict{Edge,T}, cutoff; solver = GLPKSolverMIP) where {T<:Real}
23+
function maximum_weight_maximal_matching(g::Graph, solver::AbstractMathProgSolver, w::Dict{Edge,T}, cutoff::R) where {T<:Real, R<:Real}
2424
wnew = Dict{Edge,T}()
2525
for (e,x) in w
2626
if x >= cutoff
2727
wnew[e] = x
2828
end
2929
end
30-
31-
return maximum_weight_maximal_matching(g, wnew)
30+
return maximum_weight_maximal_matching(g, solver, wnew)
3231
end
3332

3433

35-
function maximum_weight_maximal_matching(g::Graph, w::Dict{Edge,T}; solver = GLPKSolverMIP) where {T<:Real}
34+
function maximum_weight_maximal_matching(g::Graph, solver::AbstractMathProgSolver, w::Dict{Edge,T}) where {T<:Real}
3635
# TODO support for graphs with zero degree nodes
3736
# TODO apply separately on each connected component
3837
bpmap = bipartite_map(g)
@@ -51,7 +50,7 @@ function maximum_weight_maximal_matching(g::Graph, w::Dict{Edge,T}; solver = GLP
5150
edgemap[reverse(e)] = nedg
5251
end
5352

54-
model = Model(solver=solver())
53+
model = Model(solver=solver)
5554
@variable(model, x[1:length(w)] >= 0)
5655

5756
for i in v1

src/maximum_weight_matching.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ Returns MatchingResult containing:
2222
function maximum_weight_matching end
2323

2424
function maximum_weight_matching(g::Graph,
25-
w::Dict{Edge,T} = Dict{Edge,Int64}(i => 1 for i in collect(edges(g)));
26-
solver = GLPKSolverMIP) where {T <:Real}
25+
solver::AbstractMathProgSolver,
26+
w::Dict{Edge,T} = Dict{Edge,Int64}(i => 1 for i in collect(edges(g)))) where {T <:Real}
2727

28-
model = Model(solver = solver())
28+
model = Model(solver = solver)
2929
n = nv(g)
3030
edge_list = collect(edges(g))
3131

test/REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cbc

test/runtests.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ include("../src/LightGraphsMatching.jl")
22
using LightGraphs
33
using LightGraphsMatching
44
using Base.Test
5+
using Cbc: CbcSolver
56

67
g =CompleteBipartiteGraph(2,2)
78
w =Dict{Edge,Float64}()
89
w[Edge(1,3)] = 10.
910
w[Edge(1,4)] = 1.
1011
w[Edge(2,3)] = 2.
1112
w[Edge(2,4)] = 11.
12-
match = maximum_weight_maximal_matching(g,w)
13+
match = maximum_weight_maximal_matching(g, CbcSolver(), w)
1314
@test match.weight == 21
1415
@test match.mate[1] == 3
1516
@test match.mate[3] == 1
@@ -22,7 +23,7 @@ w[Edge(1,3)] = 10
2223
w[Edge(1,4)] = 0.5
2324
w[Edge(2,3)] = 11
2425
w[Edge(2,4)] = 1
25-
match = maximum_weight_maximal_matching(g,w)
26+
match = maximum_weight_maximal_matching(g, CbcSolver(), w)
2627
@test match.weight == 11.5
2728
@test match.mate[1] == 4
2829
@test match.mate[4] == 1
@@ -37,7 +38,7 @@ w[Edge(2,3)] = 11
3738
w[Edge(2,4)] = 1
3839
w[Edge(2,5)] = -1
3940
w[Edge(2,6)] = -1
40-
match = maximum_weight_maximal_matching(g,w,0)
41+
match = maximum_weight_maximal_matching(g,CbcSolver(),w,0)
4142
@test match.weight == 11.5
4243
@test match.mate[1] == 4
4344
@test match.mate[4] == 1
@@ -52,7 +53,7 @@ w[Edge(2,5)] = 11
5253
w[Edge(1,6)] = 1
5354
w[Edge(1,5)] = -1
5455

55-
match = maximum_weight_maximal_matching(g,w,0)
56+
match = maximum_weight_maximal_matching(g,CbcSolver(),w,0)
5657
@test match.weight == 12
5758
@test match.mate[1] == 6
5859
@test match.mate[2] == 5
@@ -64,11 +65,11 @@ match = maximum_weight_maximal_matching(g,w,0)
6465
g = CompleteGraph(3)
6566
w =Dict{Edge,Float64}()
6667
w[Edge(1,2)] = 1
67-
@test_throws ErrorException maximum_weight_matching(g,w)
68+
@test_throws ErrorException maximum_weight_matching(g,CbcSolver(),w)
6869

6970
w[Edge(3,2)] = 1
7071
w[Edge(1,3)] = 1
71-
match = maximum_weight_matching(g,w)
72+
match = maximum_weight_matching(g,CbcSolver(),w)
7273
@test match.weight == 1
7374

7475

@@ -80,7 +81,7 @@ add_edge!(g, 2,4)
8081
w[Edge(1,3)] = 1
8182
w[Edge(1,4)] = 3
8283
w[Edge(2,4)] = 1
83-
match = maximum_weight_matching(g,w)
84+
match = maximum_weight_matching(g,CbcSolver(),w)
8485
@test match.weight == 3
8586
@test match.mate[1] == 4
8687
@test match.mate[2] == -1
@@ -92,7 +93,7 @@ add_edge!(g, 1,2)
9293
add_edge!(g, 2,3)
9394
add_edge!(g, 3,1)
9495
add_edge!(g, 3,4)
95-
match = maximum_weight_matching(g)
96+
match = maximum_weight_matching(g,CbcSolver())
9697
@test match.weight == 2
9798
@test match.mate[1] == 2
9899
@test match.mate[2] == 1
@@ -104,7 +105,7 @@ w[Edge(1,2)] = 1
104105
w[Edge(2,3)] = 1
105106
w[Edge(1,3)] = 1
106107
w[Edge(3,4)] = 1
107-
match = maximum_weight_matching(g,w)
108+
match = maximum_weight_matching(g,CbcSolver(), w)
108109
@test match.weight == 2
109110
@test match.mate[1] == 2
110111
@test match.mate[2] == 1
@@ -115,7 +116,7 @@ w[Edge(1,2)] = 1
115116
w[Edge(2,3)] = 1
116117
w[Edge(1,3)] = 5
117118
w[Edge(3,4)] = 1
118-
match = maximum_weight_matching(g,w)
119+
match = maximum_weight_matching(g,CbcSolver(),w)
119120
@test match.weight == 5
120121
@test match.mate[1] == 3
121122
@test match.mate[2] == -1

0 commit comments

Comments
 (0)