-
Notifications
You must be signed in to change notification settings - Fork 7
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
performance improvement for A* algorithm #68
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice work !
Please check the tests - fix them - thank you (https://github.com/flatland-association/flatland-rl/actions/runs/8425098470/job/23077182909?pr=68) |
@aiAdrian the failed tests are an expected consequence of this change in the underlying algorithm, because the new priority queue breaks ties in a different way. |
I suggest fixing or disabling the tests. then merge and open a new issue to rethink and rebuild the tests, respectively. I think it's a good idea to build the test as you suggested. Please create the issue and disable the test with a link to the new issue - or just fix the test in a first run. A soon a this is done, i will do the review again. Thank you (@gdalle ) for this very nice work |
Most of the credit goes to @bcrobin03 :) I'll let him choose between fixing the tests or selectively disabling them, and open a new issue to discuss a redesign |
@bcrobin03 can you also clean up this branch to remove the notebook diffs and keep only the core code? The number of lines changed is alarming. |
I am looking into it |
…test_sparse_rail_generator_deterministic)
@aiAdrian I think this is ready! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for this really great performance improvement!
Changes
The changes made are:
test_flatland_envs_sparse_rail_generators.py
:test_sparse_rail_generator()
andtest_sparse_rail_generator_deterministic()
because they relied heavily on the datastructure used in A*Checklist
*I used heapq which is from the standard library so I did not change requirements
I encountered some trouble with the A* test, indeed as I use a heap now the path taken is not the one expected by the test as it does not solve ties the same way as the ordered set, however the length, and destination are equivalent (algorithm does indeed find a way that is the least costly). I considered that it would maybe be interesting to not test to a particular path but only test on the length of the path. Therefore this code does not fullfil the requirements to pass the tests, but maybe we can discuss it ?
I claim that it is faster but how much ? I tested different set of parameters and found the following gain of performance (this is in seconds), by timing the function env.reset():
here is an idea of the gain of performance of A* heap VS orderedSet:
Here is an idea of the gain of performance respective to the size of the grid with 5 cities:
Careful I labeled the x-axis as number of cities where it is in fact the grid size (square)