7

I have a digraph which is strongly connected (i.e. there is a path from i to j and j to i for each pair of nodes (i, j) in the graph G). I wish to find a strongly connected graph out of this graph such that the sum of all edges is the least.

To put it differently, I need to get rid of edges in such a way that after removing them, the graph will still be strongly connected and of least cost for the sum of edges.

I think it's an NP hard problem. I'm looking for an optimal solution, not approximation, for a small set of data like 20 nodes.

Edit

A more general description: Given a grap G(V,E) find a graph G'(V,E') such that if there exists a path from v1 to v2 in G than there also exists a path between v1 and v2 in G' and sum of each ei in E' is the least possible. so its similar to finding a minimum equivalent graph, only here we want to minimize the sum of edge weights rather than sum of edges.

Edit:

My approach so far: I thought of solving it using TSP with multiple visits, but it is not correct. My goal here is to cover each city but using a minimum cost path. So, it's more like the cover set problem, I guess, but I'm not exactly sure. I'm required to cover each and every city using paths whose total cost is minimum, so visiting already visited paths multiple times does not add to the cost.

Kazoom
  • 5,179
  • 16
  • 54
  • 65
  • no its not, i am trying to implement tsp and its variations – Kazoom Oct 08 '09 at 07:17
  • I'm confused as to what the cost is. Is it the sum of the cost of the edges you keep? The sum of the cost of the n^2 paths between each pair of nodes? The sum of the cost of a set of paths that cover each node (which doesn't really fit with the requirement of SCC)? – Keith Randall Oct 10 '09 at 03:50
  • cost would be sum of weights of all the edges that make the graph – Kazoom Oct 10 '09 at 20:12

7 Answers7

12

Your problem is known as minimum spanning strong sub(di)graph (MSSS) or, more generally, minimum cost spanning sub(di)graph and is NP-hard indeed. See also another book: page 501 and page 480.

I'd start with removing all edges that don't satisfy the triangle inequality - you can remove edge a -> c if going a -> b -> c is cheaper. This reminds me of TSP, but don't know if that leads anywhere.

My previous answer was to use the Chu-Liu/Edmonds algorithm which solves Arborescence problem; as Kazoom and ShreevatsaR pointed out, this doesn't help.

sdcvvc
  • 24,483
  • 4
  • 63
  • 101
  • MST for directed spanning tree does not really solve the problem. the directed tree mst finds shortest path only from the root to other node. in my case i need to find a graph which has paths from one node to every other node, may not be the least, but the overall sum of edges of a graph need to be minimum – Kazoom Oct 11 '09 at 16:07
  • "the directed tree mst finds shortest path only from the root to other node" - that's what Dijkstra does? According to other reference I linked, the overall sum is minimized, and the resulting graph is strongly connected. Could you clearly state what's wrong? (It's not a literal use of undirected MST algorithm to directed graph) – sdcvvc Oct 11 '09 at 16:33
  • @sdcvvc: The resulting graph given by the minimum-arborescence problem is an arborescence, hence not strongly connected. It has paths from the root to all other nodes, but not between all pairs of nodes. For example, it has no edge incoming into the root, or outgoing from the leaves. – ShreevatsaR Oct 11 '09 at 16:38
  • 3
    To get within a factor of 2 of optimal is easy - pick an arbitrary node and compute a minimum spanning out-tree and in-tree for that node. – Keith Randall Oct 17 '09 at 22:36
2

I would try this in a dynamic programming kind of way.

0- put the graph into a list

1- make a list of new subgraphs of each graph in the previous list, where you remove one different edge for each of the new subgraphs

2- remove duplicates from the new list

3- remove all graphs from the new list that are not strongly connected

4- compare the best graph from the new list with the current best, if better, set new current best

5- if the new list is empty, the current best is the solution, otherwise, recurse/loop/goto 1

In Lisp, it could perhaps look like this:

(defun best-subgraph (digraphs &optional (current-best (best digraphs)))
  (let* ((new-list (remove-if-not #'strongly-connected
                                  (remove-duplicates (list-subgraphs-1 digraphs)
                                                     :test #'digraph-equal)))
         (this-best (best (cons current-best new-list))))
    (if (null new-list)
        this-best
        (best-subgraph new-list this-best))))

The definitions of strongly-connected, list-subgraphs-1, digraph-equal, best, and better are left as an exercise for the reader.

Svante
  • 46,788
  • 11
  • 77
  • 118
1

Few ideas that helped me to solve the famous facebull puzzle:

Preprocessing step:

  1. Pruning: remove all edges a-b if there are cheaper or having the same cost path, for example: a-c-b.

  2. Graph decomposition: you can solve subproblems if the graph has articulation points

  3. Merge vertexes into one virtual vertex if there are only one outgoing edge.

Calculation step:

  1. Get approximate solution using the directed TSP with repeated visits. Use Floyd Warshall and then solve Assignment problem O(N^3) using hungarian method. If we got once cycle - it's directed TSP solution, if not - use branch and bound TSP. After that we have upper bound value - the cycle of the minimum cost.

  2. Exact solution - branch and bound approach. We remove the vertexes from the shortest cycle and try build strongly connected graph with less cost, than upper bound.

That's all folks. If you want to test your solutions - try it here: http://codercharts.com/puzzle/caribbean-salesman

cat_baxter
  • 139
  • 2
  • what is the purpose for Floyd Warshall? – ruandao Mar 19 '14 at 10:06
  • why can use hungarian (don't need to take care for the weight?) – ruandao Mar 19 '14 at 12:17
  • after use hungarian method. if we never got cycle. why the result was upper bound value of the cycle of the minimum cost? – ruandao Mar 19 '14 at 12:26
  • 1
    1. We need FW for the step 1. If we got the path a->b (for example a->c->b) shorter than the original vertex a->b, then we can remove such vertex. 2. If Hungarian gives us one cycle - it's equal to directed TSP solution, so we take it as upper bound. – cat_baxter Mar 19 '14 at 13:52
  • if we get multi cycle, so we make each cycle to a virtual vertex and hungarian it again? until we get only one cycle, then it's the upper bound – ruandao Mar 20 '14 at 02:54
  • No multi use of the Hungarian algo doesn't get us the directed TSP solution :) – cat_baxter Mar 20 '14 at 11:50
  • seems like step 1 was use to get a approximate solution(the upper bound value). what's the mean of remove the vertexes from the shortest cycle? when use branch and bound, it will need to calculate the low bound so we can throw the redundancy tree, but what's the low bound, i try to use mini input and output and not sure how... – ruandao Mar 21 '14 at 12:46
  • i found that when use branch and bound to solve tsp problem. people are chose to use a node mini input and mini ouput, why will it be part of the low bound? it seems will appear two chose on some rows or some cols – ruandao Mar 21 '14 at 13:16
  • tks. I got [a explain for why the sum(minInput,miniOutput)/2 will be the smallest](http://www.jot.fm/issues/issue_2003_03/column7.pdf) – ruandao Mar 21 '14 at 15:14
1

This problem is equivalent to the problem described here: http://www.facebook.com/careers/puzzles.php?puzzle_id=1

mlbright
  • 11
  • 1
0

Seems like what you basically want is an optimal solution for traveling-salesman where it is permitted for nodes to be visited more than once.

Edit:

Hmm. Could you solve this by essentially iterating over each node i and then doing a minimum spanning tree of all the edges pointing to that node i, unioned with another minimum spanning tree of all the edges pointing away from that node?

Amber
  • 446,318
  • 77
  • 595
  • 531
  • actually i solved that problem TSPm, but it would not work, in my case i should be allowed to revisit the node as well as the edges multiple times, i will edit the question for more description – Kazoom Oct 08 '09 at 07:16
0

Sounds like you want to use the Dijkstra algorithm

Maurice Perry
  • 31,563
  • 8
  • 67
  • 95
  • Dijkstra does not apply here... at least not in any obvious way. – Igor ostrovsky Oct 08 '09 at 07:25
  • Well, you can use Dijkstra to solve TSP, so it *is* a possible solution. It's just a matter of defining the search space of partial solutions, then searching it in least-cost-so-far order. Of course that doesn't mean it's a good solution in this case. – Steve314 Oct 14 '09 at 19:05
0

A 2-approximation to the minimal strongly connected subgraph is obtained by taking a union of a minimal in-branching and minimal out-branching, both rooted at the same (but arbitrary) vertex.

An out-branching, also known as arborescence, is a directed tree rooted at a single vertex spanning all vertexes. An in-branching is the same with reverse edges. These can be found by Edmonds' algorithm in time O(VE), and there are speedups to O(E log(V)) (see the wiki page). There is even an open source implementation.

The original reference for the 2-approximation result is the paper by JaJa and Frederickson, but the paper is not freely accessible.

There is even a 3/2 approximation by Adrian Vetta (PDF), but more complicated than the above.