6

I'm aware of there's a lot of similar topics. But most of them left me some doubts in my case. What I want to do is find perfect matching (or as close to perfect as possible in case there's no perfect matching of course) and then from all of those matchings where you are able to match k out of n vertexes (where k is highest possible), I want to choose the highest possible total weight. So simply put what I'm saying is following priority:

  1. Match as many vertexes as possible
  2. Because (non weighted) maximum matching in most cases is unambiguous, I want choose the one that have the biggest sum of weights on edges. If there are several of them with same weight it doesn't matter which would be chosen.

I've heard about Ford-Fulkerson algorithm. Is it working in the way I describe it or I need other algorithm?

abc
  • 2,371
  • 3
  • 25
  • 36

1 Answers1

6

If you're implementing this yourself, you probably want to use the Hungarian algorithm. Faster algorithms exist but aren't as easy to understand or implement.

Ford-Fulkerson is a maximum flow algorithm; you can use it easily to solve unweighted matching. Turning it into a weighted matcing algorithm requires an additional trick; with that trick, you wind up with the Hungarian algorithm.

You can also use a min-cost flow algorithm to do weighted bipartite matching, but it might not work quite as well. There's also the network simplex method, but it seems to be mostly of historical interest.

tmyklebu
  • 13,915
  • 3
  • 28
  • 57
  • In fact it's to my final study diploma (idk exactly international equivalent of degree) about assigment problem, so i will give a try to understand ford-fulkerson. Problem is that i'm not sure if it's work in the way I desire. for instance take following case: := <1,3,1> <2,4,1> <1,4,infinity> doesn't max-flow means that edge <1,4,inf> would be taken and in the same way took maximum possible weight instead of first finding maximum vertex set and as second condition sum of edge weights? – abc Jun 20 '13 at 10:01
  • That isn't really how you'd use flow to solve this. You want unit capacities. If you want a direct formulation, you use a minimum-cost flow model, keep the unit capacities, and let the costs be, um, the costs. This isn't a maximum-flow problem, but there's a trick (the primal-dual method) that lets you use maximum flow as a subroutine. – tmyklebu Jun 21 '13 at 03:38