def missions() -> Sequence[Mission]: return [ Mission( Route(begin=("edge-west-WE", 0, 0), end=("edge-south-NS", 0, 0))), Mission( Route(begin=("edge-south-SN", 0, 30), end=("edge-west-EW", 0, 0))), ]
def create_scenario(): with temp_scenario(name="cycles", map="maps/6lane.net.xml") as scenario_root: actors = [ SocialAgentActor( name=f"non-interactive-agent-{speed}-v0", agent_locator="zoo.policies:non-interactive-agent-v0", policy_kwargs={"speed": speed}, ) for speed in [10, 30] ] for name, (edge_start, edge_end) in [ ("group-1", ("edge-north-NS", "edge-south-NS")), ("group-2", ("edge-west-WE", "edge-east-WE")), ("group-3", ("edge-east-EW", "edge-west-EW")), ("group-4", ("edge-south-SN", "edge-north-SN")), ]: route = Route(begin=("edge-north-NS", 1, 0), end=("edge-south-NS", 1, "max")) missions = [Mission(route=route)] * 2 gen_social_agent_missions( scenario_root, social_agent_actor=actors, name=name, missions=missions, ) yield scenario_root
def scenario_root(scenario_parent_path): # TODO: We may want to consider referencing to concrete scenarios in our tests # rather than generating them. The benefit of generting however is that # we can change the test criteria and scenario code in unison. scenario = Path(scenario_parent_path) / "cycles" scenario.mkdir() shutil.copyfile( Path(__file__).parent / "maps/6lane.net.xml", scenario / "map.net.xml") generate_glb_from_sumo_network(str(scenario / "map.net.xml"), str(scenario / "map.glb")) actors = [ SocialAgentActor( name=f"non-interactive-agent-{speed}-v0", agent_locator="zoo.policies:non-interactive-agent-v0", policy_kwargs={"speed": speed}, ) for speed in [10, 30, 80] ] for name, (edge_start, edge_end) in [ ("group-1", ("edge-north-NS", "edge-south-NS")), ("group-2", ("edge-west-WE", "edge-east-WE")), ("group-3", ("edge-east-EW", "edge-west-EW")), ("group-4", ("edge-south-SN", "edge-north-SN")), ]: route = Route(begin=("edge-north-NS", 1, 0), end=("edge-south-NS", 1, "max")) missions = [Mission(route=route)] * 2 # double up gen_social_agent_missions( scenario, social_agent_actor=actors, name=name, missions=missions, ) gen_missions( scenario, missions=[ Mission( Route(begin=("edge-west-WE", 0, 0), end=("edge-east-WE", 0, "max"))) ], ) return scenario
def scenario_root(): # TODO: We may want to consider referencing to concrete scenarios in our tests # rather than generating them. The benefit of generting however is that # we can change the test criteria and scenario code in unison. with temp_scenario(name="cycles", map="maps/6lane.net.xml") as scenario_root: actors = [ SocialAgentActor( name=f"non-interactive-agent-{speed}-v0", agent_locator="zoo.policies:non-interactive-agent-v0", policy_kwargs={"speed": speed}, ) for speed in [10, 30, 80] ] for name, (edge_start, edge_end) in [ ("group-1", ("edge-north-NS", "edge-south-NS")), ("group-2", ("edge-west-WE", "edge-east-WE")), ("group-3", ("edge-east-EW", "edge-west-EW")), ("group-4", ("edge-south-SN", "edge-north-SN")), ]: route = Route(begin=("edge-north-NS", 1, 0), end=("edge-south-NS", 1, "max")) missions = [Mission(route=route)] * 2 # double up gen_social_agent_missions( scenario_root, social_agent_actor=actors, name=name, missions=missions, ) gen_missions( scenario_root, missions=[ Mission( Route(begin=("edge-west-WE", 0, 0), end=("edge-east-WE", 0, "max"))) ], ) yield scenario_root
from smarts.sstudio import gen_traffic, gen_missions from smarts.sstudio.types import ( Traffic, Flow, Route, RandomRoute, TrafficActor, Mission, ) scenario = os.path.dirname(os.path.realpath(__file__)) agent_missions = [ Mission( Route(begin=("edge-north-NS", 0, 10), end=("edge-south-NS", (0, ), 10))), Mission( Route(begin=("edge-north-WN", 0, 40), end=("edge-north-SN", (0, ), 10))), Mission( Route(begin=("edge-east-EN", 0, 20), end=("edge-north-SN", (0, ), 10))), ] gen_missions(scenario, agent_missions, overwrite=True) gen_traffic( scenario, Traffic(flows=[ Flow(
from pathlib import Path from smarts.sstudio import gen_scenario from smarts.sstudio.types import ( Route, Mission, Scenario, ) missions = [ Mission(Route(begin=("edge-south-SN", 1, 40), end=("edge-west-EW", 0, 60))) ] gen_scenario( Scenario(ego_missions=missions), output_dir=Path(__file__).parent, )
from smarts.sstudio.genscenario import gen_scenario from smarts.sstudio.types import ( CutIn, Flow, Mission, Route, Scenario, Traffic, TrafficActor, ) ego_missions = [ Mission( route=Route(begin=("edge-west-WE", 0, 10), end=("edge-west-WE", 0, "max")), task=CutIn(), ), ] scenario = Scenario( traffic={ "basic": Traffic(flows=[ Flow( route=Route(begin=("edge-west-WE", 1, 10), end=("edge-west-WE", 1, "max")), rate=400, actors={TrafficActor(name="car"): 1.0}, ) ])
from smarts.sstudio.genscenario import gen_scenario from smarts.sstudio.types import ( Flow, Mission, Route, Scenario, Traffic, TrafficActor, UTurn, ) ego_missions = [ Mission( route=Route(begin=("edge-west-WE", 1, 30), end=("edge-west-EW", 0, 100)), task=UTurn(initial_speed=20), ), ] scenario = Scenario( traffic={ "basic": Traffic(flows=[ Flow( route=Route(begin=("edge-west-EW", 0, 20), end=("edge-west-EW", 1, "max")), rate=400, actors={TrafficActor(name="car"): 1.0}, ) ])
EndlessMission, Flow, JunctionEdgeIDResolver, Mission, RandomRoute, Route, Scenario, Traffic, TrafficActor, Via, ) ego_missions = [ Mission( route=Route(begin=("edge-south-SN", 1, 10), end=("edge-west-EW", 1, "max")), task=CutIn(complete_on_edge_id=JunctionEdgeIDResolver( "edge-south-SN", 1, "edge-west-EW", 0)), ), EndlessMission( begin=("edge-south-SN", 1, 10), via=( Via( "edge-south-SN", lane_offset=30, lane_index=1, required_speed=4, ), Via( JunctionEdgeIDResolver("edge-south-SN", 1, "edge-west-EW", 0), lane_offset=10, lane_index=0,
Traffic, Flow, Route, RandomRoute, TrafficActor, Distribution, LaneChangingModel, JunctionModel, Mission, ) scenario = os.path.dirname(os.path.realpath(__file__)) agent_missions = [ Mission( Route(begin=("edge-west-WE", 0, 10), end=("edge-south-NS", (0, ), 40))), Mission( Route(begin=("edge-west-WE", 0, 20), end=("edge-west-WE", (0, ), 25))), Mission( Route(begin=("edge-south-SN", 0, 60), end=("edge-west-EW", (0, ), 50))), ] gen_missions(scenario, agent_missions, overwrite=True) total_rate = 3600 # vehicles/hr impatient_car = TrafficActor( name="car", speed=Distribution(sigma=0.2, mean=1.0),
social_agent1 = SocialAgentActor( name="zoo-car1", agent_locator="scenarios.zoo_intersection.agent_prefabs:zoo-agent2-v0", initial_speed=20, ) social_agent2 = SocialAgentActor( name="zoo-car2", agent_locator="scenarios.zoo_intersection.agent_prefabs:zoo-agent2-v0", initial_speed=20, ) gen_social_agent_missions( scenario, social_agent_actor=social_agent2, name=f"s-agent-{social_agent2.name}", missions=[Mission(RandomRoute())], ) gen_social_agent_missions( scenario, social_agent_actor=social_agent1, name=f"s-agent-{social_agent1.name}", missions=[ EndlessMission(begin=("edge-south-SN", 0, 30)), Mission( Route(begin=("edge-west-WE", 0, 10), end=("edge-east-WE", 0, 10))), ], ) # Agent Missions gen_missions(
from pathlib import Path from smarts.sstudio import gen_scenario from smarts.sstudio.types import ( Route, Mission, Scenario, ) missions = [ Mission(Route(begin=("edge-south-SN", 1, 40), end=("edge-west-EW", 0, 60))), Mission(Route(begin=("edge-west-WE", 1, 50), end=("edge-east-WE", 0, 60))), Mission(Route(begin=("edge-north-NS", 0, 40), end=("edge-south-NS", 1, 40))), Mission(Route(begin=("edge-east-EW", 0, 50), end=("edge-west-EW", 1, 40))), ] gen_scenario( Scenario(ego_missions=missions), output_dir=Path(__file__).parent, )
from smarts.sstudio.types import ( Traffic, Flow, Route, RandomRoute, TrafficActor, Mission, ) scenario = os.path.dirname(os.path.realpath(__file__)) gen_missions( scenario, [ Mission( Route(begin=("edge-west-WE", 0, 10), end=("edge-south-NS", 0, 40))), Mission( Route(begin=("edge-west-WE", 1, 10), end=("edge-south-NS", 0, 40))), ], ) gen_traffic( scenario, Traffic(flows=[ Flow( route=RandomRoute(), rate=3600, actors={TrafficActor(name="car"): 1.0}, )
from smarts.sstudio.genscenario import gen_scenario from smarts.sstudio.types import ( EndlessMission, Flow, JunctionEdgeIDResolver, Mission, RandomRoute, Route, Scenario, Traffic, TrafficActor, Via, ) ego_missions = [ Mission(route=Route(begin=("edge-south-SN", 1, 10), end=("edge-west-EW", 1, "max")), ), EndlessMission( begin=("edge-south-SN", 1, 10), via=( Via( "edge-south-SN", lane_offset=30, lane_index=1, required_speed=4, ), Via( JunctionEdgeIDResolver("edge-south-SN", 1, "edge-west-EW", 0), lane_offset=10, lane_index=0, required_speed=2, ),
Distribution, Flow, LaneChangingModel, Mission, RandomRoute, Route, Scenario, Traffic, TrafficActor, ) social_vehicle_num = 100 ego_missions = [ Mission( route=Route(begin=("edge-south-SN", 1, 10), end=("edge-west-EW", 1, 8)), # begin 45.6 ), ] left_traffic_actor = TrafficActor( name="car", speed=Distribution(sigma=0.2, mean=1), lane_changing_model=LaneChangingModel(impatience=0), # junction_model=JunctionModel( # drive_after_yellow_time=1.0, impatience=0) ) scenario = Scenario( traffic={ "basic": Traffic(flows=[ Flow(
from smarts.sstudio.types import ( Distribution, Flow, LaneChangingModel, Mission, RandomRoute, Route, Scenario, Traffic, TrafficActor, ) social_vehicle_num = 100 ego_missions = [ Mission(route=Route(begin=("edge-south-SN", 0, 10), end=("edge-east-WE", 0, 8)), ), ] right_traffic_actor = TrafficActor( name="car", speed=Distribution(sigma=0.2, mean=1), lane_changing_model=LaneChangingModel(impatience=0), ) scenario = Scenario( traffic={ "basic": Traffic(flows=[ Flow( route=RandomRoute(), rate=1, actors={right_traffic_actor: 1.0},
from pathlib import Path from smarts.sstudio import types as t from smarts.sstudio.types import Mission, Route from smarts.sstudio import gen_traffic, gen_missions scenario = str(Path(__file__).parent) agent_missions = [ Mission( Route(begin=("edge-west-WE", 0, 80), end=("edge-east-WE", (1, ), 40))), Mission( Route(begin=("edge-east-EW", 0, 80), end=("edge-south-NS", (1, ), 40))), Mission( Route(begin=("edge-south-SN", 0, 80), end=("edge-west-EW", (1, ), 40))), ] gen_missions(scenario, missions=agent_missions, overwrite=True) traffic = t.Traffic(flows=[ t.Flow( route=t.Route( begin=("edge-west-WE", 0, 10), end=("edge-east-WE", 0, -10), ), rate=400, actors={ t.TrafficActor("car"): 1, },
# # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from pathlib import Path from smarts.sstudio import gen_scenario from smarts.sstudio.types import ( Route, Mission, Scenario, ) missions = [ Mission(Route(begin=("gneE17", 0, 10), end=("gneE5", 1, 100))), Mission(Route(begin=("gneE22", 0, 10), end=("gneE5", 0, 100))), Mission(Route(begin=("gneE17", 0, 25), end=("gneE5", 0, 100))), Mission(Route(begin=("gneE22", 0, 25), end=("gneE5", 1, 100))), ] gen_scenario( Scenario(ego_missions=missions), output_dir=Path(__file__).parent, )
def generate_left_turn_missions( missions, shuffle_missions, route_distributions, route_lanes, speed, map_dir, level_name, save_dir, stopwatcher_behavior, stopwatcher_route, seed, stops, bubbles, intersection_name, traffic_density, ): # dont worry about these seeds, theyre used by sumo sumo_seed = random.choice([0, 1, 2, 3, 4]) stopwatcher_info = None stopwatcher_added = False if stopwatcher_behavior: stopwatcher_info = { "behavior": stopwatcher_behavior, "direction": get_direction(stopwatcher_route), } random.seed(seed) np.random.seed(seed) all_flows = [] metadata = {"routes": {}, "total_vehicles": 0, "stopwatcher": None} scenario = save_dir + f"-flow-{seed}" # Remove old traffic route if it exists(otherwise, won't update to new flows) if os.path.exists(f"{scenario}/traffic/all.rou.xml"): shutil.rmtree(scenario) for route_key, route_info in route_distributions["routes"].items(): # to skip None if route_info: ego_routes = [ ego_mission_config_to_route( ego_mission_config=ego_mission_config, route_lanes=route_lanes, stopwatcher_behavior=stopwatcher_behavior, ) for ego_mission_config in missions ] # Not all routes need to have a custom start/end offset if "pos_offsets" in route_info: pos_offsets = route_info["pos_offsets"] else: pos_offsets = None flows, vehicles_log_info = generate_social_vehicles( route_distribution=route_info["distribution"], begin_time_init=route_info["begin_time_init"], num_vehicles=route_info["vehicles"], route_direction=get_direction(route_key), route_lanes=route_lanes, route_has_turn=route_info["has_turn"], start_end_on_different_lanes_probability=route_info[ "start_end_on_different_lanes_probability" ], stops=stops, deadlock_optimization=route_info["deadlock_optimization"], pos_offsets=pos_offsets, stopwatcher_info=stopwatcher_info, traffic_params={"speed": speed, "traffic_density": traffic_density}, ) if ( stopwatcher_behavior and len(flows) > 0 and get_direction(route_key) == stopwatcher_info["direction"] ): stopwatcher_added = True print( f'stop watcher added to {get_direction(route_key)} flows among {route_info["vehicles"]} vehicles!' ) all_flows.extend(flows) metadata["routes"][route_key] = vehicles_log_info scenario = save_dir + f"-flow-{seed}" if stopwatcher_behavior: if not stopwatcher_added and level_name != "no-traffic": print( f'There was no matching flows for stopwatcher, adding it to {stopwatcher_info["direction"]}.' ) # vehicles_log_info[f'stopwatcher_{stopwatcher_info["behavior"]}']["count"] += 1 all_flows.append( generate_stopwatcher( stopwatcher_behavior=stopwatcher_info["behavior"], stopwatcher_route=stopwatcher_info["direction"], start_lane_id=0, end_lane_id=0, ) ) scenario += f"-stopwatcher-{stopwatcher_info['behavior']}" copy_map_files(scenario, map_dir, speed) vehicles_to_not_hijack = [] traffic = Traffic(flows=all_flows) try: gen_traffic(scenario, traffic, name=f"all", seed=sumo_seed) if stops: add_stops_to_traffic(scenario, stops, vehicles_to_not_hijack) except Exception as exception: print(exception) # Patch: Remove route files from traffic folder to make intersection empty. if traffic_density == "no-traffic": os.remove(f"{scenario}/traffic/all.rou.xml") if stopwatcher_behavior or "ego_hijacking_params" not in route_distributions: mission_objects = [Mission(ego_route) for ego_route in ego_routes] else: speed_m_per_s = float("".join(filter(str.isdigit, speed))) * 5.0 / 18.0 hijacking_params = route_distributions["ego_hijacking_params"] zone_range = hijacking_params["zone_range"] waiting_time = hijacking_params["wait_to_hijack_limit_s"] start_time = ( hijacking_params["start_time"] if hijacking_params["start_time"] != "default" else random.randint((LANE_LENGTH // speed_m_per_s), 60) ) mission_objects = [ Mission( ego_route, # Optional: control hijacking time, place, and emission. start_time=start_time, # When to start hijacking (might start later). entry_tactic=TrapEntryTactic( wait_to_hijack_limit_s=waiting_time, # When to give up hijacking. zone=MapZone( start=( ego_route.begin[0], 0, ego_route.begin[2] + zone_range[0], ), length=zone_range[1], n_lanes=(ego_route.begin[1] + 1), ), # Area to hijack. exclusion_prefixes=vehicles_to_not_hijack, # Don't hijack these. ), ) for ego_route in ego_routes ] # Shuffle the missions so agents don't do the same route all the time. if shuffle_missions: random.shuffle(mission_objects) gen_missions(scenario, mission_objects) if bubbles: bubble_objects = [ bubble_config_to_bubble_object( scenario, bubble_config, vehicles_to_not_hijack ) for bubble_config in bubbles ] gen_bubbles(scenario, bubble_objects) if stopwatcher_behavior: metadata["stopwatcher"] = { "direction": stopwatcher_info["direction"], "behavior": stopwatcher_info["behavior"], } metadata["intersection"] = { "type": intersection_name[-1], "name": intersection_name, } metadata["total_vehicles"] = len(all_flows) metadata["seed"] = seed metadata["flow_id"] = f"flow_{seed}" with open(f"{scenario}/metadata.json", "w") as log: json.dump(metadata, log)
Mission, TrapEntryTactic, MapZone, ) scenario = os.path.dirname(os.path.realpath(__file__)) gen_missions( scenario, [ Mission( Route(begin=("edge-west-WE", 0, 10), end=("edge-south-NS", 0, 40)), entry_tactic=TrapEntryTactic( wait_to_hijack_limit_s=3, zone=MapZone( start=("edge-west-WE", 0, 5), length=30, n_lanes=1, ), ), ), Mission( Route(begin=("edge-west-WE", 0, 10), end=("edge-west-WE", 0, 25)), entry_tactic=TrapEntryTactic( wait_to_hijack_limit_s=3, zone=MapZone( start=("edge-west-WE", 0, 5), length=30, n_lanes=1, ), ),
import os from smarts.sstudio import gen_traffic, gen_missions from smarts.sstudio.types import ( Traffic, Flow, Route, RandomRoute, TrafficActor, Mission, ) scenario = os.path.dirname(os.path.realpath(__file__)) agent_missions = [ Mission(Route(begin=("left_top", 0, 30), end=("right_bottom", (0, ), 40))), Mission(Route(begin=("left_bottom", 0, 30), end=("right_top", (0, ), 40))), Mission(Route(begin=("left_top", 0, 10), end=("right_top", (0, ), 30))), Mission(Route(begin=("left_bottom", 0, 10), end=("right_top", (0, ), 40))), ] gen_missions(scenario, agent_missions, overwrite=True) gen_traffic( scenario, Traffic(flows=[ Flow( route=RandomRoute(), rate=3600, actors={TrafficActor(name="car"): 1.0}, )
def to_mission(start_edge, end_edge): route = Route(begin=(start_edge, 1, 0), end=(end_edge, 1, "max")) return Mission(route=route)
def generate_left_turn_missions( mission, route_distributions, route_lanes, speed, map_dir, level_name, save_dir, stopwatcher_behavior, stopwatcher_route, seed, intersection_name, traffic_density, ): # dont worry about these seeds, theyre used by sumo sumo_seed = random.choice([0, 1, 2, 3, 4]) stopwatcher_info = None stopwatcher_added = False if stopwatcher_behavior: stopwatcher_info = { "behavior": stopwatcher_behavior, "direction": get_direction(stopwatcher_route), } random.seed(seed) np.random.seed(seed) all_flows = [] metadata = {"routes": {}, "total_vehicles": 0, "stopwatcher": None} scenario = save_dir + f"-flow-{seed}" # Remove old traffic route if it exists(otherwise, won't update to new flows) if os.path.exists(f"{scenario}/traffic/all.rou.xml"): shutil.rmtree(scenario) for route_key, route_info in route_distributions["routes"].items(): # to skip None if route_info: if stopwatcher_behavior: # put the ego on the side road ego_start_lane, ego_end_lane = 0, 0 mission_start, mission_end = "south-side", "dead-end" ego_start_pos, ego_end_pos = 100, 5 ego_num_lanes = 1 else: mission_start, mission_end = mission["start"], mission["end"] ego_start_lane, ego_end_lane = ( route_lanes[mission_start] - 1, route_lanes[mission_end] - 1, ) ego_start_pos, ego_end_pos = ( random.randint(50, 120), random.randint(50, 150), ) ego_num_lanes = route_lanes[mission_start] ego_route = Route( begin=(f"edge-{mission_start}", ego_start_lane, ego_start_pos), end=(f"edge-{mission_end}", ego_end_lane, ego_end_pos), ) flows, vehicles_log_info = generate_social_vehicles( ego_start_lane=ego_start_lane, route_distribution=route_info["distribution"], begin_time_init=route_info["begin_time_init"], num_vehicles=route_info["vehicles"], route_direction=get_direction(route_key), route_lanes=route_lanes, route_has_turn=route_info["has_turn"], start_end_on_different_lanes_probability=route_info[ "start_end_on_different_lanes_probability"], deadlock_optimization=route_info["deadlock_optimization"], stopwatcher_info=stopwatcher_info, ) if (stopwatcher_behavior and len(flows) > 0 and get_direction(route_key) == stopwatcher_info["direction"]): stopwatcher_added = True print( f'stop watcher added to {get_direction(route_key)} flows among {route_info["vehicles"]} vehicles!' ) all_flows.extend(flows) metadata["routes"][route_key] = vehicles_log_info scenario = save_dir + f"-flow-{seed}" if stopwatcher_behavior: if not stopwatcher_added and level_name != "no-traffic": print( f'There was no matching flows for stopwatcher, adding it to {stopwatcher_info["direction"]}.' ) # vehicles_log_info[f'stopwatcher_{stopwatcher_info["behavior"]}']["count"] += 1 all_flows.append( generate_stopwatcher( stopwatcher_behavior=stopwatcher_info["behavior"], stopwatcher_route=stopwatcher_info["direction"], start_lane_id=0, end_lane_id=0, )) scenario += f"-stopwatcher-{stopwatcher_info['behavior']}" copy_map_files(scenario, map_dir, speed) if stopwatcher_behavior or "ego_hijacking_params" not in route_distributions: gen_missions(scenario, [Mission(ego_route)]) else: speed_m_per_s = float("".join(filter(str.isdigit, speed))) * 5.0 / 18.0 hijacking_params = route_distributions["ego_hijacking_params"] zone_range = hijacking_params["zone_range"] waiting_time = hijacking_params["wait_to_hijack_limit_s"] start_time = hijacking_params["start_time"] if start_time == "default": start_time = random.randint((LANE_LENGTH // speed_m_per_s), 60) gen_missions( scenario, [ Mission( ego_route, # optional: control hijacking time, place, and emission. start_time= start_time, # when to start hijacking (might start later) entry_tactic=TrapEntryTactic( wait_to_hijack_limit_s= waiting_time, # when to give up on hijacking and start emitting a social vehicle instead zone=MapZone( start=( f'edge-{mission["start"]}', 0, ego_start_pos + zone_range[0], ), length=zone_range[1], n_lanes=route_lanes[mission["start"]], ), # area to hijack exclusion_prefixes=tuple( ), # vehicles to be excluded (check vehicle ids) ), ), ], ) traffic = Traffic(flows=all_flows) gen_traffic(scenario, traffic, name=f"all", seed=sumo_seed) # patch: remove route files from traffic folder to make intersection empty if traffic_density == "no-traffic": os.remove(f"{scenario}/traffic/all.rou.xml") if stopwatcher_behavior: metadata["stopwatcher"] = { "direction": stopwatcher_info["direction"], "behavior": stopwatcher_info["behavior"], } metadata["intersection"] = { "type": intersection_name[-1], "name": intersection_name, } metadata["total_vehicles"] = len(all_flows) metadata["seed"] = seed metadata["flow_id"] = f"flow_{seed}" with open(f"{scenario}/metadata.json", "w") as log: json.dump(metadata, log)
laner_agent = SocialAgentActor( name="laner-agent", agent_locator= "scenarios.intersections.2lane_circle.agent_prefabs:laner-agent-v0", ) buddha_agent = SocialAgentActor( name="buddha-agent", agent_locator= "scenarios.intersections.2lane_circle.agent_prefabs:buddha-agent-v0", ) gen_social_agent_missions( scenario, social_agent_actor=laner_agent, name=f"s-agent-{laner_agent.name}", missions=[ Mission(Route(begin=("edge-east-EW", 0, 5), end=("edge-west-EW", 0, 5))) ], ) gen_social_agent_missions( scenario, social_agent_actor=buddha_agent, name=f"s-agent-{buddha_agent.name}", missions=[ Mission(Route(begin=("edge-west-WE", 0, 5), end=("edge-east-WE", 0, 5))) ], )
import os from smarts.sstudio import gen_traffic, gen_missions from smarts.sstudio.types import (Traffic, Flow, Route, RandomRoute, TrafficActor, Mission, Distribution, LaneChangingModel, JunctionModel) scenario = os.path.dirname(os.path.realpath(__file__)) agent_missions = [ Mission( Route(begin=("edge-west-WE", 0, 100), end=("edge-east-WE", (1, ), 40))), Mission( Route(begin=("edge-south-SN", 0, 50), end=("edge-west-EW", (0, ), 40))), Mission( Route(begin=("edge-east-EW", 0, 50), end=("edge-west-EW", (1, ), 40))), Mission( Route(begin=("edge-north-NS", 0, 50), end=("edge-south-NS", (1, ), 30))) ] gen_missions(scenario, agent_missions, overwrite=True) impatient_car = TrafficActor( name="car", speed=Distribution(sigma=0.2, mean=0.5), lane_changing_model=LaneChangingModel(impatience=1, cooperative=0.25), junction_model=JunctionModel(drive_after_red_time=1.5, drive_after_yellow_time=1.0,
Flow, JunctionModel, LaneChangingModel, Mission, RandomRoute, Route, Scenario, Traffic, TrafficActor, ) social_vehicle_num = 100 ego_missions = [ Mission( route=Route(begin=("edge-south-SN", 1, 10), end=("edge-north-SN", 1, 8)), ), ] stright_traffic_actor = TrafficActor( name="car", speed=Distribution(sigma=0.2, mean=1), lane_changing_model=LaneChangingModel(impatience=0), junction_model=JunctionModel( drive_after_red_time=1.5, drive_after_yellow_time=1.0, impatience=0.5 ), ) scenario = Scenario( traffic={ "basic": Traffic( flows=[
import os from smarts.sstudio import gen_traffic, gen_missions from smarts.sstudio.types import ( Traffic, Flow, Route, RandomRoute, TrafficActor, Mission, ) scenario = os.path.dirname(os.path.realpath(__file__)) agent_missions = [ Mission(Route(begin=("left_in", 0, 80), end=("merged", (0, ), 40))), Mission(Route(begin=("left_in", 0, 50), end=("merged", (0, ), 40))), Mission(Route(begin=("ramp_in", 0, 80), end=("merged", (0, ), 60))), Mission(Route(begin=("ramp_in", 0, 50), end=("merged", (0, ), 60))), ] gen_missions(scenario, agent_missions, overwrite=True) gen_traffic( scenario, Traffic(flows=[ Flow( route=RandomRoute(), rate=3600, actors={TrafficActor(name="car"): 1.0}, )
import os from smarts.sstudio import gen_traffic, gen_missions from smarts.sstudio.types import ( Traffic, Flow, Route, RandomRoute, TrafficActor, Mission, ) scenario = os.path.dirname(os.path.realpath(__file__)) agent_missions = [ Mission(Route(begin=("left_in", 0, 80), end=("off_ramp", (0, ), 40))), Mission(Route(begin=("left_in", 0, 30), end=("right_out", (0, ), 40))), ] gen_missions(scenario, agent_missions, overwrite=True) gen_traffic( scenario, Traffic(flows=[ Flow( route=RandomRoute(), rate=3600, actors={TrafficActor(name="car"): 1.0}, ) ]), name="random",