Observation Functions¶
In this section, we describe how to implement and extend observation functions in RouteRL
. Observation functions are responsible for defining the observations available to agents interacting with the environment.
To create a new observation function, you must define a class that inherits from the Observations
base class. Below, we outline the structure of the Observations
class and provide details about its members and functionality:
Observations Class¶
- class routerl.environment.Observations(machine_agents_list: List[Any], human_agents_list: List[Any])[source]
Abstract base class for observation functions.
- Parameters:
machine_agents_list (List[Any]) – List of machine agents.
human_agents_list (List[Any]) – List of human agents.
- abstractmethod observation_space() Dict[str, Box] [source]
Define the observation space for the observation function.
- Returns:
Dict[str, Box] – A dictionary where keys are agent IDs and values are Gym spaces.
Default Observation Function: PreviousAgentStart
¶
The PreviousAgentStart
class serves as the default implementation for observation functions in RouteRL
. This class is designed to monitor and manage the number of agents with identical origin-destination pairs and start times, operating within a predefined threshold.
Details of the PreviousAgentStart
class are provided below:
- class routerl.environment.observations.PreviousAgentStart(machine_agents_list: List[Any], human_agents_list: List[Any], simulation_params: Dict[str, Any], agent_params: Dict[str, Any])[source]
Observes the number of agents with the same origin-destination and start time within a threshold.
- Parameters:
machine_agents_list (List[Any]) – List of machine agents.
human_agents_list (List[Any]) – List of human agents.
simulation_params (Dict[str, Any]) – Simulation parameters.
agent_params (Dict[str, Any]) – Agent parameters.
- Variables:
observations (List[Any]) – List of observations.
- agent_observations(agent_id: str) ndarray [source]
Retrieve the observation for a specific agent.
- Parameters:
agent_id (str) – The ID of the agent.
- Returns:
np.ndarray – The observation array for the specified agent.
- observation_space() Dict[str, Box] [source]
Define the observation space for each machine agent.
- Returns:
Dict[str, Box] – A dictionary where keys are agent IDs and values are Gym spaces.
- reset_observation() Dict[str, ndarray] [source]
Reset observations to the initial state.
- Returns:
Dict[str, np.ndarray] – A dictionary of initial observations for all machine agents.
PreviousAgentStartPlusStartTime
¶
The PreviousAgentStartPlusStartTime
class is another observation functions in RouteRL
. This class is designed to monitor and manage the number of agents with identical origin-destination pairs and start times, operating within a predefined threshold as well as the start time of the specific agent.
Details of the PreviousAgentStartPlusStartTime
class are provided below:
- class routerl.environment.observations.PreviousAgentStartPlusStartTime(machine_agents_list: List[Any], human_agents_list: List[Any], simulation_params: Dict[str, Any], agent_params: Dict[str, Any])[source]
Observes the number of agents with the same origin-destination and start time within a threshold and includes the start of the specific agent as well.
- agent_observations(agent_id: str) ndarray [source]
Retrieve the observation for a specific agent.
- Parameters:
agent_id (str) – The ID of the agent.
- Returns:
np.ndarray – The observation array for the specified agent.
- observation_space() Dict[str, Box] [source]
Define the observation space for each machine agent.
- Returns:
Dict[str, Box] – A dictionary where keys are agent IDs and values are Gym spaces.
- reset_observation() Dict[str, ndarray] [source]
Reset observations to the initial state.
- Returns:
obs (Dict[str, np.ndarray]) – A dictionary of initial observations for all machine agents.