Commit 18cec392 by Jaeyoung Lee

Further improve Follow and make KeepLane default (available any time).

parent 1f913dc3
......@@ -53,9 +53,8 @@ class SimpleIntersectionEnv(RoadEnv, EpisodicEnvBase):
# can be set to a specific value which may be different than the default.
# TODO: check _cost_weights in both here and ManeuverBase. The _cost_weights has to be substituted to here, but it doesn't sometimes.
# TODO: set a functionality of setting _cost_weights for low and high level training separately.
_cost_weights = (0, 0, 0, 0, 0, 0, 0, 0)
#(10.0 * 1e-3, 10.0 * 1e-3, 0.25 * 1e-3, 1.0 * 1e-3,
#100.0 * 1e-3, 0.1 * 1e-3, 0.05 * 1e-3, 0.1 * 1e-3)
_cost_weights = (10.0 * 1e-3, 10.0 * 1e-3, 0.25 * 1e-3, 1.0 * 1e-3,
100.0 * 1e-3, 0.1 * 1e-3, 0.05 * 1e-3, 0.1 * 1e-3)
#TODO: Move this to constants
# The empirical min and max of each term in the cost vector, which is used to normalize the values
......
......@@ -30,9 +30,8 @@ class ManeuverBase(EpisodicEnvBase):
# as a negative reward, so a cost will be summed up to the reward
# with subtraction.
# TODO: remove or to provide additional functionality, keep _cost_weights in ManeuverBase here (see other TODOs in simple_intersection_env regarding _cost_weights).
_cost_weights = (0, 0, 0, 0, 0, 0, 0, 0)
#(10.0 * 1e-3, 10.0 * 1e-3, 0.25 * 1e-3, 1.0 * 1e-3,
#100.0 * 1e-3, 0.1 * 1e-3, 0.05 * 1e-3, 0.1 * 1e-3)
_cost_weights = (10.0 * 1e-3, 10.0 * 1e-3, 0.25 * 1e-3, 1.0 * 1e-3,
100.0 * 1e-3, 0.1 * 1e-3, 0.05 * 1e-3, 0.1 * 1e-3)
_extra_r_terminal = None
_extra_r_on_timeout = None
......
......@@ -53,6 +53,16 @@ class KeepLane(ManeuverBase):
return extract_ego_features(features_tuple, 'v', 'v_ref', 'e_y', 'psi', 'v tan(psi/L)', 'theta', 'lane', 'acc', 'psi_dot')
@property
def initiation_condition(self):
"""a virtual function (property) from ManeuverBase.
As KeepLane is a default maneuver, it has to be activated to be chosen at any time, state, and condition
(refer to initiation_condition of ManeuverBase for the usual case.
:returns True.
"""
return True
@property
def extra_termination_condition(self):
if self._enable_low_level_training_properties: # activated only for the low-level training.
if (self.env.ego.v < self._v_ref / 5) and self.env.ego.acc < 0:
......@@ -383,6 +393,7 @@ class ChangeLane(ManeuverBase):
'psi_dot')
# TODO: In the low-level training of Follow, sometime the initial state doesn't satisfy its initiation condition.
class Follow(ManeuverBase):
_reward_in_goal = None
......@@ -422,7 +433,6 @@ class Follow(ManeuverBase):
self.env._terminate_in_goal = False
self._penalty_for_out_of_range = 200
self._penalty_for_change_lane = 200
self._reward_in_goal = 200
self._enable_low_level_training_properties = True
self._extra_action_weights_flag = True
......@@ -436,7 +446,6 @@ class Follow(ManeuverBase):
self._set_v_ref()
def _set_v_ref(self):
#if self._enable_low_level_training_properties:
self._target_veh_i, _ = self.env.get_V2V_distance()
if self._target_veh_i is not None:
......@@ -460,23 +469,18 @@ class Follow(ManeuverBase):
@property
def extra_termination_condition(self):
# APs = self.env.ego.APs
if self._target_veh_i is None:
return False
if self._enable_low_level_training_properties: # activated only for the low-level training.
if self.env.ego.APs['has_stopped_in_stop_region'] and \
self.env.ego.APs['in_stop_region']:
self._extra_r_terminal = None
return True
elif (rd.speed_limit / 5 < self._v_ref) and \
APs = self.env.ego.APs
if (rd.speed_limit / 5 < self._v_ref) and \
(self.env.ego.v < self._v_ref / 2) and \
self.env.ego.acc < 0 and \
not self.env.ego.APs['veh_ahead_stopped_now']:
self._extra_r_terminal = -100
return True
not APs['veh_ahead_stopped_now'] and \
not APs['in_stop_region']:
self._extra_r_terminal = -100
return True
else:
self._extra_r_terminal = None
......@@ -493,4 +497,4 @@ class Follow(ManeuverBase):
return ego_features + extract_other_veh_features(
features_tuple, self._target_veh_i, 'rel_x', 'rel_y', 'v', 'acc')
else:
return ego_features + (0.0, 0.0, 0.0, 0.0)
\ No newline at end of file
return ego_features + (0.0, 0.0, 0.0, 0.0)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment