Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions src/GraphsMatching.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ using SparseArrays: spzeros
using JuMP
using MathOptInterface
const MOI = MathOptInterface
import BlossomV # 'using BlossomV' leads to naming conflicts with JuMP
using BlossomV: BlossomV # 'using BlossomV' leads to naming conflicts with JuMP
using Hungarian

export MatchingResult, maximum_weight_matching, maximum_weight_maximal_matching, minimum_weight_perfect_matching, HungarianAlgorithm, LPAlgorithm
export MatchingResult,
weight,
is_matched_vertex,
matching_vertex,
matching_vertices,
matched_edges,
maximum_weight_matching,
maximum_weight_maximal_matching,
minimum_weight_perfect_matching,
HungarianAlgorithm,
LPAlgorithm

"""
struct MatchingResult{U}
Expand All @@ -30,6 +40,42 @@ struct MatchingResult{U<:Real}
mate::Vector{Int}
end

"""
weight(m::MatchingResult)

returns the total weight of the matching
"""
weight(m::MatchingResult) = m.weight

"""
is_matched_vertex(m::MatchingResult, u)

returns true if vertex `u` is matched with another vertex
"""
is_matched_vertex(m::MatchingResult, u) = (m.mate[u] != -1)

"""
matching_vertex(m::MatchingResult, u)

returns the vertex matched with `u` (-1 if `u` is not matched)
"""
matching_vertex(m::MatchingResult, u) = m.mate[u]

"""
matching_vertices(m::MatchingResult)

returns a list of the matching vertices (-1 if the vertex is not matched)
"""
matching_vertices(m::MatchingResult) = m.mate

"""
matching_vertex(m::MatchingResult, u)

returns a list of the matched edges
"""
matched_edges(m::MatchingResult) =
[Edge(u, v) for (u, v) in enumerate(matching_vertices(m)) if (u < v)]

include("lp.jl")
include("maximum_weight_matching.jl")
include("blossomv.jl")
Expand Down
Loading