Path: blob/main/tools/contributed/sumopy/coremodules/simulation/simulation.py
169689 views
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo1# Copyright (C) 2016-2025 German Aerospace Center (DLR) and others.2# SUMOPy module3# Copyright (C) 2012-2021 University of Bologna - DICAM4# This program and the accompanying materials are made available under the5# terms of the Eclipse Public License 2.0 which is available at6# https://www.eclipse.org/legal/epl-2.0/7# This Source Code may also be made available under the following Secondary8# Licenses when the conditions for such availability set forth in the Eclipse9# Public License 2.0 are satisfied: GNU General Public License, version 210# or later which is available at11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1314# @file simulation.py15# @author Joerg Schweizer16# @date 2012171819import numpy as np20import agilepy.lib_base.classman as cm21import agilepy.lib_base.arrayman as am22import agilepy.lib_base.xmlman as xm23from agilepy.lib_base.misc import random_choice, get_inversemap24import results25from simplaconfig import SimplaConfig26from taxi import TaxiService272829class Simulation(cm.BaseObjman):30def __init__(self, scenario, name='Simulation',31info='Simulation, contains simulation specific parameters and methods.', **kwargs):32# print 'Network.__init__',name,kwargs33self._init_objman(ident='simulation',34parent=scenario,35name=name,36info=info,37version=0.2,38**kwargs)39attrsman = self.set_attrsman(cm.Attrsman(self))40self._init_attributes()41self._init_constants()4243def _init_attributes(self):44print 'Simulation._init_attributes id', id(self), self.parent.rootname # ,dir(self)45attrsman = self.get_attrsman()4647# if self.get_version()<0.2:48# self.delete('results')4950self.results = attrsman.add(cm.ObjConf(51results.Simresults('results', parent=self),52is_child=False,53is_save=False, # will not be saved54groups=['results']))5556# upgrade57# self.results.set_save(False)58# print ' self.results', self.results5960# load taxi services61self.taxiservice = attrsman.add(cm.ObjConf(62TaxiService(self),63is_child=True,64groups=['misc']65))6667# platooning simulation tool68self.simplaconfig = attrsman.add(cm.ObjConf(69SimplaConfig(self),70is_child=True,71groups=['misc']72))7374def _init_constants(self):75# no! for attrs onlyself.do_not_save_attrs(['results',])# redundant is_save = False76pass7778def get_scenario(self):79return self.parent8081def add_simobject(self, obj=None, ident=None, SimClass=None, **kwargs):8283if obj is not None:84ident = obj.get_ident()8586if not hasattr(self, ident):87if obj is None:88# init simobject and make it a child of simulation89obj = SimClass(ident, self, **kwargs)90is_child = True91else:92# link to simobject, which must be a child of another object93is_child = False9495attrsman = self.get_attrsman()96attrsman.add(cm.ObjConf(obj,97groupnames=['simulation objects'],98is_child=is_child,99))100101setattr(self, ident, obj)102103return getattr(self, ident)104105def get_simobjects(self):106#demandobjects = set([])107# for ident, conf in self.get_group_attrs('').iteritems():108# demandobjects.add(conf.get_value())109return self.get_attrsman().get_group_attrs('simulation objects').values()110111112