# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
# %load_ext autoreload
# %autoreload 2
# %matplotlib inline
import sys, os, pickle
# sys.path.append('/home/noambuckman/traffic_simulations/src')
sys.path.append('/Users/noambuckman/git-repos/traffic_simulations/src/')
# import simulator as sim
# import kinematics as kn
# import numpy as np
# import matplotlib.pyplot as plt, matplotlib.colors as colors, matplotlib.cm as cmx
# import bisect,itertools
# import time,copy
# # import ipyparallel as ipp
# import itertools
# import random as rand
import TrafficSimulator as ts
import TrafficCoordinator as tc

# import AutonomousVehicle as AV
# import queue as queue
# import pickle as pickle
# # rand.seed(30)
# import cProfile
# -

# # Generating Simulations

experiment_name = "all_cars_h0_ego"

results_directory = '/Users/noambuckman/git-repos/traffic_simulations/results/'
if not os.path.exists(results_directory):
    os.makedirs(results_directory)

all_cars_simulations_list = pickle.load(open(results_directory+experiment_name+".p",'rb'))
all_experiment_results = []
for i_sim in range(len(all_cars_simulations_list)):
    print("Simulation # %d \n "%i_sim)
    
    all_cars = all_cars_simulations_list[i_sim]
    
    #######
    traffic_simulator = ts.TrafficSimulator()
    traffic_simulator.deltaT = 0.05
    traffic_simulator.batch = True
    traffic_simulator.initialize_map(10,10,4,0.1)
    traffic_simulator.coordinator = tc.BatchTrafficCoordinatorNew()
    traffic_simulator.coordinator.bid_tax = 0
    #############IMPORTANT PARAMATERS
    traffic_simulator.time_for_next_car = -1
    traffic_simulator.coordinator.k_batch_intervals_time = 4.0 #s
    traffic_simulator.coordinator.k_replan_increment_sec = 0.5 #s
    traffic_simulator.coordinator.k_max_retries = 60
    traffic_simulator.coordinator.k_min_number_cars_without_reservations = 4
    
    
    ##### Experiment
    traffic_simulator.coordinator.strict_priority = True
    traffic_simulator.coordinator.swaps_allowed = False
    
    
    print("Strict Priority + No Swaps")
    sim1_results = ts.run_sim_experiments(traffic_simulator, all_cars)
    
    
    #######
    traffic_simulator = ts.TrafficSimulator()
    traffic_simulator.deltaT = 0.05
    traffic_simulator.batch = True
    traffic_simulator.initialize_map(10,10,4,0.1)
    traffic_simulator.coordinator = tc.BatchTrafficCoordinatorNew()
    traffic_simulator.coordinator.bid_tax = 0
    #############IMPORTANT PARAMATERS
    traffic_simulator.time_for_next_car = -1
    traffic_simulator.coordinator.k_batch_intervals_time = 4.0 #s
    traffic_simulator.coordinator.k_replan_increment_sec = 0.5 #s
    traffic_simulator.coordinator.k_max_retries = 60
    traffic_simulator.coordinator.k_min_number_cars_without_reservations = 4
    
    
    
    ##### Experiment
    traffic_simulator.coordinator.strict_priority = True
    traffic_simulator.coordinator.swaps_allowed = True    
    
    print("Strict Priority + Swaps")

    sim2_results = ts.run_sim_experiments(traffic_simulator, all_cars)
    

    
    
    #######
    traffic_simulator = ts.TrafficSimulator()
    traffic_simulator.deltaT = 0.05
    traffic_simulator.batch = True
    traffic_simulator.initialize_map(10,10,4,0.1)
    traffic_simulator.coordinator = tc.BatchTrafficCoordinatorNew()
    traffic_simulator.coordinator.bid_tax = 0
    #############IMPORTANT PARAMATERS
    traffic_simulator.time_for_next_car = -1
    traffic_simulator.coordinator.k_batch_intervals_time = 4.0 #s
    traffic_simulator.coordinator.k_replan_increment_sec = 0.5 #s
    traffic_simulator.coordinator.k_max_retries = 60
    traffic_simulator.coordinator.k_min_number_cars_without_reservations = 4

    
    
    ##### Experiment
    traffic_simulator.coordinator.strict_priority = False
    traffic_simulator.coordinator.swaps_allowed = False
    
    print("Relaxed Priority + No Swaps")

    sim3_results = ts.run_sim_experiments(traffic_simulator, all_cars)
    

    
    

    
    
    
    
    #######
    traffic_simulator = ts.TrafficSimulator()
    traffic_simulator.deltaT = 0.05
    traffic_simulator.batch = True
    traffic_simulator.initialize_map(10,10,4,0.1)
    traffic_simulator.coordinator = tc.BatchTrafficCoordinatorNew()
    traffic_simulator.coordinator.bid_tax = 0
    #############IMPORTANT PARAMATERS
    traffic_simulator.time_for_next_car = -1
    traffic_simulator.coordinator.k_batch_intervals_time = 4.0 #s
    traffic_simulator.coordinator.k_replan_increment_sec = 0.5 #s
    traffic_simulator.coordinator.k_max_retries = 60
    traffic_simulator.coordinator.k_min_number_cars_without_reservations = 4
    
    
    print("Relaxed Priority + Swaps")

    ##### Experiment
    traffic_simulator.coordinator.strict_priority = False
    traffic_simulator.coordinator.swaps_allowed = True    
    
    sim4_results = ts.run_sim_experiments(traffic_simulator, all_cars)
    
    this_sim_results = [sim1_results,sim2_results,sim3_results,sim4_results]
    all_experiment_results += [this_sim_results]

pickle.dump(all_experiment_results,open(results_directory+experiment_name+'_results.p','wb'))

print("DONE AND SAVED!")



StarcoderdataJupyterScriptsDedupFiltered