Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find a weighted bipartite graph's minimum edge cover using Mathematica 8?

In graph theory, we use the Hungarian Algorithm to compute a weighted bipartite graph's minimum edge cover (a set of edges that is incident to every vertices, the one with the minimum total weight.)

I find that in new version 8 of Mathematica, there is a whole new package of functions for Graph Theory, (begin with Graph[].) But I've not found any function that do this job. I do find a function called FindEdgeCover[] that can only find a edge cover, not the minimum one.

like image 982
xzhu Avatar asked Sep 11 '11 02:09

xzhu


1 Answers

I did a few experiments and, although not documented, it seems that FindEdgeCover[] does what you want.

Consider for example:

 h[list_] := CompleteGraph[4, EdgeWeight -> list]

 FindEdgeCover[h@Range@6]
 (*
 ->  {1->2,1->3,1->4}
 *)

But

 FindEdgeCover[h@Reverse@Range@6]
 (*
 -> {1->2,3->4}
 *)

of course no warranty ...

Edit

Here you have some code to experiment with by using different weighted adjacency matrices

adj = {{\[Infinity], 1, 1, 1, 1}, {1, \[Infinity], 2, 2, 2}, 
       {1, 2, \[Infinity], 2, 2}, {1, 2, 2, \[Infinity], 2}, 
       {1, 2, 2, 2, \[Infinity]}}
g = WeightedAdjacencyGraph[adj];
g = WeightedAdjacencyGraph[adj, VertexShapeFunction -> "Name", 
  EdgeLabels -> 
   MapThread[
    Rule, {EdgeList@g, AbsoluteOptions[g, EdgeWeight] /. {_ -> x_} -> x}], 
  GraphHighlight -> FindEdgeCover[g]]

enter image description here

NB: The code is not good at all, but I couldn't find a way to use EdgeLabels -> “EdgeWeight”. I posted this question to see if someone can do it.

like image 110
Dr. belisarius Avatar answered Oct 14 '22 01:10

Dr. belisarius