-
Notifications
You must be signed in to change notification settings - Fork 6
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
Refactor LatticeMaze.find_shortest_path and fix minor bug #176
base: main
Are you sure you want to change the base?
Conversation
g_score: dict[ | ||
CoordTup, float | ||
] = dict() # cost of cheapest path to node from start currently known | ||
f_score: dict[CoordTup, float] = { | ||
c_start: 0.0 | ||
} # estimated total cost of path thru a node: f_score[c] := g_score[c] + heuristic(c, c_end) | ||
|
||
# init | ||
g_score[c_start] = 0.0 | ||
g_score[c_start] = self.heuristic(c_start, c_end) |
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.
Here is the part in the old version where I have changed behaviour (see PR description for details)
# cheapest currently known path to node from start | ||
g_score: dict[CoordTup, float] = {c_start: 0.0} | ||
# estimated total cost of path through a node: f_score[c] = g_score[c] + heuristic(c, c_end) | ||
f_score: dict[CoordTup, float] = {c_start: self.heuristic(c_start, c_end)} |
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.
Here is the part in the new version where I have changed behaviour (see PR description for details)
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.
LGTM! I do think that the starting point thing was a bug although I doubt it will change the behavior since we don't use the f_score
of the starting node ever (since we do not ever pass through it again).
I feel like this might have some merge conflicts with #162 so I will wait to merge that until this is merged |
actually, it looks like there are no conflicts! |
@mivanit, should we close this? |
I don't think this actually ended up ever getting merged? I'll check in the maze-dataset repo tommorow and apply the fix there if needed. |
Some refactoring I did to help me understand
find_shortest_path
whilst reading through it.Mostly renaming. Also updated a few type hints.
There is one change in behaviour which I think fixes a minor bug.
Previously, we were initializing
g_score[c_start]
twice, first to zero (correct) and then to the manhattan distance (incorrect).I think I have fixed this by initializing g_score and f_score for c_start.
Sorry for mixing bug fixes and refactoring together! I will highlight the behaviour changes in a comment.