Skip to content

Commit

Permalink
removed MOMDP deps
Browse files Browse the repository at this point in the history
  • Loading branch information
etotheipluspi committed May 20, 2016
1 parent 2119a8a commit 4484468
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 236 deletions.
156 changes: 0 additions & 156 deletions src/policy.jl

This file was deleted.

85 changes: 5 additions & 80 deletions src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,6 @@ type POMDPPolicy <: SARSOPPolicy
end
end

#=
"""
MOMDPPolicy
Policy type for MOMDPs that contains a reference to the .policy file generated by pomdpsol.
Contains the alpha vectors and the action mapping required to execute a policy.
"""
type MOMDPPolicy <: SARSOPPolicy
filename::AbstractString
alphas::Alphas
pomdp::POMDP
action_map::Vector{Any}
MOMDPPolicy(filename::AbstractString, alphas::Alphas, pomdp) = new(filename, alphas, pomdp, Any[])
function MOMDPPolicy(filename="out.policy")
self = new()
self.filename = filename
if isfile(filename)
self.alphas = MOMDPAlphas(filename)
else
self.alphas = MOMDPAlphas()
end
return self
end
end
=#


"""
solve(solver, pomdp, policy)
Expand Down Expand Up @@ -145,19 +119,6 @@ function solve(solver::SARSOPSolver, pomdp::POMDP, policy::POMDPPolicy=create_po
return policy
end

#=
# generates a momdp policy file
function solve(solver::SARSOPSolver, pomdp::SARSOPFile, policy::MOMDPPolicy)
if isempty(solver.options)
run(`$EXEC_POMDP_SOL $(pomdp.filename) --output $(policy.filename)`)
else
options_list = _get_options_list(solver.options)
run(`$EXEC_POMDP_SOL $(pomdp.filename) --output $(policy.filename) $options_list`)
end
policy.alphas = MOMDPAlphas(policy.filename)
end
=#


function load_policy(pomdp::POMDP, file_name::AbstractString)
alphas = nothing
Expand Down Expand Up @@ -201,64 +162,28 @@ end
Returns the action index for a blief 'b' according to 'policy' for a POMDP.
"""
function action(policy::POMDPPolicy, b::DiscreteBelief)
vectors = policy.alphas.alpha_vectors
actions = policy.alphas.alpha_actions
vectors = alphas(policy)
actions = action_idxs(policy)
utilities = prod(vectors, b)
a = actions[indmax(utilities)] + 1
return a
end


function value(policy::POMDPAlphas, b::DiscreteBelief)
vectors = policy.alphas.alpha_vectors
actions = policy.alphas.alpha_actions
vectors = alphas(policy)
actions = action_idxs(policy)
utilities = prod(vectors, b)
v = maximum(utilities)
return v
end


#=
"""
action(policy, b, x)
Returns the action index for a blief 'b' according to 'policy' given the fully observable variable index 'x'.
Used for MOMDPs
"""
function action(policy::MOMDPPolicy, b::DiscreteBelief, x::Int64)
# for MOMDP
vectors = policy.alphas.alpha_vectors
actions = policy.alphas.alpha_actions
states = policy.alphas.observable_states
o = x - 1 # julia obs: 1-100, sarsop obs: 0-99
utilities = prod(vectors, b)
chunk = actions[find(s -> s == o, states)]
a = chunk[indmax(utilities[find(s -> s == o, states)])] + 1
return a
end
=#


function prod(alphas::Matrix{Float64}, b::DiscreteBelief)
@assert size(alphas, 1) == length(b) "Alpha and belief sizes not equal"
n = size(alphas, 2)
util = zeros(n)
for i = 1:n
s = 0.0
for j = 1:length(b)
s += alphas[j,i]*b[j]
end
util[i] = s
end
return util
end



"""
alphas(policy)
Returns the alpha vector matrix `vector length x number vectors`
"""
alphas(policy::SARSOPPolicy) = policy.alphas.alpha_vectors

action_idxs(policy::SARSOPPolicy) = policy.alphas.alpha_actions

0 comments on commit 4484468

Please sign in to comment.