Пример #1
0
from pathlib import Path

from smarts.core import seed
from smarts.sstudio import gen_scenario
from smarts.sstudio import types as t

seed(42)

traffic = t.Traffic(flows=[
    t.Flow(
        route=t.RandomRoute(),
        rate=60 * 60,
        actors={t.TrafficActor(name="car", vehicle_type=vehicle_type): 1},
    ) for vehicle_type in [
        "passenger",
        "bus",
        "coach",
        "truck",
        "trailer",
    ]
])

laner_actor = t.SocialAgentActor(
    name="keep-lane-agent",
    agent_locator="zoo.policies:keep-lane-agent-v0",
)

gen_scenario(
    t.Scenario(
        traffic={"basic": traffic},
        social_agent_missions={
Пример #2
0
def main(args):
    all_args = get_args(args)
    num_agents = all_args.num_agents
    num_lanes = all_args.num_lanes
    born_lane_id = all_args.born_lane_id
    born_position_offset = all_args.born_position_offset
    target_lane_id = all_args.target_lane_id
    target_position_offset = all_args.target_position_offset

    trajectory_boid_agent = t.BoidAgentActor(
        name="trajectory-boid",
        agent_locator="scenarios.straight.agent_prefabs:trajectory-boid-agent-v0",
    )

    pose_boid_agent = t.BoidAgentActor(
        name="pose-boid",
        agent_locator="scenarios.straight.agent_prefabs:pose-boid-agent-v0",
    )

    traffic = t.Traffic(
        flows=[
            t.Flow(
                route=t.Route(begin=("west", lane_idx, 0), end=("east", lane_idx, "max"),),
                rate=50,
                actors={t.TrafficActor("car"): 1},
            )
            for lane_idx in range(num_lanes)
        ]
    )

    assert len(target_position_offset) == len(born_position_offset) == num_agents, ("different number")
    assert num_lanes <= 3, ("number of lanes can not exceed 3")
    for _i in range(num_agents):
        assert (born_lane_id[_i]<=2), ("the born_land_id can not exceed 2.")
        assert (target_lane_id[_i]<=2), ("the target_land_id can not exceed 2.")
        if not born_position_offset[_i] in ["max", "random"]:
            assert int(born_position_offset[_i])<=100, ("the born_position_offset should use value 0~100 or max or random.")
        if not target_position_offset[_i] in ["max", "random"]:
            assert int(target_position_offset[_i])<=100, ("the target_position_offset should use value 0~100 or max or random.")
    print("pass the assertion")
    missions = [t.Mission(t.Route(begin=("west", born_lane_id[agent_idx], born_position_offset[agent_idx]), end=("east", target_lane_id[agent_idx], target_position_offset[agent_idx]))) for agent_idx in range(num_agents)]

    scenario = t.Scenario(
        traffic={"all": traffic},
        ego_missions=missions,
        bubbles=[
            t.Bubble(
                zone=t.PositionalZone(pos=(50, 0), size=(40, 20)),
                margin=5,
                actor=trajectory_boid_agent,
            ),
            t.Bubble(
                zone=t.PositionalZone(pos=(150, 0), size=(50, 20)),
                margin=5,
                actor=pose_boid_agent,
                keep_alive=True,
            ),
        ],
    )

    gen_scenario(scenario, output_dir=str(Path(__file__).parent))
Пример #3
0
import random
from pathlib import Path

from smarts.sstudio import types as t
from smarts.sstudio import gen_scenario

traffic = t.Traffic(flows=[
    t.Flow(
        route=t.RandomRoute(),
        rate=60 * 60,
        actors={
            t.TrafficActor(
                name="car",
                vehicle_type=random.choice([
                    "passenger", "bus", "coach", "truck", "trailer"
                ]),
            ):
            1
        },
    ) for i in range(5)
])

laner_actor = t.SocialAgentActor(
    name="keep-lane-agent",
    agent_locator="zoo.policies:keep-lane-agent-v0",
)

slow_actor = t.SocialAgentActor(
    name=f"slow-agent",
    agent_locator="zoo.policies:non-interactive-agent-v0",
    policy_kwargs={"speed": 10},
Пример #4
0
from pathlib import Path
from typing import Any, Tuple

import smarts.sstudio.types as types
from smarts.sstudio import gen_missions, gen_traffic

scenario = str(Path(__file__).parent)

patient_car = types.TrafficActor(name="car", )

shared_route = types.Route(
    begin=("edge-east", 0, 20),
    end=("edge-west", 0, 0),
)

traffic = types.Traffic(
    flows=[types.Flow(
        route=shared_route,
        rate=1,
        actors={patient_car: 1},
    )])

gen_missions(
    scenario,
    missions=[
        types.Mission(shared_route),
    ],
)
gen_traffic(scenario, traffic, "traffic")
Пример #5
0
trajectory_boid_agent = t.BoidAgentActor(
    name="trajectory-boid",
    agent_locator="scenarios.straight.agent_prefabs:trajectory-boid-agent-v0",
)

pose_boid_agent = t.BoidAgentActor(
    name="pose-boid",
    agent_locator="scenarios.straight.agent_prefabs:pose-boid-agent-v0",
)

traffic = t.Traffic(flows=[
    t.Flow(
        route=t.Route(
            begin=("west", lane_idx, 0),
            end=("east", lane_idx, "max"),
        ),
        rate=50,
        actors={t.TrafficActor("car"): 1},
    ) for lane_idx in range(3)
])

scenario = t.Scenario(
    traffic={"all": traffic},
    bubbles=[
        t.Bubble(
            zone=t.PositionalZone(pos=(50, 0), size=(40, 20)),
            margin=5,
            actor=trajectory_boid_agent,
        ),
        t.Bubble(
            zone=t.PositionalZone(pos=(150, 0), size=(50, 20)),
Пример #6
0
from pathlib import Path

from smarts.sstudio import gen_scenario
from smarts.sstudio import types as t

traffic = t.Traffic(flows=[
    t.Flow(
        route=t.Route(begin=("edge-west-WE", 0, 10),
                      end=("edge-east-WE", 0, "max")),
        rate=400,
        actors={t.TrafficActor("car"): 1},
    ),
    t.Flow(
        route=t.Route(begin=("edge-east-EW", 0, 10),
                      end=("edge-west-EW", 0, "max")),
        rate=400,
        actors={t.TrafficActor("car"): 1},
    ),
])

agent_prefabs = "scenarios.intersections.4lane_t.agent_prefabs"
bubbles = [
    t.Bubble(
        zone=t.MapZone(start=("edge-west-WE", 0, 50), length=10, n_lanes=1),
        margin=2,
        actor=t.SocialAgentActor(
            name="zoo-agent",
            agent_locator=f"{agent_prefabs}:zoo-agent-v0",
        ),
    ),
    t.Bubble(
Пример #7
0
    name="car",
    speed=t.Distribution(sigma=0.2, mean=0.8),
    lane_changing_model=t.LaneChangingModel(impatience=0, cooperative=0.5),
    junction_model=t.JunctionModel(drive_after_yellow_time=1.0,
                                   impatience=0.5),
)

traffic = {
    "1":
    t.Traffic(flows=[
        t.Flow(
            route=t.Route(
                begin=(f"gneE17", 0, 2),
                end=(f"gneE5", 1, 120),
            ),
            rate=1,
            actors={
                impatient_car: 0.5,
                patient_car: 0.5
            },
        )
    ]),
    "2":
    t.Traffic(flows=[
        t.Flow(
            route=t.Route(
                begin=(f"gneE22", 0, 2),
                end=(f"gneE5", 0, 120),
            ),
            rate=1,
            actors={
Пример #8
0
turn_right_routes = [
    ("south-SN", "east-WE"),
    ("west-WE", "south-NS"),
    ("north-NS", "west-EW"),
    ("east-EW", "north-SN"),
]

traffic = {
    name: t.Traffic(flows=[
        t.Flow(
            route=t.Route(
                begin=(f"edge-{r[0]}", 0, "random"),
                end=(f"edge-{r[1]}", 0, "random"),
            ),
            rate=1,
            actors={
                impatient_car: 0.5,
                patient_car: 0.5
            },
        ) for r in routes
    ])
    for (name, routes) in {
        "vertical":
        vertical_routes,
        "horizontal":
        horizontal_routes,
        "unprotected_left":
        turn_left_routes,
        "turns":
        turn_left_routes + turn_right_routes,
Пример #9
0
    ),
)

patient_car = t.TrafficActor(
    name="car",
    speed=t.Distribution(sigma=0.2, mean=0.8),
    lane_changing_model=t.LaneChangingModel(impatience=0, cooperative=0.5),
    junction_model=t.JunctionModel(drive_after_yellow_time=1.0, impatience=0.5),
)

traffic = {
    "1": t.Traffic(
        flows=[
            t.Flow(
                route=t.Route(begin=(f"-gneE1", 0, 35), end=(f"-gneE1", 0, 100),),
                rate=1,
                actors={impatient_car: 0.5, patient_car: 0.5},
            )
        ]
    ),
    "2": t.Traffic(
        flows=[
            t.Flow(
                route=t.Route(begin=(f"gneE1", 0, 35), end=(f"gneE1", 0, 100),),
                rate=1,
                actors={impatient_car: 0.5, patient_car: 0.5},
            )
        ]
    ),
}
Пример #10
0
from smarts.sstudio import types as t

NUM_TRAFFIC_FLOWS = 350

traffic = t.Traffic(flows=[
    t.Flow(
        route=t.RandomRoute(),
        rate=60 * 2,
        actors={
            t.TrafficActor(
                name="car",
                vehicle_type=random.choices(
                    [
                        "passenger",
                        "bus",
                        "coach",
                        "truck",
                        "trailer",
                    ],
                    weights=[5, 1, 1, 1, 1],
                    k=1,
                )[0],
            ):
            1
        },
    ) for _ in range(NUM_TRAFFIC_FLOWS)
])

laner_actor = t.SocialAgentActor(
    name="keep-lane-agent",
    agent_locator="zoo.policies:keep-lane-agent-v0",
Пример #11
0
from pathlib import Path

from smarts.sstudio import gen_scenario
from smarts.sstudio import types as t

traffic = t.Traffic(
    flows=[
        t.Flow(
            route=t.Route(
                begin=("west", 0, 10),
                end=("east", 0, "max"),
            ),
            rate=1,
            actors={t.TrafficActor("car", max_speed=8): 1},
            begin=2,
        )
    ]
)

social_agent_missions = {
    "all": (
        [
            t.SocialAgentActor(
                name="open-agent",
                agent_locator="open_agent:open_agent-v0",
                initial_speed=20,
            ),
        ],
        [
            t.Mission(
                t.Route(begin=("west", 1, 10), end=("east", 0, "max")),
Пример #12
0
from pathlib import Path

from smarts.sstudio import types as t
from smarts.sstudio import gen_scenario

NUM_TRAFFIC_FLOWS = 60

traffic = t.Traffic(flows=[
    t.Flow(
        route=t.RandomRoute(),
        rate=60 * 5,
        actors={
            t.TrafficActor(
                name="car",
                vehicle_type=random.choice([
                    "passenger", "bus", "coach", "truck"
                ]),
                speed=t.Distribution(1, 0.3),
                max_speed=10,
            ):
            1
        },
    ) for _ in range(NUM_TRAFFIC_FLOWS)
])

lane_actor_list = [
    t.SocialAgentActor(
        name=f"keep-lane-agent-{idx}",
        agent_locator="zoo.policies:keep-lane-agent-v0",
        policy_kwargs={'speed': random.choice([5.5, 6, 6.5, 7, 7.5, 8, 9])})
    for idx in range(10)
Пример #13
0
import os
from pathlib import Path

from smarts.sstudio import gen_scenario
from smarts.sstudio import types as t

traffic = t.Traffic(flows=[
    t.Flow(
        route=t.Route(begin=("edge-west-EW", 0, 10),
                      end=("edge-west-EW", 0, "max")),
        rate=1,
        actors={t.TrafficActor(name="car", max_speed=30 / 3.6): 1.0},
        begin=2,
    )
])

social_agent_missions = {
    "all": (
        [
            t.SocialAgentActor(
                name="open-agent-default",
                agent_locator="open_agent:open_agent-v0",
                # policy_kwargs={"gains": stable_config},
            ),
        ],
        [
            t.Mission(
                t.Route(begin=("edge-west-WE", 0, 10),
                        end=("edge-west-EW", 0, "max")),
                task=t.UTurn(target_lane_index=0),
            ),
Пример #14
0
act1 = t.TrafficActor(name="car",
                      speed=t.Distribution(mean=1.0, sigma=0.1),
                      min_gap=t.Distribution(mean=2.5, sigma=0))
act2 = t.TrafficActor(name="car",
                      speed=t.Distribution(mean=1.0, sigma=0.3),
                      min_gap=t.Distribution(mean=2.5, sigma=0.2))

traffic = t.Traffic(flows=[
    t.Flow(
        route=t.Route(
            begin=("west", lane_idx, "random"),
            end=("east", lane_idx, "max"),
        ),
        # route=t.RandomRoute(),
        # rate=50,
        end=2 * 60 * 60,
        rate=600,
        # actors={t.TrafficActor("car"): 1},
        actors={
            act1: 0.5,
            act2: 0.5
        },
        # actors={t.TrafficActor(name="car", speed = t.Distribution(mean=1.0, sigma=0), min_gap = t.Distribution(mean=2.5, sigma=0)): 1},
    ) for lane_idx in range(3)
])

missions = [
    # t.Mission(t.Route(begin=("west", 1, 10), end=("east", 1, 90))),
    t.Mission(t.Route(begin=("west", 1, 5), end=("east", 0, "max"))),
]

scenario = t.Scenario(