コード例 #1
0
def test_goal_tree_model_2():
    model = get_goal_tree_model()
    frame0 = Frame(0)
    state0 = AgentState(0, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    frame0.add_agent_state(0, state0)
    frame1 = Frame(1)
    state1 = AgentState(1, 0.5, 0.5, 0, 0, np.pi / 8, 0, 0, 0, 0, 0, 0)
    frame1.add_agent_state(0, state1)
    frames = [frame0, frame1]
    probs = model.goal_probabilities(frames, 0)
    assert np.allclose(probs, [0.75, 0.25])
コード例 #2
0
def test_get_vehicles_in_front():
    feature_extractor = get_feature_extractor()
    start_lanelet = feature_extractor.lanelet_map.laneletLayer.get(1)
    goal = (3.5, 0.5)
    route = feature_extractor.route_to_goal(start_lanelet, goal)

    frame = Frame(0)
    frame.add_agent_state(0, AgentState(0, 2.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0,
                                        0))
    frame.add_agent_state(1, AgentState(0, 3.0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0,
                                        0))
    frame.add_agent_state(2, AgentState(0, 3.0, 1.5, 0, 0, 0, 0, 0, 0, 0, 0,
                                        0))
    vehicles = FeatureExtractor.get_vehicles_in_front(route, frame)
    assert set(vehicles) == {0, 1}
コード例 #3
0
def test_get_goals_current_lanelets_multiple():
    feature_extractor = get_feature_extractor()
    goals = [(3.5, 1.5), (3.0, 2.5)]
    state = AgentState(0, 2.2, 1.5, 0, 0, 0.1, 0, 0, 0, 0, 0, 0)
    routes = feature_extractor.get_goal_routes(state, goals)
    current_lanelets = [r.shortestPath()[0] for r in routes]
    assert [l.id for l in current_lanelets] == [4, 5]
コード例 #4
0
def test_goal_type_turn_left():
    feature_extractor = get_feature_extractor()
    start_lanelet = feature_extractor.lanelet_map.laneletLayer.get(1)
    goal = (3.0, 2.5)
    route = feature_extractor.route_to_goal(start_lanelet, goal)
    state = AgentState(0, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    assert feature_extractor.goal_type(state, goal, route) == 'turn-left'
コード例 #5
0
def test_goal_type_straight_on():
    feature_extractor = get_feature_extractor()
    start_lanelet = feature_extractor.lanelet_map.laneletLayer.get(1)
    goal = (3.5, 0.5)
    route = feature_extractor.route_to_goal(start_lanelet, goal)
    state = AgentState(0, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    assert feature_extractor.goal_type(state, goal, route) == 'straight-on'
コード例 #6
0
def test_goal_tree_model():
    model = get_goal_tree_model()
    frame = Frame(0)
    state = AgentState(0, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    frame.add_agent_state(0, state)
    frames = [frame]
    probs = model.goal_probabilities(frames, 0)
    assert np.allclose(probs, [0.92307692, 0.07692308])
コード例 #7
0
def test_path_to_goal_length_different_lanelet():
    feature_extractor = get_feature_extractor()
    state = AgentState(0, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    goal = (3.5, 0.5)
    start_lanelet = feature_extractor.lanelet_map.laneletLayer.get(1)
    end_lanelet = feature_extractor.lanelet_map.laneletLayer.get(3)
    route = feature_extractor.routing_graph.getRoute(start_lanelet,
                                                     end_lanelet)
    assert feature_extractor.path_to_goal_length(state, goal, route) == 3
コード例 #8
0
def test_vehicle_in_front():
    feature_extractor = get_feature_extractor()
    start_lanelet = feature_extractor.lanelet_map.laneletLayer.get(1)
    goal = (3.5, 0.5)
    route = feature_extractor.route_to_goal(start_lanelet, goal)

    frame = Frame(0)

    frame.add_agent_state(0, AgentState(0, 3.0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0,
                                        0))
    frame.add_agent_state(1, AgentState(0, 2.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0,
                                        0))
    frame.add_agent_state(2, AgentState(0, 3.0, 1.5, 0, 0, 0, 0, 0, 0, 0, 0,
                                        0))

    state = AgentState(0, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0)

    agent_id, dist = FeatureExtractor.vehicle_in_front(state, route, frame)
    assert agent_id == 1
    assert dist == 2
コード例 #9
0
def get_current_lanelet_turn():
    feature_extractor = get_feature_extractor()
    state = AgentState(0, 3, 1.5, 0, 0, np.pi / 4, 0, 0, 0, 0, 0, 0)
    lanelet = feature_extractor.get_current_lanelet(state)
    assert lanelet.id == 5
コード例 #10
0
def get_current_lanelet_straight():
    feature_extractor = get_feature_extractor()
    state = AgentState(0, 3, 1.5, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    lanelet = feature_extractor.get_current_lanelet(state)
    assert lanelet.id == 4
コード例 #11
0
def get_current_lanelet_simple():
    feature_extractor = get_feature_extractor()
    state = AgentState(0, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    lanelet = feature_extractor.get_current_lanelet(state)
    assert lanelet.id == 1
コード例 #12
0
def test_angle_in_lane_curved():
    state = AgentState(0, 1.5, 1.0, 0, 0, np.pi / 2, 0, 0, 0, 0, 0, 0)
    lanelet = get_test_lanelet_curved()
    assert FeatureExtractor.angle_in_lane(state,
                                          lanelet) == pytest.approx(np.pi / 4)
コード例 #13
0
def test_angle_in_lane_straight():
    state = AgentState(0, 0.5, 0.75, 0, 0, np.pi / 4, 0, 0, 0, 0, 0, 0)
    lanelet = get_test_lanelet_straight()
    assert FeatureExtractor.angle_in_lane(state,
                                          lanelet) == pytest.approx(np.pi / 4)
コード例 #14
0
def test_angle_to_goal_angled():
    state = AgentState(0, 2.5, 1.5, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    goal = (3.5, 0.5)
    assert FeatureExtractor.angle_to_goal(state,
                                          goal) == pytest.approx(np.pi / 4)
コード例 #15
0
def test_angle_to_goal_zero():
    state = AgentState(0, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    goal = (3.5, 0.5)
    assert FeatureExtractor.angle_to_goal(state, goal) == 0