Skip to content

Commit

Permalink
Cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
zhang-zengjie committed Apr 5, 2024
1 parent 529933f commit 9038907
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 60 deletions.
5 changes: 2 additions & 3 deletions examples/intersection/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ def main(scene):
if __name__ == "__main__":

# First of first, choose the scenario
scene = 0 # 0 for no awareness
scene = 1 # 0 for no awareness
# 1 for intention-aware
# Choose the instant of the view
step = 20 # 16: the step to show relation with the OV
step = 16 # 16: the step to show relation with the OV
# 20: the step to show relation with the pedestrian
agents = main(scene)

draw(agents, scene, step)
49 changes: 2 additions & 47 deletions examples/overtaking/draw.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
import numpy as np
from config import initialize, visualize, record, complexity, data_dir


def main(scene):

N = 15 # Control horizon

print("---------------------------------------------------------")
print('Initializing...')
print("---------------------------------------------------------")
# Initialize system and specification
agents, _ = initialize(scene, N)
# agents: the dictionary of agents
# agents['ego']: ego vehicle (EV)
# agents['oppo']: opponent vehicle (OV)

# Load the data of the ego agent
print("---------------------------------------------------------")
print('Loading data from' + data_dir)
print("---------------------------------------------------------")
agents['ego'].states = np.load(data_dir + '/xe_scene_' + str(scene) + '.npy')

return agents
from config import visualize


def draw(agents, scene):
Expand All @@ -40,27 +18,4 @@ def draw(agents, scene):
oppo.predict(0, N)
xo[j] = oppo.states

if True:
# Visualize the result
visualize(agents, xe[:, :N-1], xo[:, :, :N-1], scene)

if False:
# Record the video
record(agents, xe[:, :N-1], xo[:, :, :N-1], scene, fps=24)

if False:
# Visualize complexity analysis
complexity(data_dir)


if __name__ == "__main__":

# First of first, choose the mode
intent = 2 # Select the intent of OV:
# 0 for switching-lane
# 1 for slowing-down
# 2 for speeding-up

agents = main(intent)
draw(agents, intent)

visualize(agents, xe[:, :N-1], xo[:, :, :N-1], scene)
14 changes: 4 additions & 10 deletions examples/overtaking/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from config import initialize, data_dir
import os
from commons.pce_micp_solver import PCEMICPSolver
from draw import draw

if not os.path.exists(data_dir):
os.makedirs(data_dir)
Expand Down Expand Up @@ -60,15 +61,6 @@ def main(scene):
solver.agents['ego'].apply_control(i, u_opt)
solver.agents['oppo'].apply_control(i, solver.agents['oppo'].useq[:, i])

# Save data
np.save(data_dir + '/xe_scene_' + str(scene) + '.npy', solver.agents['ego'].states)
np.save(data_dir + '/xo_scene_' + str(scene) + '.npy', solver.agents['oppo'].pce_coefs)
np.save(data_dir + '/run_time_' + str(scene) + '.npy', runtime)

print("---------------------------------------------------------")
print('Data saved to ' + data_dir)
print("---------------------------------------------------------")

return solver.agents


Expand All @@ -79,4 +71,6 @@ def main(scene):
# 0 for switching-lane
# 1 for slowing-down
# 2 for speeding-up
main(intent)

agents = main(intent)
draw(agents, intent)

0 comments on commit 9038907

Please sign in to comment.