1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-12-21 00:51:21 +00:00

Apply to all Envs

This commit is contained in:
Mo 2022-05-01 18:13:35 +02:00
parent d12d7d658a
commit 09684db724
8 changed files with 59 additions and 45 deletions

View file

@ -47,7 +47,7 @@ struct EnvHelperSharedProps{H<:AbstractHook}
end
end
function gen_env_helper(::Env, env_helper_params::EnvHelperSharedProps; args)
function gen_env_helper(::Env, env_helper_params::EnvHelperSharedProps; kwargs...)
return ReCo.method_not_implemented()
end

View file

@ -11,11 +11,11 @@ struct COMCompassEnv <: Env
direction_angle_state_space::Vector{Interval}
position_angle_state_space::Vector{Interval}
function COMCompassEnv(;
function COMCompassEnv(
args;
n_distance_states::Int64=3,
n_direction_angle_states::Int64=3,
n_position_angle_states::Int64=8,
args,
)
@assert n_distance_states > 1
@assert n_direction_angle_states > 1
@ -63,7 +63,7 @@ mutable struct COMCompassEnvHelper <: EnvHelper
half_box_len::Float64
max_elliptical_distance::Float64
function COMCompassEnvHelper(shared::EnvHelperSharedProps, half_box_len::Float64)
function COMCompassEnvHelper(shared::EnvHelperSharedProps; half_box_len::Float64)
max_elliptical_distance = sqrt(
half_box_len^2 + (half_box_len / shared.elliptical_b_a_ratio)^2
)
@ -79,8 +79,8 @@ mutable struct COMCompassEnvHelper <: EnvHelper
end
end
function gen_env_helper(::COMCompassEnv, env_helper_shared::EnvHelperSharedProps; args)
return COMCompassEnvHelper(env_helper_shared, args.half_box_len)
function gen_env_helper(::COMCompassEnv, env_helper_shared::EnvHelperSharedProps; kwargs...)
return COMCompassEnvHelper(env_helper_shared; kwargs...)
end
function pre_integration_hook!(::COMCompassEnvHelper)

View file

@ -10,8 +10,8 @@ struct LocalCOMEnv <: Env
distance_state_space::Vector{Interval}
direction_angle_state_space::Vector{Interval}
function LocalCOMEnv(;
n_distance_states::Int64=3, n_direction_angle_states::Int64=3, args
function LocalCOMEnv(
args; n_distance_states::Int64=3, n_direction_angle_states::Int64=3
)
@assert n_distance_states > 1
@assert n_direction_angle_states > 1
@ -52,7 +52,7 @@ mutable struct LocalCOMEnvHelper <: EnvHelper
half_box_len::Float64
function LocalCOMEnvHelper(
shared::EnvHelperSharedProps, half_box_len::Float64, skin_radius::Float64
shared::EnvHelperSharedProps; half_box_len::Float64, skin_radius::Float64
)
max_distance_to_local_center_of_mass = skin_radius
@ -67,8 +67,8 @@ mutable struct LocalCOMEnvHelper <: EnvHelper
end
end
function gen_env_helper(::LocalCOMEnv, env_helper_shared::EnvHelperSharedProps; args)
return LocalCOMEnvHelper(env_helper_shared, args.half_box_len, args.skin_radius)
function gen_env_helper(::LocalCOMEnv, env_helper_shared::EnvHelperSharedProps; kwargs...)
return LocalCOMEnvHelper(env_helper_shared; kwargs...)
end
function pre_integration_hook!(env_helper::LocalCOMEnvHelper)

View file

@ -5,7 +5,7 @@ The minimization variable of the additional reward term is the individual ellipt
using ..ReCo: ReCo
const TRIGGER = 0.6
const DEFAULT_TRIGGER = 0.35
struct LocalCOMWithAdditionalShapeRewardEnv <: Env
shared::EnvSharedProps
@ -13,8 +13,8 @@ struct LocalCOMWithAdditionalShapeRewardEnv <: Env
distance_state_space::Vector{Interval}
direction_angle_state_space::Vector{Interval}
function LocalCOMWithAdditionalShapeRewardEnv(;
n_distance_states::Int64=3, n_direction_angle_states::Int64=3, args
function LocalCOMWithAdditionalShapeRewardEnv(
args; n_distance_states::Int64=3, n_direction_angle_states::Int64=3
)
@assert n_distance_states > 1
@assert n_direction_angle_states > 1
@ -61,8 +61,13 @@ mutable struct LocalCOMWithAdditionalShapeRewardEnvHelper <: EnvHelper
half_box_len::Float64
max_elliptical_distance::Float64
trigger::Float64
function LocalCOMWithAdditionalShapeRewardEnvHelper(
shared::EnvHelperSharedProps, half_box_len::Float64, skin_radius::Float64
shared::EnvHelperSharedProps;
half_box_len::Float64,
skin_radius::Float64,
trigger::Float64=DEFAULT_TRIGGER,
)
max_elliptical_distance = sqrt(
half_box_len^2 + (half_box_len / shared.elliptical_b_a_ratio)^2
@ -82,16 +87,17 @@ mutable struct LocalCOMWithAdditionalShapeRewardEnvHelper <: EnvHelper
SVector(0.0, 0.0),
half_box_len,
max_elliptical_distance,
trigger,
)
end
end
function gen_env_helper(
::LocalCOMWithAdditionalShapeRewardEnv, env_helper_shared::EnvHelperSharedProps; args
)
return LocalCOMWithAdditionalShapeRewardEnvHelper(
env_helper_shared, args.half_box_len, args.skin_radius
::LocalCOMWithAdditionalShapeRewardEnv,
env_helper_shared::EnvHelperSharedProps;
kwargs...,
)
return LocalCOMWithAdditionalShapeRewardEnvHelper(env_helper_shared; kwargs...)
end
function pre_integration_hook!(env_helper::LocalCOMWithAdditionalShapeRewardEnvHelper)
@ -160,7 +166,7 @@ function state_update_hook!(
distance_to_local_center_of_mass_sum / n_particles
env_helper.add_shape_reward_term =
mean_distance_to_local_center_of_mass /
env_helper.max_distance_to_local_center_of_mass < TRIGGER
env_helper.max_distance_to_local_center_of_mass < env_helper.trigger
if env_helper.add_shape_reward_term
print("*")
end

View file

@ -5,7 +5,7 @@ The minimization variable of the additional reward term is the absolute differen
using ..ReCo: ReCo
const TRIGGER = 0.6
const DEFAULT_TRIGGER = 0.35
struct LocalCOMWithAdditionalShapeRewardEnv2 <: Env
shared::EnvSharedProps
@ -13,8 +13,8 @@ struct LocalCOMWithAdditionalShapeRewardEnv2 <: Env
distance_state_space::Vector{Interval}
direction_angle_state_space::Vector{Interval}
function LocalCOMWithAdditionalShapeRewardEnv2(;
n_distance_states::Int64=3, n_direction_angle_states::Int64=3, args
function LocalCOMWithAdditionalShapeRewardEnv2(
args; n_distance_states::Int64=3, n_direction_angle_states::Int64=3
)
@assert n_distance_states > 1
@assert n_direction_angle_states > 1
@ -60,8 +60,13 @@ mutable struct LocalCOMWithAdditionalShapeRewardEnv2Helper <: EnvHelper
half_box_len::Float64
trigger::Float64
function LocalCOMWithAdditionalShapeRewardEnv2Helper(
shared::EnvHelperSharedProps, half_box_len::Float64, skin_radius::Float64
shared::EnvHelperSharedProps;
half_box_len::Float64,
skin_radius::Float64,
trigger::Float64=DEFAULT_TRIGGER,
)
goal_κ = 0.4
max_distance_to_goal_κ = max(1 - goal_κ, goal_κ)
@ -79,16 +84,17 @@ mutable struct LocalCOMWithAdditionalShapeRewardEnv2Helper <: EnvHelper
goal_κ,
max_distance_to_goal_κ,
half_box_len,
trigger,
)
end
end
function gen_env_helper(
::LocalCOMWithAdditionalShapeRewardEnv2, env_helper_shared::EnvHelperSharedProps; args
)
return LocalCOMWithAdditionalShapeRewardEnv2Helper(
env_helper_shared, args.half_box_len, args.skin_radius
::LocalCOMWithAdditionalShapeRewardEnv2,
env_helper_shared::EnvHelperSharedProps;
kwargs...,
)
return LocalCOMWithAdditionalShapeRewardEnv2Helper(env_helper_shared; kwargs...)
end
function pre_integration_hook!(env_helper::LocalCOMWithAdditionalShapeRewardEnv2Helper)
@ -158,7 +164,7 @@ function state_update_hook!(
distance_to_local_center_of_mass_sum / n_particles
env_helper.add_shape_reward_term =
mean_distance_to_local_center_of_mass /
env_helper.max_distance_to_local_center_of_mass < TRIGGER
env_helper.max_distance_to_local_center_of_mass < env_helper.trigger
return nothing
end

View file

@ -10,8 +10,8 @@ struct NearestNeighborEnv <: Env
distance_state_space::Vector{Interval}
direction_angle_state_space::Vector{Interval}
function NearestNeighborEnv(;
n_distance_states::Int64=3, n_direction_angle_states::Int64=3, args
function NearestNeighborEnv(
args; n_distance_states::Int64=3, n_direction_angle_states::Int64=3
)
@assert n_distance_states > 1
@assert n_direction_angle_states > 1
@ -52,7 +52,7 @@ mutable struct NearestNeighborEnvHelper <: EnvHelper
half_box_len::Float64
function NearestNeighborEnvHelper(shared::EnvHelperSharedProps, half_box_len::Float64)
function NearestNeighborEnvHelper(shared::EnvHelperSharedProps; half_box_len::Float64)
goal_κ = 0.4
max_distance_to_goal_κ = max(1 - goal_κ, goal_κ)
@ -68,8 +68,10 @@ mutable struct NearestNeighborEnvHelper <: EnvHelper
end
end
function gen_env_helper(::NearestNeighborEnv, env_helper_shared::EnvHelperSharedProps; args)
return NearestNeighborEnvHelper(env_helper_shared, args.half_box_len)
function gen_env_helper(
::NearestNeighborEnv, env_helper_shared::EnvHelperSharedProps; kwargs...
)
return NearestNeighborEnvHelper(env_helper_shared; kwargs...)
end
function pre_integration_hook!(env_helper::NearestNeighborEnvHelper)

View file

@ -11,11 +11,11 @@ struct OriginCompassEnv <: Env
direction_angle_state_space::Vector{Interval}
position_angle_state_space::Vector{Interval}
function OriginCompassEnv(;
function OriginCompassEnv(
args;
n_distance_states::Int64=3,
n_direction_angle_states::Int64=3,
n_position_angle_states::Int64=8,
args,
)
@assert n_distance_states > 1
@assert n_direction_angle_states > 1
@ -63,7 +63,7 @@ mutable struct OriginCompassEnvHelper <: EnvHelper
half_box_len::Float64
max_elliptical_distance::Float64
function OriginCompassEnvHelper(shared::EnvHelperSharedProps, half_box_len::Float64)
function OriginCompassEnvHelper(shared::EnvHelperSharedProps; half_box_len::Float64)
max_elliptical_distance = sqrt(
half_box_len^2 + (half_box_len / shared.elliptical_b_a_ratio)^2
)
@ -79,8 +79,10 @@ mutable struct OriginCompassEnvHelper <: EnvHelper
end
end
function gen_env_helper(::OriginCompassEnv, env_helper_shared::EnvHelperSharedProps; args)
return OriginCompassEnvHelper(env_helper_shared, args.half_box_len)
function gen_env_helper(
::OriginCompassEnv, env_helper_shared::EnvHelperSharedProps; kwargs...
)
return OriginCompassEnvHelper(env_helper_shared; kwargs...)
end
function pre_integration_hook!(::OriginCompassEnvHelper)

View file

@ -10,9 +10,7 @@ struct OriginEnv <: Env
distance_state_space::Vector{Interval}
direction_angle_state_space::Vector{Interval}
function OriginEnv(;
n_distance_states::Int64=3, n_direction_angle_states::Int64=3, args
)
function OriginEnv(args; n_distance_states::Int64=3, n_direction_angle_states::Int64=3)
@assert n_distance_states > 1
@assert n_direction_angle_states > 1
@ -47,7 +45,7 @@ mutable struct OriginEnvHelper <: EnvHelper
half_box_len::Float64
function OriginEnvHelper(shared::EnvHelperSharedProps, half_box_len::Float64)
function OriginEnvHelper(shared::EnvHelperSharedProps; half_box_len::Float64)
max_distance_to_origin = sqrt(2) * half_box_len
return new(
@ -56,8 +54,8 @@ mutable struct OriginEnvHelper <: EnvHelper
end
end
function gen_env_helper(::OriginEnv, env_helper_shared::EnvHelperSharedProps; args)
return OriginEnvHelper(env_helper_shared, args.half_box_len)
function gen_env_helper(::OriginEnv, env_helper_shared::EnvHelperSharedProps; kwargs...)
return OriginEnvHelper(env_helper_shared; kwargs...)
end
function pre_integration_hook!(::OriginEnvHelper)