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__": ...@@ -54,22 +54,17 @@ if __name__ == "__main__":
(VehicleMode.Normal, LaneMode.Lane1), (VehicleMode.Normal, LaneMode.Lane1),
] ]
) )
# # res_list = scenario.simulate_multi(40,1) # res_list = scenario.simulate(40)
# traces = scenario.verify(40) traces = scenario.verify(40)
# fig = plt.figure(2) fig = plt.figure(2)
# fig = plot_map(tmp_map, 'g', fig) fig = plot_map(tmp_map, 'g', fig)
# fig = plot_reachtube_tree(traces, 'car1', 1, [2], 'b', 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, 'car2', 1, [2], 'r', fig)
# # for traces in res_list: plt.show()
# # 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)
# plt.show() # # this is for plot-based visualization
# traces = scenario.simulate(40)
# this is for plot-based visualization # fig = go.Figure()
traces = scenario.simulate(40) # fig = plotly_simulation_anime(traces, tmp_map, fig)
fig = go.Figure() # fig.show()
fig = plotly_simulation_anime(traces, tmp_map, fig)
fig.show()
...@@ -42,7 +42,7 @@ class State: ...@@ -42,7 +42,7 @@ class State:
if __name__ == "__main__": if __name__ == "__main__":
input_code_name = './example_controller4.py' input_code_name = './demo/example_controller4.py'
scenario = Scenario() scenario = Scenario()
car = CarAgent('car1', file_name=input_code_name) car = CarAgent('car1', file_name=input_code_name)
...@@ -70,18 +70,18 @@ if __name__ == "__main__": ...@@ -70,18 +70,18 @@ if __name__ == "__main__":
(VehicleMode.Normal, LaneMode.Lane1), (VehicleMode.Normal, LaneMode.Lane1),
] ]
) )
# traces = scenario.simulate(70) traces = scenario.simulate(70)
traces = scenario.verify(70) # traces = scenario.verify(70)
fig = plt.figure(2) # fig = plt.figure(2)
fig = plot_map(tmp_map, 'g', fig) # fig = plot_map(tmp_map, 'g', fig)
fig = plot_reachtube_tree(traces, 'car1', 1, [2], 'b', 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, 'car2', 1, [2], 'r', fig)
fig = plot_reachtube_tree(traces, 'car3', 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, 'car4', 1, [2], 'r', fig)
plt.show() # plt.show()
# fig = go.Figure() fig = go.Figure()
# fig = plotly_simulation_anime(traces, tmp_map, fig) fig = plotly_simulation_anime(traces, tmp_map, fig)
# fig.show() fig.show()
...@@ -79,18 +79,18 @@ if __name__ == "__main__": ...@@ -79,18 +79,18 @@ if __name__ == "__main__":
(VehicleMode.Normal, LaneMode.Lane3), (VehicleMode.Normal, LaneMode.Lane3),
] ]
) )
# traces = scenario.simulate(80) traces = scenario.simulate(80)
traces = scenario.verify(80) # traces = scenario.verify(80)
fig = plt.figure(2) # fig = plt.figure(2)
fig = plot_map(tmp_map, 'g', fig) # fig = plot_map(tmp_map, 'g', fig)
fig = plot_reachtube_tree(traces, 'car1', 1, [2], 'b', 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, 'car2', 1, [2], 'r', fig)
fig = plot_reachtube_tree(traces, 'car3', 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, 'car4', 1, [2], 'r', fig)
fig = plot_reachtube_tree(traces, 'car5', 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, 'car6', 1, [2], 'r', fig)
plt.show() # plt.show()
# fig = go.Figure() # fig = go.Figure()
# fig = plotly_simulation_anime(traces, tmp_map, fig) # fig = plotly_simulation_anime(traces, tmp_map, fig)
......
...@@ -45,7 +45,7 @@ class State: ...@@ -45,7 +45,7 @@ class State:
if __name__ == "__main__": if __name__ == "__main__":
input_code_name = './example_controller8.py' input_code_name = './demo/example_controller8.py'
scenario = Scenario() scenario = Scenario()
car = CarAgent('car1', file_name=input_code_name) car = CarAgent('car1', file_name=input_code_name)
...@@ -89,17 +89,19 @@ if __name__ == "__main__": ...@@ -89,17 +89,19 @@ if __name__ == "__main__":
(VehicleMode.Normal, LaneMode.Lane3), (VehicleMode.Normal, LaneMode.Lane3),
] ]
) )
traces = scenario.simulate(80) traces = scenario.simulate(20)
# traces = scenario.verify(80) # traces = scenario.verify(15)
# fig = plt.figure(2) # fig = plt.figure(2)
# fig = plot_map(tmp_map, 'g', fig) # fig = plot_map(tmp_map, 'g', fig)
# fig = plot_reachtube_tree(traces, 'car1', 1, [2], 'b', fig) # fig = plot_reachtube_tree(traces, 'car1', 1, [2], 'r', fig)
# fig = plot_reachtube_tree(traces, 'car2', 1, [2], 'r', fig) # fig = plot_reachtube_tree(traces, 'car2', 1, [2], 'g', fig)
# fig = plot_reachtube_tree(traces, 'car3', 1, [2], 'r', fig) # fig = plot_reachtube_tree(traces, 'car3', 1, [2], 'g', fig)
# fig = plot_reachtube_tree(traces, 'car4', 1, [2], 'r', fig) # fig = plot_reachtube_tree(traces, 'car4', 1, [2], 'g', fig)
# fig = plot_reachtube_tree(traces, 'car5', 1, [2], 'r', fig) # fig = plot_reachtube_tree(traces, 'car5', 1, [2], 'g', fig)
# fig = plot_reachtube_tree(traces, 'car6', 1, [2], 'r', 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() # plt.show()
fig = go.Figure() fig = go.Figure()
......
...@@ -34,7 +34,7 @@ class Simulator: ...@@ -34,7 +34,7 @@ class Simulator:
while simulation_queue != []: while simulation_queue != []:
node:AnalysisTreeNode = simulation_queue.pop(0) node:AnalysisTreeNode = simulation_queue.pop(0)
print(node.start_time, node.mode) 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: if remain_time <= 0:
continue continue
# For trace not already simulated # For trace not already simulated
...@@ -49,6 +49,10 @@ class Simulator: ...@@ -49,6 +49,10 @@ class Simulator:
transitions, transition_idx = transition_graph.get_transition_simulate_new(node) 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 # truncate the computed trajectories from idx and store the content after truncate
truncated_trace = {} truncated_trace = {}
for agent_idx in node.agent: for agent_idx in node.agent:
......
...@@ -65,8 +65,7 @@ class Verifier: ...@@ -65,8 +65,7 @@ class Verifier:
# print("here") # print("here")
# TODO: Check safety conditions here # TODO: Check safety conditions here
if node.trace['car1'][-1][0] > 50.01:
print("stop here")
# Get all possible transitions to next mode # Get all possible transitions to next mode
all_possible_transitions = transition_graph.get_transition_verify_new(node) all_possible_transitions = transition_graph.get_transition_verify_new(node)
max_end_idx = 0 max_end_idx = 0
......
...@@ -253,7 +253,10 @@ class Scenario: ...@@ -253,7 +253,10 @@ class Scenario:
tmp = tmp[1] tmp = tmp[1]
for var in discrete_variable_dict: for var in discrete_variable_dict:
tmp = tmp.replace(var, f"'{discrete_variable_dict[var]}'") 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: else:
tmp = tmp[1].split('.') tmp = tmp[1].split('.')
if tmp[0].strip(' ') in agent.controller.modes: 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