-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexplored.py
More file actions
30 lines (24 loc) · 777 Bytes
/
explored.py
File metadata and controls
30 lines (24 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'''
Created on Feb 8, 2018
@author: mroch
'''
class Explored(object):
"Maintain an explored set. Assumes that states are hashable."
def __init__(self):
"__init__() - Create an empty explored set."
self.hash_table = set()
def exists(self, state):
"""
exists(state) - Has this state already been explored?
:param state: Hashable problem state
:return: True if already seen, False otherwise.
"""
return hash(state) in self.hash_table
def add(self, state):
"""
add(state) - Add a given state to the explored set
:param state: A problem state that is hashable, e.g. a tuple
:return: None
"""
self.hash_table.add(hash(state))
return None