Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rusheb
Copy link
Collaborator

@rusheb rusheb commented Apr 13, 2023

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.

Comment on lines -149 to -158
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)
Copy link
Collaborator Author

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)

Comment on lines +149 to +152
# 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)}
Copy link
Collaborator Author

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)

@rusheb rusheb requested a review from mivanit April 13, 2023 14:49
@rusheb rusheb changed the title Refactor find_shortest_path and fix minor bug Refactor LatticeMaze.find_shortest_path and fix minor bug Apr 13, 2023
Copy link
Member

@mivanit mivanit left a 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).

@mivanit
Copy link
Member

mivanit commented Apr 20, 2023

I feel like this might have some merge conflicts with #162 so I will wait to merge that until this is merged

@mivanit
Copy link
Member

mivanit commented Apr 20, 2023

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 mivanit added the move-to-dataset-lib This PR/issue needs to be moved to the maze-dataset library label Jun 15, 2023
@rusheb
Copy link
Collaborator Author

rusheb commented Sep 19, 2023

@mivanit, should we close this?

@mivanit
Copy link
Member

mivanit commented Sep 19, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
move-to-dataset-lib This PR/issue needs to be moved to the maze-dataset library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants