Ejemplo n.º 1
0
def two_agent_capture_offset_tenth_of_second():
    with temp_scenario(name="straight",
                       map="maps/straight.net.xml") as scenario_root:
        missions = [
            t.Mission(
                t.Route(begin=("west", 1, 20), end=("east", 1, "max")),
                entry_tactic=t.TrapEntryTactic(
                    wait_to_hijack_limit_s=0,
                    zone=t.MapZone(start=("west", 0, 1), length=100,
                                   n_lanes=3),
                ),
            ),
            t.Mission(
                t.Route(begin=("west", 2, 10), end=("east", 1, "max")),
                entry_tactic=t.TrapEntryTactic(
                    wait_to_hijack_limit_s=0.1,
                    zone=t.MapZone(start=("west", 0, 1), length=100,
                                   n_lanes=3),
                ),
            ),
        ]

        scenario = t.Scenario(
            traffic={},
            ego_missions=missions,
        )

        gen_scenario(scenario, output_dir=scenario_root)
        yield Scenario.variations_for_all_scenario_roots(
            [str(scenario_root)], [AGENT_ID, AGENT_ID_2])
Ejemplo n.º 2
0
def scenarios():
    with temp_scenario(name="straight", map="maps/straight.net.xml") as scenario_root:
        ego_missions = [
            # missions of laner and buddha
            t.Mission(
                t.Route(
                    begin=("west", 0, 30),
                    end=("east", 0, "max"),
                )
            ),
            t.Mission(
                t.Route(
                    begin=("west", 0, 40),
                    end=("east", 0, "max"),
                )
            ),
        ]
        gen_scenario(
            t.Scenario(ego_missions=ego_missions),
            output_dir=scenario_root,
        )

        yield Scenario.variations_for_all_scenario_roots(
            [str(scenario_root)], [AGENT_1, AGENT_2]
        )
Ejemplo n.º 3
0
def scenarios():
    with temp_scenario(name="straight",
                       map="maps/straight.net.xml") as scenario_root:
        traffic = t.Traffic(flows=[
            t.Flow(
                route=t.Route(
                    begin=("west", 1, 0),
                    end=("east", 1, "max"),
                ),
                rate=50,
                actors={t.TrafficActor("car"): 1},
            )
        ])

        missions = [
            t.Mission(
                t.Route(begin=("west", 1, 10), end=("east", 1, "max")),
                entry_tactic=t.TrapEntryTactic(
                    wait_to_hijack_limit_s=3,
                    zone=t.MapZone(start=("west", 0, 1), length=100,
                                   n_lanes=3),
                ),
            )
        ]
        scenario = t.Scenario(
            traffic={"all": traffic},
            ego_missions=missions,
        )

        gen_scenario(scenario, output_dir=scenario_root)
        yield Scenario.variations_for_all_scenario_roots([str(scenario_root)],
                                                         [AGENT_ID])
Ejemplo n.º 4
0
def scenarios(bubble):
    with temp_scenario(name="straight",
                       map="maps/straight.net.xml") as scenario_root:
        gen_scenario(
            t.Scenario(traffic={}, bubbles=[bubble]),
            output_dir=scenario_root,
        )
        yield Scenario.variations_for_all_scenario_roots([str(scenario_root)],
                                                         [])
Ejemplo n.º 5
0
def scenarios(request):
    with temp_scenario(name="map", map=request.param[0]) as scenario_root:
        mission = t.Mission(route=t.Route(begin=("edge-west-WE", 0, 10),
                                          end=(request.param[1], 0, 40)))
        gen_scenario(
            t.Scenario(ego_missions=[mission]),
            output_dir=scenario_root,
        )
        yield Scenario.variations_for_all_scenario_roots([str(scenario_root)],
                                                         [AGENT_ID])
def scenario():
    with temp_scenario(name="map",
                       map="maps/straight.net.xml") as scenario_root:
        mission = t.Mission(route=t.Route(
            begin=("west", 1, 99.9),
            end=("east", 1, 10.0),
        ))
        gen_scenario(
            t.Scenario(ego_missions=[mission]),
            output_dir=scenario_root,
        )
        yield Scenario.variations_for_all_scenario_roots([str(scenario_root)],
                                                         [AGENT_ID])
Ejemplo n.º 7
0
def uturn_scenarios():
    with temp_scenario(name="straight",
                       map="maps/6lane.net.xml") as scenario_root:
        ego_missions = [
            t.Mission(
                route=t.Route(begin=("edge-west-WE", 0, 30),
                              end=("edge-west-EW", 0, "max")),
                task=t.UTurn(),
            ),
        ]
        gen_scenario(
            t.Scenario(ego_missions=ego_missions),
            output_dir=scenario_root,
        )

        yield Scenario.variations_for_all_scenario_roots([str(scenario_root)],
                                                         [AGENT_ID])
Ejemplo n.º 8
0
def scenarios():
    with temp_scenario(name="6lane", map="maps/6lane.net.xml") as scenario_root:
        actors = [
            t.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]
        ]

        def to_mission(start_edge, end_edge):
            route = t.Route(begin=(start_edge, 1, 0), end=(end_edge, 1, "max"))
            return t.Mission(route=route)

        def fifth_mission(start_edge, end_edge):
            route = t.Route(begin=(start_edge, 0, 0), end=(end_edge, 0, "max"))
            return t.Mission(route=route)

        gen_scenario(
            t.Scenario(
                social_agent_missions={
                    "group-1": (actors, [to_mission("edge-north-NS", "edge-south-NS")]),
                    "group-2": (actors, [to_mission("edge-west-WE", "edge-east-WE")]),
                    "group-3": (actors, [to_mission("edge-east-EW", "edge-west-EW")]),
                    "group-4": (actors, [to_mission("edge-south-SN", "edge-north-SN")]),
                    "group-5": (
                        actors,
                        [fifth_mission("edge-south-SN", "edge-east-WE")],
                    ),
                },
                ego_missions=[
                    t.Mission(
                        t.Route(
                            begin=("edge-west-WE", 0, 0), end=("edge-east-WE", 0, "max")
                        )
                    )
                ],
            ),
            output_dir=scenario_root,
        )
        yield Scenario.variations_for_all_scenario_roots(
            [str(scenario_root)], [AGENT_1]
        )
Ejemplo n.º 9
0
def scenarios(bubbles, num_vehicles):
    with temp_scenario(name="6lane",
                       map="maps/6lane.net.xml") as scenario_root:
        traffic = t.Traffic(flows=[
            t.Flow(
                route=t.Route(
                    begin=("edge-west-WE", lane, 0),
                    end=("edge-east-WE", lane, "max"),
                ),
                rate=10,
                actors={t.TrafficActor(name="car"): 1},
            ) for lane in range(num_vehicles)
        ])

        gen_scenario(
            t.Scenario(traffic={"all": traffic}, bubbles=bubbles),
            output_dir=scenario_root,
        )

        yield Scenario.variations_for_all_scenario_roots([str(scenario_root)],
                                                         [])
Ejemplo n.º 10
0
def scenarios(bubble):
    with temp_scenario(name="straight", map="maps/straight.net.xml") as scenario_root:
        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)
            ]
        )

        gen_scenario(
            t.Scenario(traffic={"all": traffic}, bubbles=[bubble]),
            output_dir=scenario_root,
        )

        yield Scenario.variations_for_all_scenario_roots([str(scenario_root)], [])
Ejemplo n.º 11
0
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)),
            margin=5,
            actor=pose_boid_agent,
            keep_alive=True,
        ),
    ],
)

gen_scenario(scenario, output_dir=str(Path(__file__).parent))
Ejemplo n.º 12
0
from pathlib import Path

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

gen_scenario(
    t.Scenario(traffic_histories=[
        "us101_0750-0805.yml",
        "us101_0805-0820.yml",
        "us101_0820-0835.yml",
    ], ),
    output_dir=Path(__file__).parent,
)
Ejemplo n.º 13
0
        "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={
            "all": ([laner_actor], [t.Mission(route=t.RandomRoute())])
        },
        bubbles=[
            t.Bubble(
                zone=t.PositionalZone(pos=(50, 0), size=(10, 15)),
                margin=5,
                actor=laner_actor,
                follow_actor_id=t.Bubble.to_actor_id(laner_actor,
                                                     mission_group="all"),
                follow_offset=(-7, 10),
            ),
        ],
    ),
    output_dir=Path(__file__).parent,
)
Ejemplo n.º 14
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))
Ejemplo n.º 15
0
            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),
            ),
        ],
    ),
}

ego_missions = [
    t.Mission(
        t.Route(begin=("edge-west-WE", 0, 10), end=("edge-west-EW", 0, "max")),
        task=t.UTurn(),
    )
]

gen_scenario(
    scenario=t.Scenario(traffic={"basic": traffic},
                        ego_missions=ego_missions
                        # social_agent_missions=social_agent_missions,
                        ),
    output_dir=Path(__file__).parent,
)
Ejemplo n.º 16
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.RandomRoute(),
        rate=60 * 60,
        actors={t.TrafficActor(name="car", vehicle_type=vehicle_type): 1},
    ) for vehicle_type in [
        "passenger",
        "bus",
        "coach",
        "truck",
        "trailer",
        "passenger",
        "bus",
        "coach",
        "truck",
        "trailer",
    ]
])

gen_scenario(
    t.Scenario(traffic={"basic": traffic}, ),
    output_dir=Path(__file__).parent,
)
Ejemplo n.º 17
0
from pathlib import Path

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

ego_missions = [
    t.Mission(t.Route(begin=("1_0_R", 1, 5), end=("1_2_R", 1, "max")))
]

gen_scenario(
    scenario=t.Scenario(ego_missions=ego_missions, ),
    output_dir=str(Path(__file__).parent),
    overwrite=True,
)
Ejemplo n.º 18
0
boid_agent = t.BoidAgentActor(
    name="hive-mind",
    agent_locator="scenarios.straight.agent_prefabs: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=(100, 0), size=(30, 20)),
            margin=5,
            actor=boid_agent,
        ),
    ],
)

gen_scenario(scenario, output_dir=str(Path(__file__).parent))
Ejemplo n.º 19
0
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# 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
import smarts.sstudio.types as t

missions = [
    t.Mission(t.Route(begin=("-gneE1", 0, 5), end=("-gneE1", 0, 97))),
    t.Mission(t.Route(begin=("gneE1", 0, 5), end=("gneE1", 0, 97))),
    t.Mission(t.Route(begin=("-gneE1", 0, 20), end=("-gneE1", 0, 97))),
    t.Mission(t.Route(begin=("gneE1", 0, 20), end=("gneE1", 0, 97))),
]

gen_scenario(
    t.Scenario(ego_missions=missions),
    output_dir=Path(__file__).parent,
)
Ejemplo n.º 20
0
laner_actor = t.SocialAgentActor(
    name="keep-lane-agent", agent_locator="zoo.policies:keep-lane-agent-v0",
)

travelling_bubbles = [
    t.Bubble(
        zone=t.PositionalZone(pos=(50, 0), size=(10, 50)),
        margin=5,
        actor=open_agent_actor,
        follow_actor_id=t.Bubble.to_actor_id(laner_actor, mission_group="all"),
        follow_offset=(-7, 10),
    )
]

static_bubbles = [
    t.Bubble(zone=t.MapZone((id_, 0, 10), 200, 1), margin=5, actor=laner_actor,)
    for id_ in ["21675239", "126742590#1", "-77720372", "-263506114#6", "-33002812#1"]
]

gen_scenario(
    t.Scenario(
        traffic={"basic": traffic},
        social_agent_missions={
            "all": ([laner_actor, open_agent_actor], [t.Mission(route=t.RandomRoute())])
        },
        bubbles=[*travelling_bubbles, *static_bubbles],
    ),
    output_dir=Path(__file__).parent,
)
Ejemplo n.º 21
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(10)
])
gen_scenario(t.Scenario(traffic={"basic": traffic}),
             output_dir=Path(__file__).parent)
Ejemplo n.º 22
0
        [
            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")),
                task=t.CutIn(),
            )
        ],
    ),
}

ego_missions = [
    t.Mission(
        t.Route(begin=("west", 1, 5), end=("east", 0, "max")),
        task=t.CutIn(),
    )
]

scenario = t.Scenario(
    traffic={"all": traffic},
    ego_missions=ego_missions,
    # social_agent_missions=social_agent_missions,
)

gen_scenario(scenario, output_dir=str(Path(__file__).parent))
Ejemplo n.º 23
0
            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)
]

mission_list = [t.Mission(route=t.RandomRoute()) for _ in range(10)]

gen_scenario(
    t.Scenario(
        traffic={"basic": traffic},
        social_agent_missions={"all": (lane_actor_list, mission_list)},
    ),
    output_dir=Path(__file__).parent,
)
Ejemplo n.º 24
0
from pathlib import Path

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

gen_scenario(
    t.Scenario(
        traffic_histories=[
            "i80_0400-0415.yml",
            "i80_0500-0515.yml",
            "i80_0515-0530.yml",
        ],
    ),
    output_dir=Path(__file__).parent,
)
Ejemplo n.º 25
0
    ),
]

ego_missions = [t.EndlessMission(begin=("edge-south-SN", 1, 20), )]

social_agent_missions = {
    "all": (
        [
            t.SocialAgentActor(name="open-agent",
                               agent_locator="open_agent:open_agent-v0"),
            t.SocialAgentActor(name="rl-agent",
                               agent_locator="rl_agent:rl-agent-v1"),
        ],
        [
            t.Mission(
                t.Route(begin=("edge-west-WE", 1, 10),
                        end=("edge-east-WE", 1, "max")))
        ],
    ),
}

gen_scenario(
    scenario=t.Scenario(
        traffic={"basic": traffic},
        bubbles=bubbles,
        ego_missions=ego_missions,
        social_agent_missions=social_agent_missions,
    ),
    output_dir=Path(__file__).parent,
)
Ejemplo n.º 26
0
from pathlib import Path

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

missions = [
    t.Mission(t.Route(begin=("-gneE1", 0, 5), end=("-gneE1", 0, 97))),
    t.Mission(t.Route(begin=("gneE1", 0, 5), end=("gneE1", 0, 97))),
    t.Mission(t.Route(begin=("-gneE1", 0, 20), end=("-gneE1", 0, 97))),
    t.Mission(t.Route(begin=("gneE1", 0, 20), end=("gneE1", 0, 97))),
]

gen_scenario(
    t.Scenario(ego_missions=missions), output_dir=Path(__file__).parent,
)
Ejemplo n.º 27
0
                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={
                impatient_car: 0.5,
                patient_car: 0.5
            },
        )
    ]),
}

gen_scenario(
    t.Scenario(ego_missions=missions, traffic=traffic),
    output_dir=Path(__file__).parent,
)
Ejemplo n.º 28
0
            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(
    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))