def additional_command(self): """See parent class. This method performs to auxiliary tasks: * Define which vehicles are observed for visualization purposes. * Maintains the "rl_veh" and "rl_queue" variables to ensure the RL vehicles that are represented in the state space does not change until one of the vehicles in the state space leaves the network. Then, the next vehicle in the queue is added to the state space and provided with actions from the policy. """ super(AVOpenEnv, self).additional_command() # Update the RL lists. self.rl_queue, self.rl_veh, self.removed_veh = update_rl_veh( self, rl_queue=self.rl_queue, rl_veh=self.rl_veh, removed_veh=self.removed_veh, control_range=self._control_range, num_rl=self.num_rl, rl_ids=reversed( sorted(self.k.vehicle.get_rl_ids(), key=self.k.vehicle.get_x_by_id)), ) # Specify actions for the uncontrolled RL vehicles based on human- # driven dynamics. for veh_id in list( set(self.k.vehicle.get_rl_ids()) - set(self.rl_veh)): self._rl_controller.veh_id = veh_id acceleration = self._rl_controller.get_action(self) self.k.vehicle.apply_acceleration(veh_id, acceleration)
def additional_command(self): """See parent class. Here, the operations are done at a per-lane level. """ for lane in range(self._num_lanes): # Collect the names of the RL vehicles on the given lane, while # tacking into account edges with an extra lane. rl_ids = [ veh for veh in self.k.vehicle.get_rl_ids() if get_lane(self, veh) == lane ] # Update the RL lists. self.rl_queue[lane], self.rl_veh[lane], self.removed_veh = \ update_rl_veh( self, rl_queue=self.rl_queue[lane], rl_veh=self.rl_veh[lane], removed_veh=self.removed_veh, control_range=self._control_range, num_rl=self.num_rl, rl_ids=reversed(sorted( rl_ids, key=self.k.vehicle.get_x_by_id)), ) # Specify actions for the uncontrolled RL vehicles based on human- # driven dynamics. for veh_id in list(set(rl_ids) - set(self.rl_veh[lane])): self._rl_controller.veh_id = veh_id acceleration = self._rl_controller.get_action(self) self.k.vehicle.apply_acceleration(veh_id, acceleration) # Specify observed vehicles. for veh_id in self.leader + self.follower: self.k.vehicle.set_observed(veh_id)
def additional_command(self): """See definition in AVOpenEnv.""" super(AVOpenMultiAgentEnv, self).additional_command() # Update the RL lists. self.rl_queue, self.rl_veh, self.removed_veh = update_rl_veh( self, rl_queue=self.rl_queue, rl_veh=self.rl_veh, removed_veh=self.removed_veh, control_range=self._control_range, num_rl=self.num_rl, rl_ids=reversed( sorted(self.k.vehicle.get_rl_ids(), key=self.k.vehicle.get_x_by_id)), ) # Specify actions for the uncontrolled RL vehicles based on human- # driven dynamics. for veh_id in list( set(self.k.vehicle.get_rl_ids()) - set(self.rl_veh)): self._rl_controller.veh_id = veh_id acceleration = self._rl_controller.get_action(self) self.k.vehicle.apply_acceleration(veh_id, acceleration)