Ejemplo n.º 1
0
    def test_initialize_container_bottleneck_001(self):
        sim_case = Simulation(self.mocks_path)
        sim_instance = Simulator(self.sim_path)
        sim_instance.register_simulation(sim_case)

        with sim_instance as s:
            while s.do_next:
                # TODO: This needs some work on Parser.py
                s.state.get_vehicle_data()
Ejemplo n.º 2
0
class TestAPI(unittest.TestCase):
    def setUp(self):
        self.get_simulator()

    def test_load_symuvia_osx(self):
        self.sim_instance = Simulator(self.sim_path)
        self.sim_instance.load_symuvia()
        self.assertEqual(self.sim_instance.libraryname, self.sim_path)

    def get_simulator(self):
        self.libpath = ("symupy", "lib", "darwin", "libSymuVia.dylib")
        self.sim_path = os.path.join(os.getcwd(), *self.libpath)
Ejemplo n.º 3
0
 def test_query_vehicles_upstream_bottleneck002(self):
     sim_case = Simulation(self.mocks_path)
     sim_instance = Simulator(self.sim_path)
     sim_instance.register_simulation(sim_case)
     with sim_instance as s:
         while s.do_next:
             s.run_step()
             if s.state.vehicle_in_network("2"):
                 nup, = s.state.vehicle_upstream("1")
                 s.stop_step()
                 continue
             else:
                 continue
     self.assertEqual(nup, "2")
Ejemplo n.º 4
0
    def test_run_stepbystep_bottleneck_001(self):
        # Using new constructor
        sim_instance = Simulator.from_path(self.mocks_path, self.sim_path)

        with sim_instance as s:
            while s.do_next:
                s.run_step()
Ejemplo n.º 5
0
    def test_drive_vehicle_bottleneck_001(self):
        sim_case = Simulation(self.mocks_path)
        sim_instance = Simulator(self.sim_path)
        sim_instance.register_simulation(sim_case)

        # with
        with sim_instance as s:
            while s.do_next:
                s.run_step()
                if s.state.vehicle_in_network("0"):
                    drive_status = s.drive_vehicle(0, 1.0)
                    s.run_step()
                    s.stop_step()
                    continue
                else:
                    continue
            self.assertEqual(drive_status, 1)
            self.assertAlmostEqual(float(sim_instance.state.query_vehicle_position("0")[0]), 1.0)
Ejemplo n.º 6
0
    def test_vehicle_in_network_bottleneck_001(self):
        sim_instance = Simulator.from_path(self.mocks_path, self.sim_path)
        flag = False
        with sim_instance as s:
            while s.do_next:
                s.run_step()
                if s.state.vehicle_in_network("0"):
                    flag = True

        self.assertTrue(flag)
Ejemplo n.º 7
0
    def test_create_drive_vehicle_bottleneck_001(self):
        sim_case = Simulation(self.mocks_path)
        sim_instance = Simulator(self.sim_path)
        sim_instance.register_simulation(sim_case)

        # with
        # REVIEW: For the sake of simplicity the vehicle will be created after an entering vehicle has been created.
        with sim_instance as s:
            while s.do_next:
                s.request_answer()  # Initialize
                s.request_answer()  # Vehicle 0
                veh_id = s.create_vehicle("VL", "Ext_In", "Ext_Out")
                s.request_answer()  # Vehicle instantiation
                drive_status = s.drive_vehicle(veh_id, 20.0, "Zone_001")
                s.stop_step()

        self.assertGreaterEqual(veh_id, 0)
        self.assertEqual(drive_status, 1)
        self.assertAlmostEqual(float(sim_instance.state.query_vehicle_position("1")[0]), 20.0)
Ejemplo n.º 8
0
    def test_vehicle_in_network_bottleneck_002(self):
        sim_instance = Simulator.from_path(self.mocks_path, self.sim_path)

        flag0, flag1, flag2 = False, False, False
        with sim_instance as s:
            while s.do_next:
                s.run_step()
                if s.state.vehicle_in_network("0", "1"):
                    flag0 = True
                if s.state.vehicle_in_network("1"):
                    flag1 = True
                if s.state.vehicle_in_network("2"):
                    flag2 = True
        self.assertTrue(flag0)
        self.assertTrue(flag1)
        self.assertTrue(flag2)
Ejemplo n.º 9
0
    def test_create_rsu_bottleneck_002(self):
        sim_instance = Simulator.from_path(self.mocks_path, self.sim_path)

        rsu = RoadSideUnit("Zone_001", 0.0)
        v2i_net = V2INetwork()
        v2i_net.register_element(rsu)

        sim_instance.register_network(v2i_net)

        with sim_instance as s:
            while s.do_next:
                s.run_step()
                if s.state.vehicle_in_network("0"):
                    s.state.update_vehicle_list()
                if s.state.vehicle_in_network("1"):
                    s.state.update_vehicle_list()
                if s.state.vehicle_in_network("2"):
                    s.state.update_vehicle_list()
        x = 2
        self.assertEqual(self.mocks_path, sim_instance.casename)
Ejemplo n.º 10
0
    def test_create_rsu_bottleneck_001(self):
        sim_instance = Simulator.from_path(self.mocks_path, self.sim_path)

        rsu = RoadSideUnit("Zone_001", 0.0)
        v2i_net = V2INetwork()
        v2i_net.register_element(rsu)

        sim_instance.register_network(v2i_net)

        with sim_instance as s:
            while s.do_next:
                s.run_step()
                if s.state.vehicle_in_network("0"):
                    s.state.create_vehicle_list()
                    x = 1
                    # v = Vehicle("0")
                    # v.plug_vehicle_to_sim(s)
                    # s.log_vehicle_in_network(v, v2i_net)
                    ## TODO: To finish
        x = 2
        self.assertEqual(self.mocks_path, sim_instance.casename)
Ejemplo n.º 11
0
 def test_run_simulation_alternative_constructor_bottleneck_001(self):
     sim_instance = Simulator.from_path(self.mocks_path, self.sim_path)
     sim_instance.run_simulation()
Ejemplo n.º 12
0
 def test_load_symuvia_osx(self):
     self.sim_instance = Simulator(self.sim_path)
     self.sim_instance.load_symuvia()
     self.assertEqual(self.sim_instance.libraryname, self.sim_path)
Ejemplo n.º 13
0
 def test_run_bottleneck_001(self):
     sim_case = Simulation(self.mocks_path)
     sim_instance = Simulator(self.sim_path)
     sim_instance.load_symuvia()
     sim_instance.run_simulation(sim_case)
Ejemplo n.º 14
0
 def test_constructor_bottleneck_001(self):
     sim_instance = Simulator.from_path(self.mocks_path, self.sim_path)
     self.assertEqual(self.mocks_path, sim_instance.casename)
Ejemplo n.º 15
0
 def test_fixed_leader_neighbors_bottleneck002(self):
     sim_case = Simulation(self.mocks_path)
     sim_instance = Simulator(self.sim_path)
     sim_instance.register_simulation(sim_case)
     pass
Ejemplo n.º 16
0
 def test_query_vehicle_neighbors_bottleneck002(self):
     sim_case = Simulation(self.mocks_path)
     sim_instance = Simulator(self.sim_path)
     sim_instance.register_simulation(sim_case)
     pass
Ejemplo n.º 17
0
    def test_create_vehicle_bottleneck_001(self):
        sim_case = Simulation(self.mocks_path)
        sim_instance = Simulator(self.sim_path)
        sim_instance.register_simulation(sim_case)

        # with
        sim_instance.load_symuvia()
        sim_instance.load_network()
        sim_instance.init_simulation()
        veh_id = sim_instance.create_vehicle("VL", "Ext_In", "Ext_Out")
        self.assertGreaterEqual(veh_id, 0)