@@ -13,7 +13,8 @@ Edges in `g` not present in `w` will not be considered for the matching.
13
13
You can use the `algorithm` argument to specify the algorithm to use.
14
14
15
15
A `cutoff` argument can be given, to reduce the computational time by
16
- excluding edges with weights higher than the cutoff.
16
+ excluding edges with weights higher than the cutoff (effective only for some algorithms,
17
+ not for the default `LEMONMWPMAlgorithm`).
17
18
18
19
When the weights are non-integer types, the keyword argument `tmaxscale` can be used to
19
20
scale the weights to integer values.
@@ -56,18 +57,27 @@ If BlossomV.jl does not work on your system,
56
57
consider using the LEMONGraphs.jl algorithm instead (the default algorithm),
57
58
which we distribute precompiled on all platforms.
58
59
59
- See also: [`minimum_weight_perfect_matching`](@ref)
60
+ See also: [`minimum_weight_perfect_matching`](@ref), [`LEMONMWPMAlgorithm`](@ref)
60
61
"""
61
62
struct BlossomVAlgorithm <: AbstractMinimumWeightPerfectMatchingAlgorithm end
62
63
64
+ """
65
+ LEMONMWPMAlgorithm()
66
+
67
+ Use the LEMON C++ implementation of minimum weight perfect matching.
68
+
69
+ See also: [`minimum_weight_perfect_matching`](@ref), [`BlossomVAlgorithm`](@ref)
70
+ """
71
+ struct LEMONMWPMAlgorithm <: AbstractMinimumWeightPerfectMatchingAlgorithm end
72
+
63
73
function minimum_weight_perfect_matching (
64
74
g:: Graph , w:: Dict{E,U}
65
75
) where {U<: Integer ,E<: Edge }
66
- return minimum_weight_perfect_matching (g, w, BlossomVAlgorithm ())
76
+ return minimum_weight_perfect_matching (g, w, LEMONMWPMAlgorithm ())
67
77
end
68
78
69
79
function minimum_weight_perfect_matching (
70
- g:: Graph , w:: Dict{E,U} , cutoff, algorithm:: AbstractMinimumWeightPerfectMatchingAlgorithm = BlossomVAlgorithm (); kws...
80
+ g:: Graph , w:: Dict{E,U} , cutoff, algorithm:: AbstractMinimumWeightPerfectMatchingAlgorithm = LEMONMWPMAlgorithm (); kws...
71
81
) where {U<: Real ,E<: Edge }
72
82
wnew = Dict {E,U} ()
73
83
for (e, c) in w
@@ -79,7 +89,7 @@ function minimum_weight_perfect_matching(
79
89
end
80
90
81
91
function minimum_weight_perfect_matching (
82
- g:: Graph , w:: Dict{E,U} , algorithm:: AbstractMinimumWeightPerfectMatchingAlgorithm = BlossomVAlgorithm (); tmaxscale= 10.0
92
+ g:: Graph , w:: Dict{E,U} , algorithm:: AbstractMinimumWeightPerfectMatchingAlgorithm = LEMONMWPMAlgorithm (); tmaxscale= 10.0
83
93
) where {U<: AbstractFloat ,E<: Edge }
84
94
wnew = Dict {E,Int32} ()
85
95
cmax = maximum (values (w))
@@ -95,7 +105,7 @@ function minimum_weight_perfect_matching(
95
105
for i in 1 : nv (g)
96
106
j = match. mate[i]
97
107
if j > i
98
- weight += w[ E (i, j)]
108
+ weight += get (w, E (i, j), zero (U))
99
109
end
100
110
end
101
111
return MatchingResult (weight, match. mate)
@@ -119,3 +129,10 @@ function minimum_weight_perfect_matching(g::Graph, w::Dict{E,U}, ::BlossomVAlgor
119
129
end
120
130
return MatchingResult (totweight, mate)
121
131
end
132
+
133
+ function minimum_weight_perfect_matching (g:: Graph , w:: Dict{E,U} , :: LEMONMWPMAlgorithm ) where {U<: Integer ,E<: Edge }
134
+ max = 2 * abs (maximum (values (w)))
135
+ weights = [- get (w, e, max) for e in edges (g)]
136
+ totweight, mate = LEMONGraphs. maxweightedperfectmatching (g, weights)
137
+ return MatchingResult (- totweight, mate)
138
+ end
0 commit comments