This commit is contained in:
2025-03-09 11:26:13 +07:00
parent 9add88b145
commit 4bf3a78daf
4 changed files with 228 additions and 177 deletions
+7 -9
View File
@@ -272,8 +272,8 @@ end
A user function that handles how state transition.
- `transitionargs::NamedTuple`
Arguments for everything the user will use within transition().
- `maxdepth::Integer`
maximum depth level MCTS goes vertically.
- `maxSimulationDepth::Integer`
maximum depth level MCTS goes vertically during simulation.
- horizontalSample::Integer
Total number to sample from the current node (i.e. expand new node horizontally)
@@ -282,15 +282,14 @@ end
# Signature
"""
function simulate(outputchannel::Channel, node::MCTSNode, transition::Function, transitionargs::NamedTuple;
maxdepth::Integer=3, horizontalSample::Integer=3
)::NamedTuple{(:simTrajectoryReward, :terminalstate), Tuple{Number, Union{Dict{Symbol, Any}, Nothing}}}
function simulate(node::MCTSNode, transition::Function, transitionargs::NamedTuple;
maxSimulationDepth::Integer=3, horizontalSample::Integer=3)
# )::NamedTuple{(:simTrajectoryReward, :terminalstate), Tuple{Number, Union{Dict{Symbol, Any}, Nothing}}}
simTrajectoryReward = 0.0
terminalstate = nothing
# listOfSimulatedNodeId = []
for depth in 1:maxdepth
for depth in 1:maxSimulationDepth
simTrajectoryReward += node.reward
if node.isterminal
terminalstate = node.state
@@ -302,8 +301,7 @@ function simulate(outputchannel::Channel, node::MCTSNode, transition::Function,
end
end
put!(outputchannel, (simTrajectoryReward=simTrajectoryReward, terminalstate=terminalstate))
# return (simTrajectoryReward=simTrajectoryReward, terminalstate=terminalstate)
return (simTrajectoryReward=simTrajectoryReward, terminalstate=terminalstate)
end