Skip to content
This repository has been archived by the owner on Apr 26, 2023. It is now read-only.

Commit

Permalink
added type stability tests to rollout and made RandomPolicy faster
Browse files Browse the repository at this point in the history
  • Loading branch information
zsunberg committed Jul 27, 2017
1 parent e8538e1 commit 960c6ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/policies/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"""
a generic policy that uses the actions function to create a list of actions and then randomly samples an action from it.
"""
mutable struct RandomPolicy <: Policy
rng::AbstractRNG
problem::Union{POMDP,MDP}
updater::Updater # set this to use a custom updater, by default it will be a void updater
mutable struct RandomPolicy{RNG<:AbstractRNG, P<:Union{POMDP,MDP}, U<:Updater} <: Policy
rng::RNG
problem::P
updater::U # set this to use a custom updater, by default it will be a void updater
end
# The constructor below should be used to create the policy so that the action space is initialized correctly
RandomPolicy(problem::Union{POMDP,MDP};
Expand Down
4 changes: 2 additions & 2 deletions test/test_rollout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ let
solver = RandomSolver(rng=MersenneTwister(1))
policy = solve(solver, problem)
sim = RolloutSimulator(max_steps=10, rng=MersenneTwister(1))
r1 = simulate(sim, problem, policy, updater(policy), initial_state_distribution(problem))
r1 = @inferred simulate(sim, problem, policy, updater(policy), initial_state_distribution(problem))

problem = GridWorld()
solver = RandomSolver(rng=MersenneTwister(1))
policy = solve(solver, problem)
sim = RolloutSimulator(max_steps=10, rng=MersenneTwister(1))
r2 = simulate(sim, problem, policy, initial_state(problem, sim.rng))
r2 = @inferred simulate(sim, problem, policy, initial_state(problem, sim.rng))

@test isapprox(r1, -27.27829, atol=1e-3)
@test isapprox(r2, 0.0, atol=1e-3)
Expand Down

0 comments on commit 960c6ca

Please sign in to comment.