-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a new pathfinding algorithm #1
Comments
Q1. Have you seen/heard of an implementation of something like this? I mean, with all restrictions of task 🥲 Tough task. Especially compared to what you have now, it's a very big leap forward |
@7uperior hi, yes, we have a solution 😉 |
Just out of curiosity, if In this case wouldn't it be effective to only consider maximum weight. Since when you consider buying X from Y, instead of considering minimum weight X-->Y, you shall calculate maximum of Y-->X instead? If the assumption of 2w<1/w is true, and we formulate the problem this way naturally we shall bypass the difficult of dead loop. |
Hi, @RongkunWang! I didn't quite understand what you mean, so I would be very grateful for a more specific example So we need a different mechanism to handle dead loops |
Hi @artememelin , I understood the original question formation. I'm just making a connection to the real-world problem and try to understand if the formation of the question makes sense. If I can exchange crypto |
@RongkunWang, of course, what you suggest is not far from the truth. Indeed, if we assume that in the real world we are unlikely to see a similar situation, then the task becomes quite simplified. However, we also need an algorithm that will be able to work with dead loops in the graph |
Description
Add a new algorithm to the package that is capable of finding the most advantageous chain of currency conversions between two specified currencies.
The "most advantageous chain of currency conversions" is defined as a sequence of exchanges from currency A to currency B such that the product of the exchange rates (the weights of the edges in the currency exchange graph) is optimized. If the goal is to sell currency A, the algorithm should maximize this product; if the goal is to buy currency A, the algorithm should minimize it.
Tasks
Tests
The algorithm must pass the following tests:
Testset
Basic rules of the algorithm
The final conversion coefficient between two currencies
A
andB
is determined by multiplying the weights of the edges corresponding to the laid path.If there is an edge from
A
toB
with weightW
in the graph, then it is assumed that an inverse edge fromB
toA
with weight1/W
is implicitly specified unless otherwise stated (likeB -> C
andC -> B
).Thus, the algorithm must search for a path in all directions of the graph, even if the edges are explicitly specified only in one direction.
Algorithm requirements
The algorithm must be able to find a path in which the final conversion coefficient will be maximum (We want to sell the base currency and get as much of the quoted currency as possible). Note that such a path may be longer than the path that would be found using the A* algorithm.
The algorithm must also be able to find a path in which the final conversion rate will be minimal (We want to buy as much of the base currency as possible and spend the minimum amount of the quoted currency). Note that such a path may be longer than the path that would be found using the A* algorithm.
For simplicity, you can break this algorithm into two separate ones to find the maximum and minimum. Or you can implement algorithm selection using keywords
Possible difficulties
Situations may arise with so-called “negative cycles” - a closed path, following which we can endlessly improve the final conversion coefficient. You need to figure out how to avoid this behavior. Here
A -> B -> C -> A -> ...
is a negative cycle.The text was updated successfully, but these errors were encountered: