-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch_tree_node.py
48 lines (35 loc) · 1.73 KB
/
search_tree_node.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''
SearchTreeNode Class used in A* Search
'''
class SearchTreeNode:
##################################################################
# Constructor
##################################################################
def __init__(self, state, action, parent, totalCost, heuristicCost):
"""
SearchTreeNodes contain the following information for A*:
:state: The state represented by the node, a tuple:
(x, y) = (col, row)
:action: The action used to transition from the parent to this node.
- The action's value is None if the initial state
- The action's value will be a string "U", "D", "L", "R" otherwise
:parent: The parent of this node in the search tree.
- The parent's value is None if the initial state
- The parent's value is a reference to the parent node otherwise
:totalCost: The total cost of the path of actions that led to this particular state.
In the notes, we refer to this value as being evaluated through g(n)
:heuristicCost: The heuristic estimate of cost to be incurred from this node to the
optimal solution
"""
self.state = state
self.action = action
self.parent = parent
self.totalCost = totalCost
self.heuristicCost = heuristicCost
##################################################################
# Methods
##################################################################
def evaluation(self):
return self.totalCost + self.heuristicCost
def __lt__(self, other):
return self.evaluation() < other.evaluation()