44 #include <unordered_set>
48 using namespace matching_blossom;
50 template<
typename TWeight>
64 std::unordered_set<edge>& matching) {
65 return doCall(G, weights, matching);
76 return doCall(GA, matching);
89 std::unordered_set<edge> matching;
90 bool result = minimumWeightPerfectMatching(G, weights, matching);
91 TWeight weight = matchingWeight(matching, weights);
92 return std::make_tuple(result, weight);
103 std::unordered_set<edge> matching;
104 bool result = minimumWeightPerfectMatching(GA, matching);
105 TWeight weight = matchingWeight(matching, GA);
106 return std::make_tuple(result, weight);
118 std::unordered_set<edge>& matching) {
120 copyWeights(G, weights, invertedWeights,
true);
121 return doCall(G, invertedWeights, matching);
134 copyWeights(G, GA, weights,
true);
135 return doCall(G, weights, matching);
148 std::unordered_set<edge> matching;
149 bool result = maximumWeightPerfectMatching(G, weights, matching);
150 TWeight weight = matchingWeight(matching, weights);
151 return std::make_tuple(result, weight);
162 std::unordered_set<edge> matching;
163 bool result = maximumWeightPerfectMatching(GA, matching);
164 TWeight weight = matchingWeight(matching, GA);
165 return std::make_tuple(result, weight);
176 std::unordered_set<edge>& matching) {
177 doMaximumWeightMatching(G, weights, matching);
187 doMaximumWeightMatching(GA.
constGraph(), GA, matching);
198 std::unordered_set<edge> matching;
199 maximumWeightMatching(G, weights, matching);
200 return matchingWeight(matching, weights);
210 std::unordered_set<edge> matching;
211 maximumWeightMatching(GA, matching);
212 return matchingWeight(matching, GA);
218 return getMatchingWeight(matching, weights);
223 return getMatchingWeight(matching, GA);
229 std::unordered_set<edge>& matching) = 0;
232 virtual bool doCall(
const GraphAttributes& GA, std::unordered_set<edge>& matching) = 0;
235 template<
class WeightContainer>
237 bool invert =
false) {
238 for (
edge e : G.edges) {
239 copy[e] = (invert ? -1 : 1) * getWeight<TWeight>(e, weights);
243 template<
class WeightContainer>
245 const WeightContainer& weights) {
247 for (
edge e : matching) {
248 value += getWeight<TWeight>(e, weights);
253 template<
class WeightContainer>
255 std::unordered_set<edge>& matching) {
260 for (
node origNode : G.nodes) {
266 for (
edge origEdge : G.edges) {
269 weightsCopy[newEdge] = weightsCopy[e] = -getWeight<TWeight>(origEdge, weights);
273 std::unordered_set<edge> matchingCopy;
277 doCall(graphCopy, weightsCopy, matchingCopy);
281 for (
edge e : matchingCopy) {
283 matching.insert(origEdge);