22"""
33MatchingLMO{G}(g::Graphs)
44
5- Return a vector v corresponding to edges(g), where if v[i] = 1,
6- the edge i is in the maximum weight matching, and if v[i] = 0, the edge i is not in the matching.
5+ Return an incidence vector v of the edges of `g`, ordered as `edges(g)` for a minimum-weight matching.
76"""
87struct MatchingLMO{G} <: FrankWolfe.LinearMinimizationOracle
98 graph:: G
@@ -16,16 +15,20 @@ function FrankWolfe.compute_extreme_point(
1615 kwargs... ,
1716) where {M}
1817 N = length (direction)
19- v = spzeros (N)
18+ if v === nothing
19+ v = spzeros (N)
20+ else
21+ v .= 0
22+ end
2023 iter = collect (edges (lmo. graph))
2124 g = SimpleGraphFromIterator (iter)
2225 l = nv (g)
2326 add_vertices! (g, l)
2427 w = Dict {typeof(iter[1]),typeof(direction[1])} ()
2528 for i in 1 : N
2629 add_edge! (g, src (iter[i]) + l, dst (iter[i]) + l)
27- w[iter[i]] = - direction[i]
28- w[Edge (src (iter[i]) + l, dst (iter[i]) + l)] = - direction[i]
30+ w[iter[i]] = direction[i]
31+ w[Edge (src (iter[i]) + l, dst (iter[i]) + l)] = direction[i]
2932 end
3033
3134 for i in 1 : l
5053"""
5154PerfectMatchingLMO{G}(g::Graphs)
5255
53- Return a vector v corresponding to edges(g), where if v[i] = 1,
54- the edge i is in the matching, and if v[i] = 0, the edge i is not in the matching.
55- If there is not possible perfect matching, all elements of v are set to 0.
56+ Return the incidence vector of a minimum-weight perfect matching, `v` is ordered as `edges(g)`.
57+ The constructor verifies that the graph admits a perfect matching.
5658"""
5759struct PerfectMatchingLMO{G} <: FrankWolfe.LinearMinimizationOracle
5860 graph:: G
5961end
6062
63+ function PerfectMatchingLMO (graph:: G ) where {G}
64+ @assert nv (graph) % 2 == 0
65+ return PerfectMatchingLMO {G} (graph)
66+ end
67+
6168function FrankWolfe. compute_extreme_point (
6269 lmo:: PerfectMatchingLMO ,
6370 direction:: M ;
6471 v= nothing ,
6572 kwargs... ,
6673) where {M}
6774 N = length (direction)
68- v = spzeros (N)
69- if (nv (lmo. graph) % 2 != 0 )
70- return v
75+ if v === nothing
76+ v = spzeros (N)
77+ else
78+ v .= 0
7179 end
7280 iter = collect (Graphs. edges (lmo. graph))
7381 w = Dict {typeof(iter[1]),typeof(direction[1])} ()
0 commit comments