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.

xzhu
  • 5,675
  • 4
  • 32
  • 52
  • 1
    Are you sure that function doesn't do what you need? According to the documentation, FindEdgeCover[g] finds an edge cover of the graph g with a minimum number of edges. So isn't it finding the minimum edge cover as required? Otherwise there would be more than one answer given, including non-minimum edge covers. – Verbeia Sep 11 '11 at 03:21
  • 1
    No, by minimum, I meant the minimum total of weight of the edges in the set, not the number of edges. – xzhu Sep 11 '11 at 04:39
  • Ah, so the unweighted version, in effect. It might be that the necessary function is not yet built in. – Verbeia Sep 11 '11 at 05:04
  • @trVoldemort - Thanks for asking this Q... I was just looking at the Hungarian Algorithm myself, but have little knowledge of graph theory. While I can follow a matrix-based explanation of the algorithm, understanding the correspondence to graphs continues to frustrate me. – telefunkenvf14 Sep 11 '11 at 08:42

1 Answers1

6

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.

Community
  • 1
  • 1
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190