KeRNeLith / QuikGraph

Generic Graph Data Structures and Algorithms for .NET
https://kernelith.github.io/QuikGraph/
Microsoft Public License
476 stars 70 forks source link

[BUG] Multigraph bug? #57

Open johna1203 opened 2 years ago

johna1203 commented 2 years ago

Describe the bug

I am trying to reproduce this strategy from the article below. https://anilpai.medium.com/currency-arbitrage-using-bellman-ford-algorithm-8938dcea56ea

Then I generated the following grap test

var tryGetPath = graph.ShortestPathsBellmanFord(e => e.Weight, "USD", out var hasNegativeCycle);
if (hasNegativeCycle) {
  Console.WriteLine("IS NEGATIVE");
}

if (tryGetPath("PLN", out var edges)) {
  Console.WriteLine($"PATH {string.Join("-->", edges.Select(e => e.Source).ToList())}");
}

but I have a problem, it is that there is an infinite loop in the following line. (EdgeExtensions.cs:265) You can see that it stays between USD <--> MXN and never leaves the while. quickGraph

I tried to fix it, but I don't know where the error.... is

If you need the source code, let me know and I'll post it here.

Thank you.

KeRNeLith commented 2 years ago

Hello @johna1203!

I'm sad it's causing you issues. I wil indeed appreciate if you provide the source code associated to your tests so we can have a look into more details :-)