Is there an algorithm that solves the following decision problem:
Given a strongly connected weighted directed graph G, defined by its transition matrix, is there a strongly connected spanning subgraph of G that has no negative cycles?
A strongly connected spanning subgraph of G is a strongly connected subgraph of G that shares the same vertexes with G. You can look to this paper for the definition of strongly connected spanning subgraph. In this paper they present an approximation for the minimum strongly connected subgraph problem.
A naive approach to this problem is to find a negative cycle of the graph using the Ford-Bellman or Floyd-Warshall algorithm, deleting an edge from this cycle, and repeating while the graph is still strongly connected. But this naive approach has poor time complexity because we will potentially run the Ford-bellman algorithm and check for strong connectivity many times -- moreover I am unable to prove if this algorithm is correct in all instances.
I'm hoping to find experts here who can tell me if this decision problem can be solved in a polynomial time and what algorithm does so. Many thanks in advance.
Here is a naive solution that has a reasonable chance of finding a strongly connecting spanning subgraph with no negative cycles in polynomial time. But is emphatically not guaranteed to find one.
Turn all weights to their negatives. Now use Ford-Bellman or Floyd-Warshall to find a negative cycle. This is actually a positive cycle in the original graph.
Now we pick one vertex in the cycle, and contract the other vertices to it.
Edges that connect to/from removed vertices are replaced by ones representing traveling along that edge and around the cycle to the one we keep. If you wind up with multiple edges between two vertices, only keep the best one.
Repeat the exercise on the new, smaller, graph.
This algorithm runs in guaranteed polynomial time (each iteration runs in polynomial time and removes at least one vertex). If it manages to reduce your graph to a point, then you just walk the process backwards and find that you have in fact found a strongly connected spanning graph with no negative cycles.
However if it fails to do so, there is no guarantee that there isn't one. You just didn't find it.
(I suspect that a guaranteed algorithm will be NP-complete.)
This problem is NP hard in general, this can be proven by reducing Hamiltonian cycle into it.
Related
I have a complete, weighted, undirected graph. The edge weights are the cost of a connection between two nodes, so the minimum spanning tree is the subset of the edges with the lowest total cost such that the graph remains connected.
The MST must be connected at all times, but unfortunately the connections aren't very reliable, so I would like to add redundancy to this graph/network.
Is it possible to compute a subset of edges such that the total edge cost is minimised and edge-connectivity is over a certain minimum?
I can see how it would be possible by bruteforcing, but I was looking for something more practical. I haven't been able to find much about this problem, I think mainly because I don't posses the vocabulary necessary to search.
My current idea is:
Compute the MST
While the it is still below a certain connectivity
Find a node most below that connectivity
Activate that node's edge with the lowest weight
The reason I don't find all the nodes below a certain connectivity all at once is because activating an edge may give another one enough connectivity.
I'm pretty sure this does not yield 100% provably optimal networks, because with this method, it is possible to over-connect nodes (e.g. you activate k edges for a node, then another node activates more shared edges, making some of those k redundant). I hope that makes sense.
Any tips would be much appreciated!
The Wikipedia article on edge connected graphs ends with, A related problem: finding the minimum k-edge-connected spanning subgraph of G (that is: select as few as possible edges in G that your selection is k-edge-connected) is NP-hard for k >= 2. They then cite a 1979 paper that shows it.
Therefore I'd suggest taking a greedy approach, and tip-toeing away.
What is the best approach to find the number of complete sub-graphs with maximum number of nodes possible, given an undirected graph?
PS: By complete I meant that every node is connected to every other node with an unique edge.
You are talking about Clique Problem, this is a classical computer science problem, it is NP Complete. Which means that it doesn't have any solution to it, which could run on today's computers in polynomial time.
Although, approximation algorithms exist to give a solution, they are weak.
I know a few algorithms that are able to find the lowest cost path for directed graph (just as Dijkstra and Floyd).
Is there any algorithm that works for non-directed graphs?
My problem is: I need to find the lowest cost path from a to b passing through all vertexes (undirected graph).
My problem is: I need to find the lowest cost path from a to b passing
through all vertexes (non-oriented graph)
This is the Traveling Salesman Problem, which is NP-Hard, so there is no known efficient solution to it.
However, if the graph is fairly small, there are some techniques to solve it optimally (in exponential time), like Dynamic Programming.
In general, changing an undirected graph to a directed one is fairly easy and is done by changing an undirected edge {u,v} to two directed edges (u,v) and (v,u)
Provided you have nonnegative edge values, you could consider every edge in an undirected graph as two edges in a directed graph, one pointed to and from connected vertices. Then you could use one of many algorithms including the ones you listed.
What I would like to know is if there is any literature that I could read for algorithms to determine the edge connectedness of all edges in a given graph.
The edge connectedness of a given edge (as understood by me) is the number of shortest paths (between diff nodes) that pass through a given edge. That is, if we were to travel from every node to every other node, how many times would we pass through a given edge.
Any help/resource would be appreciated
This is called edge betweennesss as far as I know. Here is a paper for a good algorithm for vertex betweenness, it can be easily generalized to edge betweenness:
Brandes, Ulrik (2001). "A faster algorithm for betweenness centrality" (PDF). Journal of Mathematical Sociology 25: 163–177
http://www.inf.uni-konstanz.de/algo/publications/b-fabc-01.pdf
Use Dijkstra algortihm to find the shortest path. Use this algorithm repeatedly to determine the shortest paths of all pairs of nodes. Now you can simply sum up the occurence of each edge in each path.
I have directed graph with lot of cycles, probably strongly connected, and I need to get a minimal cycle from it. I mean I need to get cycle, which is the shortest cycle in graph, and every edge is covered at least once.
I have been searching for some algorithm or some theoretical background, but only thing I have found is Chinese postman algorithm. But this solution is not for directed graph.
Can anybody help me? Thanks
Edit>> All edges of that graph have the same cost - for instance 1
Take a look at this paper - Directed Chinese Postman Problem. That is the correct problem classification though (assuming there are no more restrictions).
If you're just reading into theory, take a good read at this page, which is from the Algorithms Design Manual.
Key quote (the second half for the directed version):
The optimal postman tour can be constructed by adding the appropriate edges to the graph G so as to make it Eulerian. Specifically, we find the shortest path between each pair of odd-degree vertices in G. Adding a path between two odd-degree vertices in G turns both of them to even-degree, thus moving us closer to an Eulerian graph. Finding the best set of shortest paths to add to G reduces to identifying a minimum-weight perfect matching in a graph on the odd-degree vertices, where the weight of edge (i,j) is the length of the shortest path from i to j. For directed graphs, this can be solved using bipartite matching, where the vertices are partitioned depending on whether they have more ingoing or outgoing edges. Once the graph is Eulerian, the actual cycle can be extracted in linear time using the procedure described above.
I doubt that it's optimal, but you could do a queue based search assuming the graph is guaranteed to have a cycle. Each queue entry would contain a list of nodes representing paths. When you take an element off the queue, add all possible next steps to the queue, ensuring you are not re-visiting nodes. If the last node is the same as the first node, you've found the minimum cycle.
what you are looking for is called "Eulerian path". You can google it to find enough info, basics are here
And about algorithm, there is an algorithm called Fleury's algorithm, google for it or take a look here
I think it might be worth while just simply writing which vertices are odd and then find which combo of them will lead to the least amount of extra time (if the weights are for times or distances) then the total length will be every edge weight plus the extra. For example, if the odd order vertices are A,B,C,D try AB&CD then AC&BD and so on. (I'm not sure if this is a specifically named method, it just worked for me).
edit: just realised this mostly only works for undirected graphs.
The special case in which the network consists entirely of directed edges can be solved in polynomial time. I think the original paper is Matching, Euler tours and the Chinese postman (1973) - a clear description of the algorithm for the directed graph problem begins on page 115 (page 28 of the pdf):
When all of the edges of a connected graph are directed and the graph
is symmetric, there is a particularly simple and attractive algorithm for
specifying an Euler tour...
The algorithm to find an Euler tour in a directed, symmetric, connected graph G is to first find a spanning arborescence of G. Then, at
any node n, except the root r of the arborescence, specify any order for
the edges directed away from n so long as the edge of the arborescence
is last in the ordering. For the root r, specify any order at all for the
edges directed away from r.
This algorithm was used by van Aardenne-Ehrenfest and de Bruin to
enumerate all Euler tours in a certain directed graph [ 1 ].