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

MAINT: Add documentation and descriptive variable names in search.py #1142

Merged
merged 3 commits into from
Jan 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions search.py
Original file line number Diff line number Diff line change
@@ -123,6 +123,10 @@ def __eq__(self, other):
return isinstance(other, Node) and self.state == other.state

def __hash__(self):
# We use the hash value of the state
# stored in the node instead of the node
# object itself to quickly search a node
# with the same state in a Hash Table
return hash(self.state)


@@ -353,14 +357,16 @@ def extend(U, open_dir, open_other, g_dir, g_other, closed_dir):

def find_min(open_dir, g):
"""Finds minimum priority, g and f values in open_dir"""
m, m_f = np.inf, np.inf
# pr_min_f isn't forward pr_min instead it's the f-value
# of node with priority pr_min.
pr_min, pr_min_f = np.inf, np.inf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, the new variable names are indeed more descriptive, nice catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

for n in open_dir:
f = g[n] + problem.h(n)
pr = max(f, 2 * g[n])
m = min(m, pr)
m_f = min(m_f, f)
pr_min = min(pr_min, pr)
pr_min_f = min(pr_min_f, f)

return m, m_f, min(g.values())
return pr_min, pr_min_f, min(g.values())

def find_key(pr_min, open_dir, g):
"""Finds key in open_dir with value equal to pr_min