use dict string key

This commit is contained in:
2026-06-25 05:28:28 +07:00
parent 25f539581e
commit 26dc2d7e60
3 changed files with 16 additions and 16 deletions
+3 -3
View File
@@ -64,10 +64,10 @@ function runMCTS(
saveSimulatedNode::Bool=false,
multithread=false,
)::NamedTuple{(:root, :bestNextState, :bestTerminalState, :highValueStateList),
Tuple{MCTSNode,T,T,Vector{Dict{Symbol,Any}}}} where {T<:Any}
Tuple{MCTSNode,T,T,Vector{Dict{String,Any}}}} where {T<:Any}
root = MCTSNode("root", initialstate, 0, 0, 0, 0, false, nothing, Dict{String,MCTSNode}(),
Dict{Symbol,Any}())
Dict{String,Any}())
# storage for holding all high reward terminal nodes
highValueState = Channel{Any}(100)
@@ -125,7 +125,7 @@ function runMCTS(
bestTerminalState = selectBestTrajectoryNode(root)
# take all high value state from highValueState channel and put it in a list
highValueStateList = Vector{Dict{Symbol, Any}}()
highValueStateList = Vector{Dict{String, Any}}()
while !isempty(highValueState)
push!(highValueStateList, take!(highValueState))
end
+12 -12
View File
@@ -120,14 +120,14 @@ end
```jldoctest
julia> using Revise
julia> using YiemAgent, DataStructures
julia> initialState = Dict{Symbol, Any}(
:customerinfo=> Dict{Symbol, Any}(),
:storeinfo=> Dict{Symbol, Any}(),
julia> initialState = Dict{String, Any}(
"customerinfo"=> Dict{String, Any}(),
"storeinfo"=> Dict{String, Any}(),
:thoughtHistory=> OrderedDict{Symbol, Any}(
:question=> "How are you?",
)
)
"thoughtHistory"=> OrderedDict{String, Any}(
"question"=> "How are you?",
)
)
julia> statetype = typeof(initialState)
julia> root = YiemAgent.MCTSNode(initialState, 0, 0.0, Dict{statetype, YiemAgent.MCTSNode}())
julia> YiemAgent.isleaf(root)
@@ -247,7 +247,7 @@ function _expand(node::MCTSNode,transition::Function, transitionargs::NamedTuple
"""
if newNodeKey keys(node.children)
newNode = MCTSNode(newNodeKey, newstate, 0, progressvalue, 0, newstate[:reward],
newstate[:isterminal], node, Dict{String, MCTSNode}(), Dict{Symbol, Any}())
newstate[:isterminal], node, Dict{String, MCTSNode}(), Dict{String, Any}())
node.children[newNodeKey] = newNode
end
end
@@ -273,14 +273,14 @@ end
# Return
- `simTrajectoryReward::Number`
Cumulative reward collected along the simulation trajectory
- `terminalstate::Union{Dict{Symbol, Any}, Nothing}`
- `terminalstate::Union{Dict{String, Any}, Nothing}`
Final state if terminal state reached, nothing otherwise
# Signature
"""
function simulate(node::MCTSNode, transition::Function, transitionargs::NamedTuple;
maxSimulationDepth::Integer=3, horizontalSample::Integer=3, multithread=false
)::NamedTuple{(:simTrajectoryReward, :terminalstate), Tuple{<:Number, Union{Dict{Symbol, Any}, Nothing}}}
)::NamedTuple{(:simTrajectoryReward, :terminalstate), Tuple{<:Number, Union{Dict{String, Any}, Nothing}}}
simTrajectoryReward = 0.0
terminalstate = nothing
@@ -319,7 +319,7 @@ end
# Whether this state is terminal
# # Return
# - `Tuple{String, Dict{Symbol, <:Any}}`
# - `Tuple{String, Dict{String, <:Any}}`
# A tuple containing:
# - A unique node key string
# - A new state dictionary with updated thought history and metadata
@@ -333,7 +333,7 @@ end
# """
# function makeNewState(currentstate::T1, thoughtDict::T4, response::T2, select::Union{T3, Nothing},
# reward::T3, isterminal::Bool
# )::Tuple{String, Dict{Symbol, <:Any}} where {T1<:AbstractDict, T2<:AbstractString, T3<:Number, T4<:AbstractDict}
# )::Tuple{String, Dict{String, <:Any}} where {T1<:AbstractDict, T2<:AbstractString, T3<:Number, T4<:AbstractDict}
# # Find the latest thought key and index from current state's thought history
# currentstate_latestThoughtKey, currentstate_latestThoughtIndice =
+1 -1
View File
@@ -58,7 +58,7 @@ mutable struct MCTSNode{T1<:AbstractDict, T2<:AbstractString}
isterminal::Bool
parent::Union{MCTSNode, Nothing}
children::Dict{String, MCTSNode}
etc::Dict{Symbol, Any} # store anything
etc::Dict{String, Any} # store anything
end