Stay organized with collections
Save and categorize content based on your preferences.
C++ Reference: class MinCostPerfectMatching
Note: This documentation is automatically generated.
Given an undirected graph with costs on each edges, this class allows to
compute a perfect matching with minimum cost. A matching is a set of disjoint
pairs of nodes connected by an edge. The matching is perfect if all nodes are
matched to each others.
Adds an undirected edges between the two given nodes.
For now we only accept non-negative cost.
TODO(user): We can easily shift all costs if negative costs are needed.
Important: The algorithm supports multi-edges, but it will be slower. So it
is better to only add one edge with a minimum cost between two nodes. In
particular, do not add both AddEdge(a, b, cost) and AddEdge(b, a, cost).
TODO(user): We could just presolve them away.
Resets the class for a new graph.
TODO(user): Eventually, we may support incremental Solves(). Or at least
memory reuse if one wants to solve many problems in a row.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-06 UTC."],[[["The `MinCostPerfectMatching` class in C++ helps find the lowest-cost perfect matching in an undirected graph, where a perfect matching pairs all nodes with disjoint edges."],["It utilizes the `AddEdgeWithCost` method to define the graph's edges and their associated costs, preferably avoiding redundant or multi-edges for optimal performance."],["After using `Solve`, you can obtain the optimal cost with `OptimalCost` and the node pairings via `Match` or `Matches`, given the solution is optimal."],["The class requires specifying the number of nodes initially and allows resetting for new graph computations using `Reset`."]]],[]]