Esempio n. 1
0
 def test_save_to_file(self):
     """ Disk IO test """
     engine = rtc.Engine(config_file=self.config_file, thread_num=4)
     self.run_steps(engine, self.period)
     engine.snapshot().dump("save.json")
     self.run_steps(engine, self.period)
     record = self.get_record(engine)
     engine.load_from_file("save.json")
     self.run_and_check(engine, record)
     del engine
Esempio n. 2
0
    def test_set_replay(self):
        """change replay path on the fly"""
        eng = rtc.Engine(config_file=self.config_file, thread_num=1)

        for _ in range(100):
            eng.next_step()

        eng.set_replay_file("replay2.txt")

        for _ in range(100):
            eng.next_step()

        del eng
Esempio n. 3
0
    def test_save_and_load_multithread(self):
        """Single save and single load with multi-threading engine"""
        engine = rtc.Engine(config_file=self.config_file, thread_num=4)

        self.run_steps(engine, self.period)
        archive = engine.snapshot()

        self.run_steps(engine, self.period)
        record0 = self.get_record(engine)

        engine.load(archive)
        self.run_and_check(engine, record0)

        del engine
Esempio n. 4
0
    def test_save_and_multi_load(self):
        """Multiple saves and multiple loads with multi-threading engine"""
        engine = rtc.Engine(config_file=self.config_file, thread_num=4)

        self.run_steps(engine, self.period)
        archive = engine.snapshot()

        self.run_steps(engine, self.period)
        record0 = self.get_record(engine)

        repeats = 2
        for i in range(repeats):
            engine.load(archive)
            self.run_and_check(engine, record0)
        del engine
Esempio n. 5
0
    def test_multi_save_and_multi_load(self):
        """ Multiple save and multiple loads with multi-threading engine") """
        engine = rtc.Engine(config_file=self.config_file, thread_num=4)
        archives, records = [], []
        repeats = 5

        for i in range(repeats + 1):
            archives.append(engine.snapshot())
            records.append(self.get_record(engine))
            self.run_steps(engine, self.period)

        for i in range(repeats):
            for j in range(repeats):
                engine.load(archives[j])
                self.run_and_check(engine, records[j + 1])

        del engine
Esempio n. 6
0
    def test_data_api(self):
        """Single save and single load with single threading engine"""
        eng = rtc.Engine(config_file=self.config_file, thread_num=1)

        for _ in range(self.period):
            eng.next_step()
            running_count = len(eng.get_vehicles())
            total_count = len(eng.get_vehicles(include_waiting=True))
            self.assertTrue(running_count <= total_count)
            self.assertTrue(running_count, eng.get_vehicle_count())
            eng.get_lane_vehicle_count()
            eng.get_lane_waiting_vehicle_count()
            eng.get_lane_vehicles()
            eng.get_vehicle_speed()
            eng.get_vehicle_distance()
            eng.get_current_time()

        del eng
Esempio n. 7
0
    def test_save_and_load(self):
        """Single save and single load with single threading engine"""
        engine = rtc.Engine(config_file=self.config_file, thread_num=1)
        self.run_steps(engine, self.period)

        start_time = time.time()
        archive = engine.snapshot()
        save_time = time.time() - start_time

        self.run_steps(engine, self.period)
        record0 = self.get_record(engine)

        start_time = time.time()
        engine.load(archive)
        load_time = time.time() - start_time

        self.run_and_check(engine, record0)

        del engine
        print("\nsave: %.4fs load: %.4fs" % (save_time, load_time))
Esempio n. 8
0
    "interval": 1.0,
    "warning": True,
    "seed": 0,
    "dir": "data/",
    "roadnetFile": "atlanta_out.json",
    "flowFile": "atlanta_flow.json",
    "rlTrafficLight": False,
    "laneChange": False,
    "saveReplay": True,
    "roadnetLogFile": "frontend/test_atlanta.json",
    "replayLogFile": "frontend/atlanta_replay.txt"
}
# config_dict["roadnetFile"] = "hangzhou_no_uturn.json"
config_path = os.path.join('data', 'config_engine.json')
with open(config_path, 'w') as config_file:
    json.dump(config_dict, config_file, indent=4)

eng = rtc.Engine(config_path, thread_num=1)

for step in range(500):
    print(step)

    # print(step,eng.get_vehicle_count())
    eng.get_vehicle_count()
    eng.get_lane_vehicle_count()
    eng.get_lane_waiting_vehicle_count()
    eng.get_current_time()
    eng.get_vehicle_speed()

    eng.next_step()
Esempio n. 9
0
import matplotlib.pyplot as plt
import DQAgent
from random import randint
from keras.utils import to_categorical

from utilities import findCollisions, plot_seaborn

MAX_INPUT_SIZE = 500
vehicles_in_step = {
}  #dictionary with all vehicles in current step. built in the following format:
#{id: {location: {}, velocity: float}}
collisions_in_step = [
]  #list with all the locations of the collisions in the step
CRUISING_SPEED = 16.67  #goal speed, where at cars are expected to drive if not slowing down to avoid collision

eng = rtc.Engine("examples/config.json", thread_num=1)

old_states = []


def isCruising(car_id, vehicles):
    return vehicles[car_id]["velocity"] == CRUISING_SPEED


def isSlow(car_id, vehicles):
    return not isCruising(car_id, vehicles)


def refreshDicts(eng):
    refreshVehicleList(eng)
    refreshCollisionList(eng)