Back

max-weight-matching (clj)

(source)

function

(max-weight-matching edges opts) (max-weight-matching edges)
Compute a maximum-weighted matching of G. A matching is a subset of edges in which no node occurs more than once. The weight of a matching is the sum of the weights of its edges. A maximal matching cannot add more edges and still be a matching. The cardinality of a matching is the number of matched edges. Parameters ---------- `edges` : Edges of an undirected graph. A sequence of tuples [i j wt] describing an undirected edge between vertex i and vertex j with weight wt. There is at most one edge between any two vertices; no vertex has an edge to itself. Vertices are identified by consecutive, non-negative integers. `opts` : option map Options ---------- max-cardinality: boolean, optional (default=false) If max-cardinality is true, compute the maximum-cardinality matching with maximum weight among all maximum-cardinality matchings. check-optimum: boolean, optional (default=false) Check optimality of solution before returning; only works on integer weights. Returns ------- matching : collection A maximal matching of the graph in the form of a collection of unique vertices pairs. Notes ----- This function takes time O(number_of_nodes ** 3). If all edge weights are integers, the algorithm uses only integer computations. If floating point weights are used, the algorithm could return a slightly suboptimal matching due to numeric precision errors. This method is based on the "blossom" method for finding augmenting paths and the "primal-dual" method for finding a matching of maximum weight, both methods invented by Jack Edmonds [1]_. References ---------- .. [1] "Efficient Algorithms for Finding Maximum Matching in Graphs", Zvi Galil, ACM Computing Surveys, 1986.

Examples