Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/sumopy/coremodules/simulation/simulation.py
169689 views
1
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
2
# Copyright (C) 2016-2025 German Aerospace Center (DLR) and others.
3
# SUMOPy module
4
# Copyright (C) 2012-2021 University of Bologna - DICAM
5
# This program and the accompanying materials are made available under the
6
# terms of the Eclipse Public License 2.0 which is available at
7
# https://www.eclipse.org/legal/epl-2.0/
8
# This Source Code may also be made available under the following Secondary
9
# Licenses when the conditions for such availability set forth in the Eclipse
10
# Public License 2.0 are satisfied: GNU General Public License, version 2
11
# or later which is available at
12
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
13
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
14
15
# @file simulation.py
16
# @author Joerg Schweizer
17
# @date 2012
18
19
20
import numpy as np
21
import agilepy.lib_base.classman as cm
22
import agilepy.lib_base.arrayman as am
23
import agilepy.lib_base.xmlman as xm
24
from agilepy.lib_base.misc import random_choice, get_inversemap
25
import results
26
from simplaconfig import SimplaConfig
27
from taxi import TaxiService
28
29
30
class Simulation(cm.BaseObjman):
31
def __init__(self, scenario, name='Simulation',
32
info='Simulation, contains simulation specific parameters and methods.', **kwargs):
33
# print 'Network.__init__',name,kwargs
34
self._init_objman(ident='simulation',
35
parent=scenario,
36
name=name,
37
info=info,
38
version=0.2,
39
**kwargs)
40
attrsman = self.set_attrsman(cm.Attrsman(self))
41
self._init_attributes()
42
self._init_constants()
43
44
def _init_attributes(self):
45
print 'Simulation._init_attributes id', id(self), self.parent.rootname # ,dir(self)
46
attrsman = self.get_attrsman()
47
48
# if self.get_version()<0.2:
49
# self.delete('results')
50
51
self.results = attrsman.add(cm.ObjConf(
52
results.Simresults('results', parent=self),
53
is_child=False,
54
is_save=False, # will not be saved
55
groups=['results']))
56
57
# upgrade
58
# self.results.set_save(False)
59
# print ' self.results', self.results
60
61
# load taxi services
62
self.taxiservice = attrsman.add(cm.ObjConf(
63
TaxiService(self),
64
is_child=True,
65
groups=['misc']
66
))
67
68
# platooning simulation tool
69
self.simplaconfig = attrsman.add(cm.ObjConf(
70
SimplaConfig(self),
71
is_child=True,
72
groups=['misc']
73
))
74
75
def _init_constants(self):
76
# no! for attrs onlyself.do_not_save_attrs(['results',])# redundant is_save = False
77
pass
78
79
def get_scenario(self):
80
return self.parent
81
82
def add_simobject(self, obj=None, ident=None, SimClass=None, **kwargs):
83
84
if obj is not None:
85
ident = obj.get_ident()
86
87
if not hasattr(self, ident):
88
if obj is None:
89
# init simobject and make it a child of simulation
90
obj = SimClass(ident, self, **kwargs)
91
is_child = True
92
else:
93
# link to simobject, which must be a child of another object
94
is_child = False
95
96
attrsman = self.get_attrsman()
97
attrsman.add(cm.ObjConf(obj,
98
groupnames=['simulation objects'],
99
is_child=is_child,
100
))
101
102
setattr(self, ident, obj)
103
104
return getattr(self, ident)
105
106
def get_simobjects(self):
107
#demandobjects = set([])
108
# for ident, conf in self.get_group_attrs('').iteritems():
109
# demandobjects.add(conf.get_value())
110
return self.get_attrsman().get_group_attrs('simulation objects').values()
111
112