Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Commit

Permalink
got rid of parents, split up label in DPWObsNode
Browse files Browse the repository at this point in the history
  • Loading branch information
zsunberg committed Jul 20, 2016
1 parent e8fff98 commit 5797f23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
22 changes: 10 additions & 12 deletions src/solver.jl
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 12 additions & 10 deletions 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
Expand Down

0 comments on commit 5797f23

Please sign in to comment.