Skip to content

Commit

Permalink
MAINT: Add documentation and descriptive variable names in search.py (a…
Browse files Browse the repository at this point in the history
…imacode#1142)

* DOC: Add docstring to __hash__ method in Node

* MAINT: Add documenation and descriptive variable names

* FIXUP: Revert to previos names
  • Loading branch information
tirthasheshpatel authored and antmarakis committed Jan 2, 2020
1 parent df33d47 commit 4363ddb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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
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
Expand Down

0 comments on commit 4363ddb

Please sign in to comment.