From 5797f238b9dabbc3d64808b9aa3b4f2065d5a56d Mon Sep 17 00:00:00 2001 From: Zachary Sunberg Date: Wed, 20 Jul 2016 16:24:14 -0700 Subject: [PATCH] got rid of parents, split up label in DPWObsNode --- src/solver.jl | 22 ++++++++++------------ src/tree.jl | 22 ++++++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/solver.jl b/src/solver.jl index 60d3596..7a18013 100644 --- a/src/solver.jl +++ b/src/solver.jl @@ -79,8 +79,7 @@ function simulate{S,A,O,B}(pomcp::POMCPPlanner{S,A,O,POMCPSolver{B}}, h::BeliefN h.children[a] = ActNode(a, init_N(pomcp.problem, h, a), init_V(pomcp.problem, h, a), - h, - Dict{O,BeliefNode{S,A,O,B}}()) + Dict{O,ObsNode{S,A,O,B}}()) end return POMDPs.discount(pomcp.problem)^depth * estimate_value(pomcp, pomcp.problem, s, h) @@ -107,10 +106,10 @@ function simulate{S,A,O,B}(pomcp::POMCPPlanner{S,A,O,POMCPSolver{B}}, h::BeliefN hao = best_node.children[o] else if isa(pomcp.solver.node_belief_updater, ParticleReinvigorator) - hao = ObsNode(o, 0, ParticleCollection{S}(), best_node, Dict{A,ActNode{S,A,O,B}}()) + hao = ObsNode(o, 0, ParticleCollection{S}(), Dict{A,ActNode{A,O,ObsNode{S,A,O,B}}}()) else new_belief = update(pomcp.solver.node_belief_updater, h.B, a, o) # this relies on h.B not being modified - hao = ObsNode(o, 0, new_belief, best_node, Dict{A,ActNode{S,A,O,B}}()) + hao = ObsNode(o, 0, new_belief, Dict{A,ActNode{A,O,ObsNode{S,A,O,B}}}()) end best_node.children[o]=hao end @@ -142,8 +141,7 @@ function simulate{S,A,O,B}(pomcp::POMCPPlanner{S,A,O,POMCPDPWSolver{B}}, h::Beli h.children[a] = ActNode(a, init_N(pomcp.problem, h, a), init_V(pomcp.problem, h, a), - h, - Dict{O,BeliefNode{S,A,O,B}}()) + Dict{O,DPWObsNode{S,A,O,B}}()) end if length(h.children) <= 1 return POMDPs.discount(pomcp.problem)^depth * estimate_value(pomcp, pomcp.problem, s, h) @@ -174,20 +172,20 @@ function simulate{S,A,O,B}(pomcp::POMCPPlanner{S,A,O,POMCPDPWSolver{B}}, h::Beli hao = best_node.children[o] else if isa(pomcp.solver.node_belief_updater, ParticleReinvigorator) - hao = ObsNodeDPW((o, sp, r,), 0, ParticleCollection{S}(), best_node, Dict{A,ActNode{S,A,O,B}}()) + hao = DPWObsNode(o, sp, r, 0, ParticleCollection{S}(), Dict{A,ActNode{A,O,DPWObsNode{S,A,O,B}}}()) else new_belief = update(pomcp.solver.node_belief_updater, h.B, a, o) # this relies on h.B not being modified - hao = ObsNodeDPW((o, sp, r,), 0, new_belief, best_node, Dict{Any,ActNode{S,A,O,B}}()) + hao = DPWObsNode(o, sp, r, 0, new_belief, Dict{A,ActNode{A,O,DPWObsNode{S,A,O,B}}}()) end best_node.children[o]=hao end else # otherwise sample nodes - os = collect(values(best_node.children)) - wv = WeightVec(Int[node.N for node in os]) + os = collect(values(best_node.children)) # XXX allocation + wv = WeightVec(Int[node.N for node in os]) # XXX allocation hao = sample(pomcp.solver.rng, os, wv) - sp = hao.label[2] - r = hao.label[3] + sp = hao.state + r = hao.reward end R = r + POMDPs.discount(pomcp.problem)*simulate(pomcp, hao, sp, depth+1) diff --git a/src/tree.jl b/src/tree.jl index 32e41ad..3954dd1 100644 --- a/src/tree.jl +++ b/src/tree.jl @@ -1,27 +1,29 @@ abstract BeliefNode{S,A,O,B} -type ActNode{S,A,O,B} # Need A, O, everything in belief +# Note: links to parents were taken out because they hadn't been used in anything we've done so far +# Note: the label is really only important for visualization + +type ActNode{A, O, BNodeType <: BeliefNode} # Need A, O, everything in belief label::A # for keeping track of which action this corresponds to N::Int64 V::Float64 - parent::BeliefNode - children::Dict{O,BeliefNode{S,A,O,B}} # maps observations to ObsNodes + children::Dict{O, BNodeType} # maps observations to ObsNodes end -type ObsNodeDPW{S,A,O,Belief} <: BeliefNode{S,A,O,Belief} - label::Tuple{O,S,Float64} # observation, state, reward +type DPWObsNode{S,A,O,Belief} <: BeliefNode{S,A,O,Belief} + label::O + state::S + reward::Float64 N::Int64 B::Belief # belief/state distribution - parent::ActNode{S,A,O,Belief} - children::Dict{A,ActNode{S,A,O,Belief}} + children::Dict{A,ActNode{A,O,DPWObsNode{S,A,O,Belief}}} end type ObsNode{S,A,O,Belief} <: BeliefNode{S,A,O,Belief} label::O N::Int64 - B::Belief # belief/state distribution # perhaps should be nullable in the future - parent::ActNode{S,A,O,Belief} - children::Dict{A,ActNode{S,A,O,Belief}} + B::Belief # belief/state distribution + children::Dict{A,ActNode{A,O,ObsNode{S,A,O,Belief}}} end type RootNode{RootBelief} <: BeliefNode