2022-01-14 12:01:14 +00:00
|
|
|
using ..ReCo: Particle
|
|
|
|
|
2022-01-11 18:00:41 +00:00
|
|
|
function pre_integration_hook(::EnvHelper)
|
2022-01-14 12:01:14 +00:00
|
|
|
return ReCo.method_not_implemented()
|
2022-01-11 18:00:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function state_update_helper_hook(
|
|
|
|
::EnvHelper, id1::Int64, id2::Int64, r⃗₁₂::SVector{2,Float64}
|
|
|
|
)
|
2022-01-14 12:01:14 +00:00
|
|
|
return ReCo.method_not_implemented()
|
2022-01-11 18:00:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function state_update_hook(::EnvHelper, particles::Vector{Particle})
|
2022-01-14 12:01:14 +00:00
|
|
|
return ReCo.method_not_implemented()
|
2022-01-11 18:00:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function update_reward!(::Env, ::EnvHelper, particle::Particle)
|
2022-01-14 12:01:14 +00:00
|
|
|
return ReCo.method_not_implemented()
|
2022-01-11 18:00:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function update_table_and_actions_hook(
|
|
|
|
env_helper::EnvHelper, particle::Particle, first_integration_step::Bool
|
|
|
|
)
|
|
|
|
env, agent, hook = get_env_agent_hook(env_helper)
|
|
|
|
|
|
|
|
id = particle.id
|
|
|
|
|
|
|
|
if !first_integration_step
|
|
|
|
# Old state
|
2022-01-15 20:27:15 +00:00
|
|
|
env.shared.state_id = env_helper.shared.old_states_id[id]
|
2022-01-11 18:00:41 +00:00
|
|
|
|
2022-01-15 20:27:15 +00:00
|
|
|
action_id = env_helper.shared.actions_id[id]
|
2022-01-11 18:00:41 +00:00
|
|
|
|
|
|
|
# Pre act
|
2022-01-15 20:27:15 +00:00
|
|
|
agent(PRE_ACT_STAGE, env, action_id)
|
|
|
|
hook(PRE_ACT_STAGE, agent, env, action_id)
|
2022-01-11 18:00:41 +00:00
|
|
|
|
|
|
|
# Update to current state
|
2022-01-15 20:27:15 +00:00
|
|
|
env.shared.state_id = env_helper.shared.states_id[id]
|
2022-01-11 18:00:41 +00:00
|
|
|
|
|
|
|
# Update reward
|
|
|
|
update_reward!(env, env_helper, particle)
|
|
|
|
|
|
|
|
# Post act
|
|
|
|
agent(POST_ACT_STAGE, env)
|
|
|
|
hook(POST_ACT_STAGE, agent, env)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Update action
|
2022-01-15 20:27:15 +00:00
|
|
|
action_id = agent(env)
|
|
|
|
action = env.shared.action_space[action_id]
|
2022-01-11 18:00:41 +00:00
|
|
|
|
|
|
|
env_helper.shared.actions[id] = action
|
2022-01-15 20:27:15 +00:00
|
|
|
env_helper.shared.actions_id[id] = action_id
|
2022-01-11 18:00:41 +00:00
|
|
|
|
|
|
|
return nothing
|
|
|
|
end
|
|
|
|
|
|
|
|
act_hook(::Nothing, args...) = nothing
|
|
|
|
|
|
|
|
function act_hook(
|
|
|
|
env_helper::EnvHelper, particle::Particle, δt::Float64, si::Float64, co::Float64
|
|
|
|
)
|
|
|
|
# Apply action
|
|
|
|
action = env_helper.shared.actions[particle.id]
|
|
|
|
|
|
|
|
vδt = action[1] * δt
|
|
|
|
particle.tmp_c += SVector(vδt * co, vδt * si)
|
|
|
|
particle.φ += action[2] * δt
|
|
|
|
|
|
|
|
return nothing
|
|
|
|
end
|