doug reich
Some guy
- Joined
- 4/23/08
- Messages
- 684
- Points
- 28
vic,
I used modified Bellman-Ford as well. I wrote it from scratch, not using Boost, but the key features to avoid repeated currencies for me was to add a std::set to each iteration that saves those nodes visited on that path. In my implementation I could check the set in constant time, since std::set returns the elements in order. Think merge-sort.
I don't think you can modify the graph, however, because all the other paths will want to explore those edges, no?
I found that you also have to make some modifications to the algorithm if you want ALL of the best arbitrage loops. That is, if after 3 steps you reach node X through two equally-good paths, you will want to save both paths (this could happen if some currencies are pegged, e.g.). (Bellman Ford will normally break-ties arbitrarily, but you may want to allow ties) Not difficult to do, depending on your implementation, but be aware.
I used modified Bellman-Ford as well. I wrote it from scratch, not using Boost, but the key features to avoid repeated currencies for me was to add a std::set to each iteration that saves those nodes visited on that path. In my implementation I could check the set in constant time, since std::set returns the elements in order. Think merge-sort.
I don't think you can modify the graph, however, because all the other paths will want to explore those edges, no?
I found that you also have to make some modifications to the algorithm if you want ALL of the best arbitrage loops. That is, if after 3 steps you reach node X through two equally-good paths, you will want to save both paths (this could happen if some currencies are pegged, e.g.). (Bellman Ford will normally break-ties arbitrarily, but you may want to allow ties) Not difficult to do, depending on your implementation, but be aware.