def test_find(self):
        """Tests the find_by_name and find_all_by_type functions"""
        class TestGUISystem(TestGUISystemBase):
            pass

        test_gui_system = TestGUISystem()
        model = AimsunTemplate(GKSystem=None, GKGUISystem=test_gui_system)

        objects = [
            TestObject('Cat', 'Animal'),
            TestObject('Squirrel', 'Animal'),
            TestObject('Bach', 'Musician'),
            TestObject('Husky', 'Animal'),
            TestObject('Mozart', 'Musician')
        ]

        search1 = model.find_by_name(objects, 'Husky')
        self.assertEqual(search1.name, 'Husky')
        self.assertEqual(search1.type_name, 'Animal')

        search2 = model.find_all_by_type(objects, 'Musician')
        self.assertEqual([x.name for x in search2], ['Bach', 'Mozart'])
        self.assertEqual(set([x.type_name for x in search2]), {'Musician'})
Пример #2
0
os.remove(file_path)

# open template in Aimsun
print('[load.py] Loading template ' + template_path)
model = AimsunTemplate(GKSystem, GKGUISystem)
model.load(template_path)

# collect the simulation parameters
params_file = 'flow/core/kernel/scenario/data.json'
params_path = os.path.join(config.PROJECT_PATH, params_file)
with open(params_path) as f:
    data = json.load(f)

# retrieve replication by name
replication_name = data['replication_name']
replication = model.find_by_name(model.replications, replication_name)

if replication is None:
    print('[load.py] ERROR: Replication ' + replication_name +
          ' does not exist.')

# retrieve experiment and scenario
experiment = replication.experiment
scenario = experiment.scenario
scenario_data = scenario.input_data
scenario_data.add_extension(
    os.path.join(config.PROJECT_PATH, 'flow/utils/aimsun/run.py'), True)

# if subnetwork_name was specified in the Aimsun params,
# try to only load subnetwork; it not specified or if
# subnetwork is not found, load the whole network