I have a directed graph with negative edge weights. The graph is modified by the program and sometimes will form negative cycles. When that happens, shortest path algorithms (Bellman-ford/Johnson/Floyd-Warshall) would detect the existence of such negative cycle and fail, but no other useful information is produced.

I would like to identify what edge causes the negative cycle and disallow such modifications in the graph. Can someone help me with a pointer?

Thanks,

Paul

Paul, If you're about to add an edge (source, destination, weight), and you know the distance from destination to source, then you're creating a negative cycle if and only if new weight + old distance is negative.

On the other hand, if you've just got a graph, the bellman-ford algorithm detects negative cycles and can exhibit one when it finds one. You just need to either find an implementation that does that (rather than just failing), or write one yourself. It's not a difficult algorithm and there's lots of pseudocode on the web.

(It's probably a couple of days consultancy work if you want one custom-written for you. I do this sort of thing for a living and would be happy to.)

I'm not sure exactly what you need. I don't know, but I'd imagine that there's an on-line version of Bellman-Ford that keeps its distances up to date cheaply as new edges come in, and will scream if you add a bad one.

Similar Questions

The session time out is set to 20mins but the application session keeps expiring abruptly well within 20 mins. I am not able to identify the cause of session expiry? Is there a way to find what is cau

I wrote some code to measure cpu cycles per byte. I'm getting negative cpb but dont know why ... It shows me that cpb = -0.855553 cycles/byte My pseudocode: #include <stdio.h> #include <strin

I'm trying to understand exactly why the Bellman-Ford Algorithm would not work with a negative weight cycle. I do understand that negative weight cycles will prevent the program from giving the right

I am quite new to Boost graph. I am trying to adapt an example for finding Dijkstra Shortest Path algorithm which used VertexList = vecS. I changed the vertex container to ListS. I learned that we hav

I have implemented an algorithm to find an Euler cycle for a given starting vertex in an undirected graph (using DFS and removing visited edges), but it always returns only one path. How do I modify t

Let G be an unweighted directed graph containing cycles. I'm looking for an algorithm which finds/creates all acyclic graphs G', composed of all vertices in G and a subset of edges of G, just small en

I have the following problem. Given a directed graph G=(V,E) with edge costs cij between all edges {i,j}. We have multiple sources, say s1,...,sk, and one target, say t. The problem is to find the low

I need to find the shortest path in a graph that passes through at least one edge marked as must pass. Any ideas? Could Dijkstra's algorithm be modified in order to achieve this? Thanks.

I'm having trouble trying to figure out a shortest-path algorithm such that given a undirected unweighted graph with an start point a and end point b, every path must contain/run into the vertex v. Is

How is Dijkstra algorithm better tham A* algorithm for finding shortest path?

I have an embedded linux device. I am trying to come up with some test cases that would exercise various subsystems, code paths, system calls in the kernel to identify problems/loose ends in the kerne

I have code that is supposed to find the shortest path from point A to point B. To do this i am using a A-star variation. I am using a 2d array to represent a 2d grid but my path does not take diagona

I am trying to write a regular expression in PERL that will pick the shortest match. I have written one that will identify many matches, but I need to be able to pick the shortest of all the matches.

For a directed graph G(V,E) where it has negative weights, I searched some similar topics and it seems Bellmanford can detect negative cycles. But it stops once negative cycles found, so how can we li

I'm trying to find the shortest path between two maxima on a discrete energy landscape whereby the shortest path is that which reduces the least in height over the course of the total path. Probably m

I'm trying to figure out the best method of getting/displaying the shortest distance between multiple locations. To best explain this think of it as a map and use the following below. All of the dista

Good morning. My friend gave me an interesting graph problem which goes as below. Given a simple graph in which two cycles share at most one vertex, how to label edges with non negative real number su

I am working through a shortest path problem using Dijkstra's Algorithm. I am having trouble because the algorithm is supposed to provide the shortest path, but after running the algorithm I get a sho

I'm not asking for an algorithm to check the existence of a negative cycle in a graph(Bellman Ford or Floyd Warshall can do that), rather whether or not there exists a polynomial time algorithm to fin

I'm trying to find a way to find the shortest path through a grocery store, visiting a list of locations (shopping list). The path should start at a specified start position and can end at multiple en

I want to develop an algorithm that let me find the shortest path from a given point A and another point B; something like find the shortest path given two cities(**). The problem is that I can not us

In this earlier question the OP asked how to find a shortest path in a graph that goes from u to v and also passes through some node w. The accepted answer, which is quite good, was to run Dijkstra's

See picture. This is tab design I'm working on for my TabControl: As you see - path got 4 points - corners of my tab. But no matter how I try - with enough magnification I see some kind of artifacts

Let's say I have a weighted graph with weights on both edges and vertices. How do I find the cheapest path from a certain node s to a certain node t? My complexity should be O(n2(n+m)).

For the AFP entry Dijkstra's Shortest Path Algorithm, both the proof outline and proof document were nonexistent *. Unfortunately, I did not find an IsaMakefile either to build those documents locally

I am trying to implement Dijkstra's shortest path algorithm using C++ and STL. Since STL's priority queues do not support a decrease-key operation, I decided to use regular ordered sets. My algorithm

Mr. Rowan plans to make a walking tour of Paris. However, since he is a little lazy, he wants to take the shortest path that goes through all the places he wants to visit. He plans to take a bus to th

I'm having problems getting my shortest path algorithm to work correctly. I have a 2d array 20 x 20 that contains the edge weights representing roads between cities. I do not get the correct results f

Some days ago, Someone ask me, If we have some agents in our environment, and they want go from their sources to their destinations, how we can find the total shortest path for all of them such that t

This question is an exact duplicate of: Minimum distance between start and end by going through must visit points in a maze 1 answer I am working on a shortest maze problem, and there is a star

So I'm trying to code Dijkstra's shortest path algorithm in C++. For some reason, it's not adding up the distances correctly... Here is what I have so far for code. You can ignore the section where I

I'm looking for a solution since days but can't find a way to solve it. My goal is to find the shortest way between 2 bus stops, based on the time the bus takes between them. So I have bus lines, and

I'm studying graph theory and I have a question about the connection between minimum spanning trees and shortest path trees. Let G be an undirected, connected graph where all edges are weighted with d

I am trying to know and understand as many algorithms as I can and I stumbled across a strange algorithm in a contest packet that finds the minimum number of steps to solve a maze (shortest path). I u

I am not a very experienced programmer with these kind of things, but I wanted to write a program that receives two Facebook profiles, and returns the shortest path of people between them. I guess t

why negative edges cycles are allowed in bellman ford algorithms while no negative edge allowed in dijkstra algorithms?

i have n points on a 2d plane, with n <= 12, and i need the distance of the shortest path available including all points, starting on any of them, but not making a closed circuit i've been trying f

I am looking for a way to augment the BFS method used to find the single source shortest paths in an unweighted directed graph and solve the above problem in O(N+M) time. where N is the number of vert

Can someone please explain how given an undirected graph G = (V; E); edge lengths le > 0; and edge edges in E. We can generate the length of the shortest cycle containing edge e. I understand how t

For an undirected, unweighted graph, is there any difference in the time complexity of the algorithm to compute its average shortest path length vs, the complexity of the algorithm which computes the

I'm curious, do you have any technical recommendations against referencing a symlinked directory in your PATH environment variable? I.e. as opposed to using the directory that the symlink resolves to?

I know Dijkstra fails when there are negative edge weights, but when do both algorithms fail?

This is a general algorithm question. I want to run some shortest path algorithm on an undirected graph where both edges and vertices have costs associated with them. Most of the shortest path finding

I'm new in graph theory and need a little help. Let's say we have a graph with defined start and end vertext. How can I get the shortest path ONLY between the start and end vertex using BFS. I've writ

I am surprised why the following code that calculates all pairs shortest pairs does not show me any output. Here is the code: #include <iostream> #include <conio.h> using namespace std; in

I know that many algorithms are available for calculating the shortest path between two points in a graph or a grid, like breadth-first, all-pairs (Floyd's), Dijkstra's. However, as I noticed, all of

I have a global unique path table which can be thought of as a directed un-weighted graph. Each node represents either a piece of physical hardware which is being controlled, or a unique location in t

I know it is possible to get the shortest path of minimum number of nodes by using Cypher and Gremlin? How about getting a path with minimum traversal cost? One of the example I can think of is the bu

Code jam problem is the following: You are given a complete undirected graph with N nodes and K forbidden edges. N <= 300, K <= 15. Find the number of Hamiltonian cycles in the graph that do n

I'm trying to come up with a shortest path algorithm, using the Greedy Tree algorithm. Examples: Dijkstra or Prim I however can't seem to figure out how I should be making my data structure. When I tr