-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeNode_class.py
More file actions
29 lines (26 loc) · 1.16 KB
/
TreeNode_class.py
File metadata and controls
29 lines (26 loc) · 1.16 KB
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
import math
class TreeNode:
"""Represents a node in the search tree for task planning"""
def __init__(self, node_id, parent=None):
self.node_id = node_id
self.parent = parent
self.child_nodes = []
self.successes = 0
self.explored_count = 0
self.available_actions = []
def create_child(self, node_id):
"""Creates a new child node and links it to the current node"""
new_node = TreeNode(node_id, self)
self.child_nodes.append(new_node)
return new_node
def record_result(self, outcome):
"""Records the outcome of a simulation for this node"""
self.explored_count += 1
self.successes += outcome
def calculate_priority_score(self, total_iterations, exploration_constant=1.414):
"""Calculates node priority using Upper Confidence Bound formula"""
if self.explored_count == 0:
return float('inf')
success_rate = self.successes / self.explored_count
exploration_term = exploration_constant * math.sqrt(math.log(total_iterations) / self.explored_count)
return success_rate + exploration_term