Skip to content
Snippets Groups Projects
Commit 9041ae32 authored by li213's avatar li213
Browse files

handle cases when the returned transition is empty

parent a2d8f0c9
No related branches found
No related tags found
No related merge requests found
......@@ -54,22 +54,17 @@ if __name__ == "__main__":
(VehicleMode.Normal, LaneMode.Lane1),
]
)
# # res_list = scenario.simulate_multi(40,1)
# traces = scenario.verify(40)
# res_list = scenario.simulate(40)
traces = scenario.verify(40)
# fig = plt.figure(2)
# 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)
# # for traces in res_list:
# # generate_simulation_anime(traces, tmp_map, fig)
# # # fig,x_lim,y_lim = plot_simulation_tree(traces, 'car1', 1, [2], 'b', fig,x_lim,y_lim)
# # # fig,x_lim,y_lim = plot_simulation_tree(traces, 'car2', 1, [2], 'r', fig,x_lim,y_lim)
fig = plt.figure(2)
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)
plt.show()
# plt.show()
# this is for plot-based visualization
traces = scenario.simulate(40)
fig = go.Figure()
fig = plotly_simulation_anime(traces, tmp_map, fig)
fig.show()
# # this is for plot-based visualization
# traces = scenario.simulate(40)
# fig = go.Figure()
# fig = plotly_simulation_anime(traces, tmp_map, fig)
# fig.show()
......@@ -42,7 +42,7 @@ class State:
if __name__ == "__main__":
input_code_name = './example_controller4.py'
input_code_name = './demo/example_controller4.py'
scenario = Scenario()
car = CarAgent('car1', file_name=input_code_name)
......@@ -70,18 +70,18 @@ if __name__ == "__main__":
(VehicleMode.Normal, LaneMode.Lane1),
]
)
# traces = scenario.simulate(70)
traces = scenario.verify(70)
traces = scenario.simulate(70)
# traces = scenario.verify(70)
fig = plt.figure(2)
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)
plt.show()
# fig = plt.figure(2)
# 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)
# plt.show()
# fig = go.Figure()
# fig = plotly_simulation_anime(traces, tmp_map, fig)
# fig.show()
fig = go.Figure()
fig = plotly_simulation_anime(traces, tmp_map, fig)
fig.show()
......@@ -79,18 +79,18 @@ if __name__ == "__main__":
(VehicleMode.Normal, LaneMode.Lane3),
]
)
# traces = scenario.simulate(80)
traces = scenario.verify(80)
traces = scenario.simulate(80)
# traces = scenario.verify(80)
fig = plt.figure(2)
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, 'car5', 1, [2], 'r', fig)
fig = plot_reachtube_tree(traces, 'car6', 1, [2], 'r', fig)
plt.show()
# fig = plt.figure(2)
# 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, 'car5', 1, [2], 'r', fig)
# fig = plot_reachtube_tree(traces, 'car6', 1, [2], 'r', fig)
# plt.show()
# fig = go.Figure()
# fig = plotly_simulation_anime(traces, tmp_map, fig)
......
......@@ -45,7 +45,7 @@ class State:
if __name__ == "__main__":
input_code_name = './example_controller8.py'
input_code_name = './demo/example_controller8.py'
scenario = Scenario()
car = CarAgent('car1', file_name=input_code_name)
......@@ -89,17 +89,19 @@ if __name__ == "__main__":
(VehicleMode.Normal, LaneMode.Lane3),
]
)
traces = scenario.simulate(80)
# traces = scenario.verify(80)
traces = scenario.simulate(20)
# traces = scenario.verify(15)
# fig = plt.figure(2)
# 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, 'car5', 1, [2], 'r', fig)
# fig = plot_reachtube_tree(traces, 'car6', 1, [2], 'r', fig)
# fig = plot_reachtube_tree(traces, 'car1', 1, [2], 'r', fig)
# fig = plot_reachtube_tree(traces, 'car2', 1, [2], 'g', fig)
# fig = plot_reachtube_tree(traces, 'car3', 1, [2], 'g', fig)
# fig = plot_reachtube_tree(traces, 'car4', 1, [2], 'g', fig)
# fig = plot_reachtube_tree(traces, 'car5', 1, [2], 'g', fig)
# fig = plot_reachtube_tree(traces, 'car6', 1, [2], 'g', fig)
# fig = plot_reachtube_tree(traces, 'car7', 1, [2], 'g', fig)
# fig = plot_reachtube_tree(traces, 'car8', 1, [2], 'g', fig)
# plt.show()
fig = go.Figure()
......
......@@ -34,7 +34,7 @@ class Simulator:
while simulation_queue != []:
node:AnalysisTreeNode = simulation_queue.pop(0)
print(node.start_time, node.mode)
remain_time = time_horizon - node.start_time
remain_time = round(time_horizon - node.start_time,10)
if remain_time <= 0:
continue
# For trace not already simulated
......@@ -49,6 +49,10 @@ class Simulator:
transitions, transition_idx = transition_graph.get_transition_simulate_new(node)
# If there's no transitions (returned transitions is empty), continue
if not transitions:
continue
# truncate the computed trajectories from idx and store the content after truncate
truncated_trace = {}
for agent_idx in node.agent:
......
......@@ -65,8 +65,7 @@ class Verifier:
# print("here")
# TODO: Check safety conditions here
if node.trace['car1'][-1][0] > 50.01:
print("stop here")
# Get all possible transitions to next mode
all_possible_transitions = transition_graph.get_transition_verify_new(node)
max_end_idx = 0
......
......@@ -253,7 +253,10 @@ class Scenario:
tmp = tmp[1]
for var in discrete_variable_dict:
tmp = tmp.replace(var, f"'{discrete_variable_dict[var]}'")
possible_dest[i] = eval(tmp)
res = eval(tmp)
if not isinstance(res, list):
res = [res]
possible_dest[i] = res
else:
tmp = tmp[1].split('.')
if tmp[0].strip(' ') in agent.controller.modes:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment