Minimum Spanning Tree for Directed Graphs

I'm working on a school assignment (not intending to cheat here) that consists of implementing a graph. I have every method of the graph working properly, as best I can determine (with extensive test code), except that I cannot figure out an algorithm for doing a minimum spanning tree if the graph is directed. (My method for an undirected graph works.)

I'll try to describe my current algorithm, which, as implemented, works for many directed graphs, but not all.

I attempt to generate a minimum spanning tree for each vertex (treating that vertex as the root), by these steps (taken for each vertex):

Create a new empty graph

Add every vertex of the current graph to it

For every vertex that is not being treated as the root, I take its least-cost incoming edge, and add it to the graph.

Once a tree has been returned for each possible root, I eliminate any trees that contain cycles or have fewer than (# of vertices - 1) edges. (It is OK for this method to fail for an unconnected graph.) I then return the remaining tree, if any, that has the lowest total edge cost.

This works for all of the test graphs I have in most of my test class, but it does not work for a test graph whose adjacency matrix looks like this:

| D | A | C | B |

-+++++

D||| 2 ||

-+++++

A||| 7 | 1 |

-+++++

C| 1 ||||

-+++++

B| 6 | 2 |||

-+++++

I don't think it can be easily modified to work for this case either, so I need a totally different approach.

I'm currently reading and trying to understand the Gabow/Myers paper from 1978, but I'm having trouble with it. (I purposely chose an older algorithm thinking it might be easier to understand than a sleeker, more modern one.)

Several papers seem to mention that you can get to a directed spanning tree via depth-first traversal, but as I understand depth-first traversal, the minimum spanning trees of the directed graphs I can solve are not depth-first traversals of the graphs at all. I assume they mean something that I just can't see.

I'm not looking for code, but if someone can suggest an algorithm that I might be able to understand, I would appreciate it. Or a hint would be great too. I will of course continue to pursue this on my own in the meantime.

Here is the API specification for what I've coded. I'm including it only so that you can see, if you are interested, what has already been coded. I have completed all of the methods described in the API and they all work as best I can tell.

http://jody140.dsl.frii.net/cs/cs3/Graph/

[2630 byte] By [Alethiographera] at [2007-10-2 16:25:04]
# 1

After posting the above, I realized I could not see why Kruskal's algorithm, which I used for my undirected graph, would not work for a directed graph. When I tried it, it actually did work, or at least it satisfied my understanding of what a directed spanning tree is.

I'm now wondering if that understanding is wrong.

Take a graph whose adjacency matrix is like this | D | A | C | B |

-+++++

D||| 2 ||

-+++++

A||| 7 | 1 |

-+++++

C| 1 ||||

-+++++

B| 6 | 2 |||

-+++++

Is this a spanning tree of that graph?

| D | A | C | B |

-+++++

D|||||

-+++++

A|||| 1 |

-+++++

C| 1 ||||

-+++++

B| 6 ||||

-+++++

It meets the requirement that every vertex except one has at most one incoming edge, and the entire graph is connected. But does the definition additionally require that there is some node from which every other node can be reached? Because that requirement is not satisfied, if so.

Alethiographera at 2007-7-13 17:23:37 > top of Java-index,Other Topics,Algorithms...
# 2

> Is this a spanning tree of that graph?

Yes.

> It meets the requirement that every vertex except one

> has at most one incoming edge, and the entire graph

> is connected. But does the definition additionally

> require that there is some node from which every

> other node can be reached? Because that requirement

> is not satisfied, if so.

Corect. But, if I'm not mistaken, algorithms for getting (minimal) spanning trees for undirected grapghs (such as Kruskal's algorithm) cannot be applied to directed graphs.

The following people independently found a solution to this: Chu, Liu, Edmonds and Bock. I don't have any specifics, but I'm sure Google has.

Hope it's of use to you.

Good luck.

prometheuzza at 2007-7-13 17:23:37 > top of Java-index,Other Topics,Algorithms...
# 3

I'm just posting a follow-up. Once I realized my idea of the definition of a spanning tree for a directed graph was wrong, I ended up using Dijkstra's algorithm (for minimum cost path) to solve this problem. It actually does not work, but it was the best I could come up with in time to turn in the assignment.

Since then, it seems to me that Prim's algorithm could be used to get the minimum spanning tree treating each root as a vertex, and the results could then be compared. (Not every vertex in a directed graph will necessarily give a spanning tree, but among those that do, the one with the lowest total cost would be the minimum spanning tree.)

Anyway, I'm just posting this for the benefit of anyone who might be watching for an answer, or who might search for one in the future. I haven't confirmed that my approach would work.

Alethiographera at 2007-7-13 17:23:37 > top of Java-index,Other Topics,Algorithms...
# 4

Finding a minumum cost spanning tree in a directed graph is equivalent

to solving the MCNF problem (Minimum Cost Network Flow). This problem

is a sub-problem of a general LP (Linear Program) For a very

detailed description of a very powerful and useful algorithm, read:

"Linear Network Optimization, Algorithms and codes"

Dimitri P. Bertsekas

MIT Press

ISBN 0-262-02334-2

kind regards,

Jos

JosAHa at 2007-7-13 17:23:37 > top of Java-index,Other Topics,Algorithms...
# 5
hey man i am doing a research on Graph Theory. I would like to see the code of Minimum Spanning Tree graphs that run. here is my email if u can email it: agdamly_ash@yahoo.com
businessman_arkansasa at 2007-7-13 17:23:38 > top of Java-index,Other Topics,Algorithms...
# 6
> hey man i am doing a research on Graph Theory. I> would like to see the code of Minimum Spanning Tree> graphs that run. here is my email if u can email it:> agdamly_ash@yahoo.comeye send it 2 u
prometheuzza at 2007-7-13 17:23:38 > top of Java-index,Other Topics,Algorithms...