update
This commit is contained in:
+12
-40
@@ -199,47 +199,18 @@ end
|
||||
# Signature
|
||||
"""
|
||||
function expand(node::MCTSNode,transition::Function, transitionargs::NamedTuple;
|
||||
horizontalSample::Integer=3)
|
||||
@sync for i in 1:horizontalSample
|
||||
@spawn _expand(node, transition, transitionargs)
|
||||
horizontalSample::Integer=3, multithread=false)
|
||||
if multithread
|
||||
@sync for i in 1:horizontalSample
|
||||
@spawn _expand(node, transition, transitionargs)
|
||||
end
|
||||
else
|
||||
for i in 1:horizontalSample
|
||||
_expand(node, transition, transitionargs)
|
||||
end
|
||||
end
|
||||
|
||||
#CHANGE for testing
|
||||
# for i in 1:horizontalSample
|
||||
# _expand(node, transition, transitionargs)
|
||||
# end
|
||||
end
|
||||
# function expand(node::MCTSNode,transition::Function, transitionargs::NamedTuple;
|
||||
# horizontalSample::Integer=3)
|
||||
|
||||
# nthSample = 0
|
||||
# listOfNewNodeId = []
|
||||
# while true
|
||||
# nthSample += 1
|
||||
# if nthSample <= horizontalSample
|
||||
# result = transition(node.state, transitionargs)
|
||||
# newNodeKey::AbstractString = result[:newNodeKey]
|
||||
# newstate::AbstractDict = result[:newstate]
|
||||
# progressvalue::Integer = result[:progressvalue]
|
||||
|
||||
# """
|
||||
# [] newNodeKey ∉ keys(node.children).
|
||||
# New state may have semantic vector close enought to
|
||||
# one of existing child state. Which can be assume that they are the same state
|
||||
# semantically-wise i.e. De javu. This could be used to recall lessons for this
|
||||
# similar situation to improve decisionMaker and evaluator.
|
||||
# """
|
||||
# if newNodeKey ∉ keys(node.children)
|
||||
# push!(listOfNewNodeId, newNodeKey)
|
||||
# newNode = MCTSNode(newNodeKey, newstate, 0, progressvalue, 0, newstate[:reward],
|
||||
# newstate[:isterminal], node, Dict{String, MCTSNode}(), Dict{Symbol, Any}())
|
||||
# node.children[newNodeKey] = newNode
|
||||
# end
|
||||
# else
|
||||
# return listOfNewNodeId
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
function _expand(node::MCTSNode,transition::Function, transitionargs::NamedTuple)
|
||||
result = transition(node.state, transitionargs)
|
||||
@@ -282,7 +253,7 @@ end
|
||||
# Signature
|
||||
"""
|
||||
function simulate(node::MCTSNode, transition::Function, transitionargs::NamedTuple;
|
||||
maxSimulationDepth::Integer=3, horizontalSample::Integer=3)
|
||||
maxSimulationDepth::Integer=3, horizontalSample::Integer=3, multithread=false)
|
||||
# )::NamedTuple{(:simTrajectoryReward, :terminalstate), Tuple{Number, Union{Dict{Symbol, Any}, Nothing}}}
|
||||
|
||||
simTrajectoryReward = 0.0
|
||||
@@ -295,7 +266,8 @@ function simulate(node::MCTSNode, transition::Function, transitionargs::NamedTup
|
||||
break
|
||||
else
|
||||
_ = expand(node, transition, transitionargs;
|
||||
horizontalSample=horizontalSample)
|
||||
horizontalSample=horizontalSample,
|
||||
multithread=multithread)
|
||||
node = selectChildNode(node)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user