@@ -13,7 +13,8 @@ Edges in `g` not present in `w` will not be considered for the matching.
1313You can use the `algorithm` argument to specify the algorithm to use.
1414
1515A `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`).
1718
1819When the weights are non-integer types, the keyword argument `tmaxscale` can be used to
1920scale the weights to integer values.
@@ -56,18 +57,27 @@ If BlossomV.jl does not work on your system,
5657consider using the LEMONGraphs.jl algorithm instead (the default algorithm),
5758which we distribute precompiled on all platforms.
5859
59- See also: [`minimum_weight_perfect_matching`](@ref)
60+ See also: [`minimum_weight_perfect_matching`](@ref), [`LEMONMWPMAlgorithm`](@ref)
6061"""
6162struct BlossomVAlgorithm <: AbstractMinimumWeightPerfectMatchingAlgorithm end
6263
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+
6373function minimum_weight_perfect_matching (
6474 g:: Graph , w:: Dict{E,U}
6575) where {U<: Integer ,E<: Edge }
66- return minimum_weight_perfect_matching (g, w, BlossomVAlgorithm ())
76+ return minimum_weight_perfect_matching (g, w, LEMONMWPMAlgorithm ())
6777end
6878
6979function 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...
7181) where {U<: Real ,E<: Edge }
7282 wnew = Dict {E,U} ()
7383 for (e, c) in w
@@ -79,7 +89,7 @@ function minimum_weight_perfect_matching(
7989end
8090
8191function 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
8393) where {U<: AbstractFloat ,E<: Edge }
8494 wnew = Dict {E,Int32} ()
8595 cmax = maximum (values (w))
@@ -95,7 +105,7 @@ function minimum_weight_perfect_matching(
95105 for i in 1 : nv (g)
96106 j = match. mate[i]
97107 if j > i
98- weight += w[ E (i, j)]
108+ weight += get (w, E (i, j), zero (U))
99109 end
100110 end
101111 return MatchingResult (weight, match. mate)
@@ -119,3 +129,10 @@ function minimum_weight_perfect_matching(g::Graph, w::Dict{E,U}, ::BlossomVAlgor
119129 end
120130 return MatchingResult (totweight, mate)
121131end
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