diff --git a/demo/demo1.py b/demo/demo1.py index b4c57e0c6047e4ab6d0feaec9a072a2697989757..681f9282854933abd672805f9aad17772020e11e 100644 --- a/demo/demo1.py +++ b/demo/demo1.py @@ -34,7 +34,7 @@ class State: if __name__ == "__main__": - input_code_name = 'example_controller1.py' + input_code_name = './example_controller1.py' scenario = Scenario() car = NPCAgent('car1') diff --git a/demo/demo2.py b/demo/demo2.py index 7c8d006f6a2c9bb62dd972e5a2121ee64219dd91..45fa7927341e720c7f6802c82b8e1381e800afcc 100644 --- a/demo/demo2.py +++ b/demo/demo2.py @@ -54,8 +54,8 @@ if __name__ == "__main__": (VehicleMode.Normal, LaneMode.Lane1), ] ) - # res_list = scenario.simulate(40) - traces = scenario.verify(40) + # res_list = scenario.simulate(40, 0.05) + traces = scenario.verify(40, 0.05) fig = plt.figure(2) fig = plot_map(tmp_map, 'g', fig) diff --git a/demo/demo3.py b/demo/demo3.py index 83ab13376c2c9c88f94e42e8f6f95e038c5005d0..0209421b5ac4862359856d1b42875af9e1ca5241 100644 --- a/demo/demo3.py +++ b/demo/demo3.py @@ -3,7 +3,6 @@ from dryvr_plus_plus.example.example_agent.car_agent import CarAgent from dryvr_plus_plus.scene_verifier.scenario.scenario import Scenario from dryvr_plus_plus.example.example_map.simple_map2 import SimpleMap2, SimpleMap3, SimpleMap5, SimpleMap6 from dryvr_plus_plus.plotter.plotter2D import * -from dryvr_plus_plus.example.example_sensor.fake_sensor import FakeSensor3 import matplotlib.pyplot as plt import plotly.graph_objects as go @@ -35,14 +34,14 @@ class State: v = 0.0 vehicle_mode: VehicleMode = VehicleMode.Normal lane_mode: LaneMode = LaneMode.Lane0 - type_mode: LaneObjectMode = LaneObjectMode.Vehicle + type: LaneObjectMode = LaneObjectMode.Vehicle - def __init__(self, x, y, theta, v, vehicle_mode: VehicleMode, lane_mode: LaneMode, type_mode: LaneObjectMode): + def __init__(self, x, y, theta, v, vehicle_mode: VehicleMode, lane_mode: LaneMode, type: LaneObjectMode): pass if __name__ == "__main__": - input_code_name = './demo/example_controller4.py' + input_code_name = './example_controller4.py' scenario = Scenario() car = CarAgent('car1', file_name=input_code_name) @@ -76,8 +75,8 @@ if __name__ == "__main__": fig = plot_map(tmp_map, 'g', fig) fig = plot_reachtube_tree(traces, 'car1', 1, [2], 'b', fig) fig = plot_reachtube_tree(traces, 'car2', 1, [2], 'r', fig) - fig = plot_reachtube_tree(traces, 'car3', 1, [2], 'r', fig) - fig = plot_reachtube_tree(traces, 'car4', 1, [2], 'r', fig) + # fig = plot_reachtube_tree(traces, 'car3', 1, [2], 'r', fig) + # fig = plot_reachtube_tree(traces, 'car4', 1, [2], 'r', fig) plt.show() # fig = go.Figure() diff --git a/demo/demo4.py b/demo/demo4.py index 098a4de7c690dc639178b87cad4bcebcf13514db..8f6f4bf38ebed12cb357232380376d7a42f2cfa0 100644 --- a/demo/demo4.py +++ b/demo/demo4.py @@ -2,8 +2,6 @@ from dryvr_plus_plus.example.example_agent.car_agent import CarAgent, NPCAgent from dryvr_plus_plus.scene_verifier.scenario.scenario import Scenario from dryvr_plus_plus.example.example_map.simple_map2 import SimpleMap2, SimpleMap3, SimpleMap4, SimpleMap5, SimpleMap6 from dryvr_plus_plus.plotter.plotter2D import * -from dryvr_plus_plus.example.example_sensor.fake_sensor import FakeSensor3 -from dryvr_plus_plus.scene_verifier.sensor.base_sensor import BaseSensor import matplotlib.pyplot as plt import plotly.graph_objects as go diff --git a/demo/demo5.py b/demo/demo5.py index 8c9ffdd990c1db4a8bd528114f2ba5f66204eac0..1607ad52e93df835e3cee1aeebf453a527d45a03 100644 --- a/demo/demo5.py +++ b/demo/demo5.py @@ -3,7 +3,6 @@ from dryvr_plus_plus.example.example_agent.car_agent import CarAgent from dryvr_plus_plus.scene_verifier.scenario.scenario import Scenario from dryvr_plus_plus.example.example_map.simple_map2 import SimpleMap2, SimpleMap3, SimpleMap5, SimpleMap6 from dryvr_plus_plus.plotter.plotter2D import * -from dryvr_plus_plus.example.example_sensor.fake_sensor import FakeSensor3 from dryvr_plus_plus.scene_verifier.sensor.base_sensor import BaseSensor import matplotlib.pyplot as plt diff --git a/demo/demo6.py b/demo/demo6.py index b2e6563b9a16357921aeab17038cbce4dcdcbdb0..7532b251c544833f0636f3dadfbcfa52b6cbf00f 100644 --- a/demo/demo6.py +++ b/demo/demo6.py @@ -3,7 +3,6 @@ from dryvr_plus_plus.example.example_agent.car_agent import CarAgent from dryvr_plus_plus.scene_verifier.scenario.scenario import Scenario from dryvr_plus_plus.example.example_map.simple_map2 import SimpleMap2, SimpleMap3, SimpleMap4, SimpleMap5, SimpleMap6 from dryvr_plus_plus.plotter.plotter2D import * -from dryvr_plus_plus.example.example_sensor.fake_sensor import FakeSensor3 from dryvr_plus_plus.scene_verifier.sensor.base_sensor import BaseSensor import matplotlib.pyplot as plt @@ -84,7 +83,7 @@ if __name__ == "__main__": ] ) # traces = scenario.simulate(80, 0.05) - traces = scenario.verify(50, 0.05) + traces = scenario.verify(80, 0.05) fig = plt.figure(2) fig = plot_map(tmp_map, 'g', fig) diff --git a/dryvr_plus_plus/example/example_sensor/fake_sensor.py b/dryvr_plus_plus/example/example_sensor/fake_sensor.py index a982ef6b451eca842e460635f1b2fdaff2e933f4..a1d1946af1a958d8abe8e3d85a088b2849ac7b59 100644 --- a/dryvr_plus_plus/example/example_sensor/fake_sensor.py +++ b/dryvr_plus_plus/example/example_sensor/fake_sensor.py @@ -25,28 +25,32 @@ def adds(d, thing, attrs, vals): d[thing + '.' + k].append(v) def add_states_2d(cont, disc, thing, val): - state, mode = val + state, mode, static = val adds(cont, thing, ['x','y','theta','v'], state[1:5]) - adds(disc, thing, ["vehicle_mode", "lane_mode", "type"], mode) + adds(disc, thing, ["vehicle_mode", "lane_mode"], mode) + adds(disc, thing, ['type'], static) def add_states_3d(cont, disc, thing, val): - state, mode = val + state, mode, static = val transp = np.transpose(np.array(state)[:, 1:5]) assert len(transp) == 4 adds(cont, thing, ["x", "y", "theta", "v"], transp) - adds(disc, thing, ["vehicle_mode", "lane_mode", "type"], mode) + adds(disc, thing, ["vehicle_mode", "lane_mode"], mode) + adds(disc, thing, ['type'], static) def set_states_2d(cnts, disc, thing, val): - state, mode = val + state, mode, static = val sets(cnts, thing, ["x", "y", "theta", "v"], state[1:5]) - sets(disc, thing, ["vehicle_mode", "lane_mode", "type"], mode) + sets(disc, thing, ["vehicle_mode", "lane_mode"], mode) + sets(disc, thing, ['type'], static) def set_states_3d(cnts, disc, thing, val): - state, mode = val + state, mode, static = val transp = np.transpose(np.array(state)[:, 1:5]) assert len(transp) == 4 sets(cnts, thing, ["x", "y", "theta", "v"], transp) - sets(disc, thing, ["vehicle_mode", "lane_mode", "type"], mode) + sets(disc, thing, ["vehicle_mode", "lane_mode"], mode) + sets(disc, thing, ['type'], static) class FakeSensor2: def sense(self, scenario, agent, state_dict, lane_map): @@ -87,65 +91,3 @@ class FakeSensor2: if "sign" in state_dict: set_states_3d(cnts, disc, "sign", state_dict["sign"]) return cnts, disc, {} - -class FakeSensor3: - def sense(self, scenario, agent, state_dict, lane_map): - cont = {} - disc = {} - len_dict = {'others':len(state_dict)-1} - tmp = np.array(state_dict['car1'][0]) - if tmp.ndim < 2: - for agent_id in state_dict: - if agent_id == agent.id: - set_states_2d(cont, disc, 'ego', state_dict[agent_id]) - else: - add_states_2d(cont, disc, 'others', state_dict[agent_id]) - else: - for agent_id in state_dict: - if agent_id == agent.id: - set_states_3d(cont, disc, "ego", state_dict[agent_id]) - else: - add_states_3d(cont, disc, 'others', state_dict[agent_id]) - return cont, disc, len_dict - - -def set_states_2d_ball(cnts, disc, thing, val): - state, mode = val - sets(cnts, thing, ["x", "y", "vx", "vy"], state[1:5]) - sets(disc, thing, ["ball_mode", "lane_mode"], mode) -def set_states_3d_ball(cnts, disc, thing, val): - state, mode = val - transp = np.transpose(np.array(state)[:, 1:5]) - assert len(transp) == 4 - sets(cnts, thing, ["x", "y", "vx", "vy"], transp) - sets(disc, thing, ["ball_mode", "lane_mode"], mode) -def add_states_2d_ball(cont, disc, thing, val): - state, mode = val - adds(cont, thing, ['x','y','vx','vy'], state[1:5]) - adds(disc, thing, ["ball_mode", "lane_mode", "type"], mode) -def add_states_3d_ball(cont, disc, thing, val): - state, mode = val - transp = np.transpose(np.array(state)[:, 1:5]) - assert len(transp) == 4 - adds(cont, thing, ['x','y','vx','vy'], transp) - adds(disc, thing, ["ball_mode", "lane_mode", "type"], mode) - -class FakeSensor4: - def sense(self, scenario, agent, state_dict, lane_map): - cont = {} - disc = {} - len_dict = {'others':len(state_dict)-1} - tmp = np.array(list(state_dict.values())[0]) - if tmp.ndim < 2: - for agent_id in state_dict: - if agent_id == agent.id: - set_states_2d_ball(cont, disc, 'ego', state_dict[agent_id]) - else: - add_states_2d_ball(cont, disc, 'others', state_dict[agent_id]) - else: - for agent_id in state_dict: - if agent_id == agent.id: - set_states_3d_ball(cont, disc, "ego", state_dict[agent_id]) - else: - add_states_3d_ball(cont, disc, 'others', state_dict[agent_id]) - return cont, disc, len_dict \ No newline at end of file diff --git a/dryvr_plus_plus/scene_verifier/scenario/scenario.py b/dryvr_plus_plus/scene_verifier/scenario/scenario.py index f9e94fe6bd1ecbd8dea4c1e188aa888615e75217..286b7e9165cf53c2c71a28e60b55565ccaa63703 100644 --- a/dryvr_plus_plus/scene_verifier/scenario/scenario.py +++ b/dryvr_plus_plus/scene_verifier/scenario/scenario.py @@ -143,7 +143,7 @@ class Scenario: lhs = reset_variable rhs = expr for lhs_idx, cts_variable in enumerate(agent.controller.state_defs[agent.controller.ego_type].cont): - if "output."+cts_variable == lhs: + if cts_variable == lhs: break # substituting low variables