MCPcopy Index your code
hub / github.com/algorithmicsuperintelligence/optillm / expand

Method expand

optillm/mcts.py:54–67  ·  view source on GitHub ↗
(self, node: MCTSNode)

Source from the content-addressed store, hash-verified

52 return selected_node
53
54 def expand(self, node: MCTSNode) -> MCTSNode:
55 logger.debug(f"Expanding node. Current state: {node.state}")
56 actions = self.generate_actions(node.state)
57 logger.debug(f"Generated {len(actions)} possible actions")
58 for i, action in enumerate(actions):
59 new_state = self.apply_action(node.state, action)
60 child = MCTSNode(new_state, parent=node)
61 node.children.append(child)
62 self.graph.add_edge(id(node), id(child))
63 self.node_labels[id(child)] = f"Visits: {child.visits}\nValue: {child.value:.2f}"
64 logger.debug(f"Created child node {i+1}. Action: {action[:50]}...")
65 selected_child = random.choice(node.children)
66 logger.debug(f"Randomly selected child node for simulation. Visits: {selected_child.visits}, Value: {selected_child.value}")
67 return selected_child
68
69 def simulate(self, node: MCTSNode) -> float:
70 logger.debug(f"Starting simulation from node. Current query: {node.state.current_query}")

Callers 1

searchMethod · 0.95

Calls 3

generate_actionsMethod · 0.95
apply_actionMethod · 0.95
MCTSNodeClass · 0.85

Tested by

no test coverage detected