framework.scenario
Note
For more detailed explanation of the genetic representation, please refer to our main paper listed in Publication.
framework.scenario.__init__
- class framework.scenario.Scenario(ad_section: framework.scenario.ad_agents.ADSection, pd_section: framework.scenario.pd_agents.PDSection, tc_section: framework.scenario.tc_config.TCSection, gid: int = - 1, cid: int = - 1, fitness: deap.base.Fitness = framework.scenario.ScenarioFitness(()))
Genetic representation of a scenario (individual)
- Parameters
- static from_json(json_file_path: str) framework.scenario.Scenario
Converts a JSON file into Scenario object
- Parameters
json_file_path (str) – name of the JSON file
- Returns
Scenario object
- Return type
- static get_conflict_one() framework.scenario.Scenario
Randomly generates a scenario that gurantees at least 2 ADS instances have conflicting trajectory
- Returns
randomly generated scenario with conflict
- Return type
- static get_one() framework.scenario.Scenario
Randomly generates a scenario using the representation
- Returns
randomlly generated scenario
- Return type
- has_ad_conflict() int
Check number of ADS instance pairs with conflict
- Returns
number of conflicts
- Return type
int
- to_dict() dict
Converts the chromosome to dict
- Returns
scenario in JSON format
- Return type
dict
- class framework.scenario.ScenarioFitness(values=())
Class to represent weight of each fitness function
- weights = (-1.0, 1.0, 1.0, 1.0)
- Note
minimize closest distance, maximize number of decisions, maximize pairs having conflicting trajectory, maximize unique violation. Refer to our paper for more detailed explanation.
framework.scenario.ad_agents
- class framework.scenario.ad_agents.ADAgent(routing: List[str], start_s: float, dest_s: float, start_t: float)
Genetic representation of a single ADS instance
- Parameters
routing (List[str]) – list of lanes expected to travel on
start_s (float) – where on the initial lane
dest_s (float) – where on the destination lane
start_t (float) – when should the instance start
- Example
the ADS instance will start from
(routing[0],start_s)
and drive towards(routing[-1], dest_s)
- static get_one() framework.scenario.ad_agents.ADAgent
Randomly generates an ADS instance representation
- Returns
an ADS instance representation
- Return type
- static get_one_for_routing(routing: List[str]) framework.scenario.ad_agents.ADAgent
Get an ADS instance representation with the specified routing
- Parameters
routing (List[str]) – expected routing to be completed
- Returns
an ADS instance representation with the specified routing
- Return type
- property initial_position: apollo.utils.PositionEstimate
Get the initial position of the ADS instance
- Returns
initial position
- Return type
- property routing_str: str
The routing in string format
- Returns
string version of the routing
- Return type
str
- property waypoints: List[apollo.utils.PositionEstimate]
- Convert routing to a list of waypoints ready to be sent
as a routing request
- Returns
waypoints
- Return type
List[PositionEstimate]
- class framework.scenario.ad_agents.ADSection(adcs: List[framework.scenario.ad_agents.ADAgent])
Genetic representation of the ADS instance section
- Parameters
adcs (List[ADAgent]) – list of ADS instance representations
- add_agent(adc: framework.scenario.ad_agents.ADAgent) bool
Adds an ADS instance representation to the section
- Returns
True if successfully added, False otherwise
- Return type
bool
- adjust_time()
Readjusts all ADS instances so that at least 1 ADS instance will start driving as early as 2 seconds since the scenario starts. This helps ensuring we will not be sitting there for a while and no ADS instance is doing anything interesting.
- static get_one() framework.scenario.ad_agents.ADSection
Randomly generates an ADS instance section
- Returns
randomly generated section
- Return type
- has_conflict(adc: framework.scenario.ad_agents.ADAgent) bool
Checks if the ADS instance has conflict with any other ADS already in the section
- Returns
True if conflict exists, False otherwise
- Return type
bool
- framework.scenario.ad_agents.random() x in the interval [0, 1).
framework.scenario.pd_agents
- class framework.scenario.pd_agents.PDAgent(cw_id: str, speed: float, start_t: float)
Genetic representation of a single pedestrian
- Parameters
cw_id (str) – the ID of the crosswalk this pedestrian is on
speed (float) – the speed of this pedestrian
start_s (float) – the start time of this pedestrian
- static get_one() framework.scenario.pd_agents.PDAgent
Randomly generates an pedestrian representation
- Returns
a pedestrian representation
- Return type
- static get_one_for_cw(cw_id: str) framework.scenario.pd_agents.PDAgent
Get a pedestrian representation with the specified crosswalk ID
- Parameters
cw_id (str) – ID of the expected crosswalk
- Returns
a pedestrian representation
- Return type
- class framework.scenario.pd_agents.PDSection(pds: List[framework.scenario.pd_agents.PDAgent])
Genetic representation of the pedestrian section
- Parameters
pds (List[PDAgent]) – list of pedestrian representations
- add_agent(pd: framework.scenario.pd_agents.PDAgent) bool
Adds an pedestrian representation to the section
- Returns
True if successfully added, False otherwise
- Return type
bool
- static get_one() framework.scenario.pd_agents.PDSection
Randomly generates a pedestrian section
- Returns
randomly generated section
- Return type
framework.scenario.PedestrianManager
- class framework.scenario.PedestrianManager.PedestrianManager(pedestrians: framework.scenario.pd_agents.PDSection)
A simplified modeling of constant speed pedestrians
- Parameters
pedestrians (PDSection) – pedestrians to be managed
- calculate_position(pd: framework.scenario.pd_agents.PDAgent, time_spent_walking: float) Tuple[modules.common.proto.geometry_pb2.Point3D, float]
Calculate the pedestrians location and heading at a given time
- Parameters
pd (PDAgent) – the pedestrian to be calculated
time_spent_walking (float) – the amount of time pedestrian has traveled for
- Returns
the position and heading
- Return type
Tuple[Point3D, float]
- static get_instance() framework.scenario.PedestrianManager.PedestrianManager
Returns the singleton instance
- Returns
manager object
- Return type
- get_pedestrians(curr_time: float) List[Tuple[modules.common.proto.geometry_pb2.Point3D, float]]
Get the location and heading of all pedestrians
- Parameters
curr_time (float) – time since start of the scenario
- Returns
list consisting position and heading
- Return type
List[Tuple[Point3D, float]]
framework.scenario.ScenarioRunner
- class framework.scenario.ScenarioRunner.ScenarioRunner(containers: List[apollo.ApolloContainer.ApolloContainer])
Executes a scenario based on the specification
- Parameters
containers (List[ApolloContainer]) – containers to be used for scenario
- static get_instance() framework.scenario.ScenarioRunner.ScenarioRunner
Returns the singleton instance
- Returns
an instance of runner
- Return type
- init_scenario()
Initialize the scenario
- run_scenario(generation_name: str, scenario_name: str, save_record=False) List[Tuple[apollo.ApolloRunner.ApolloRunner, framework.scenario.ad_agents.ADAgent]]
Execute the scenario based on the specification
- Parameters
generation_name (str) – name of the generation
scenario_name (str) – name of the scenario
save_record (bool) – whether to save records or not
- set_scenario(s: framework.scenario.Scenario)
Set the scenario for this runner
- Parameters
s (Scenario) – scenario representation
framework.scenario.tc_config
- class framework.scenario.tc_config.TCSection(initial: Dict[str, str], final: Dict[str, str], duration_g: float, duration_y: float, duration_b: float)
Genetic representation of the traffic control section
- Parameters
initial (Dict[str, str]) – the initial configuration
final (Dict[str, str]) – the final configuration
duration_g (float) – green signal duration
duration_y (float) – yellow change interval duration
duration_b (float) – red clearance interval duration
- calculate_transition() Dict[str, str]
Calculates the color of signals during the transition stage.
- Returns
color assignment for signals during the transition stage
- Return type
Dict[str, str]
- Example
If a signal was green in the initial configuration, but is red in the final configuration, it must be yellow during the transition stage.
- static generate_config(preference=[]) Dict[str, str]
Generate a configuration with certain signals being green
- Parameters
preference (List[str]) – signals prefered to be green
- Returns
a configuration in which preferred signals are green
- Return type
Dict[str, str]
- get_config_with_color(color: str) Dict[str, str]
Gets a configuration where all signals have the specified color
- Parameters
color (str) – color to be specified
- Returns
a configuration in which all signals have the specified color
- Return type
Dict[str, str]
- Warning
It is reasonable if all signals are red, but all signals being green will definitely cause problems!
- static get_one() framework.scenario.tc_config.TCSection
Randomly generates a traffic control section
- Returns
traffic control section
- Rypte
TCSection
- static get_random_duration_g() int
Generate a random duration for green light
- Returns
green light duration
- Return type
int
framework.scenario.TrafficControlManager
- class framework.scenario.TrafficControlManager.TrafficControlManager(tc: framework.scenario.tc_config.TCSection)
Manages traffic signals during a scenario based on the specification
- Parameters
tc (TCSection) – traffic control section
- get_traffic_configuration(curr_t: float) modules.perception.proto.traffic_light_detection_pb2.TrafficLightDetection
Based on the current time, generate a TrafficLightDetection message ready to be published to the ADS
- Parameters
curr_t (float) – time since start of the scenario
- Returns
traffic light detection message
- Return type
TrafficLightDetection