Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/sumopy/coremodules/simulation/taxi.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 taxi.py
16
# @author Joerg Schweizer
17
# @date 2012
18
19
"""
20
taxi service module
21
22
In order to use taxis, the at least one vtype needs to have the taxi device
23
"""
24
import os
25
import sys
26
import numpy as np
27
28
29
from agilepy.lib_base.processes import Process
30
#from xml.sax import saxutils, parse, handler
31
32
import agilepy.lib_base.classman as cm
33
import agilepy.lib_base.arrayman as am
34
import agilepy.lib_base.xmlman as xm
35
from coremodules.demand.demandbase import DemandobjMixin
36
37
38
class TaxiService(DemandobjMixin, cm.BaseObjman):
39
def __init__(self, simulation,
40
name='Taxi service',
41
info='Taxi service configuration. In order to use vehicles as taxis, they must have the taxi device.',
42
version=0.1,
43
**kwargs):
44
# print 'TaxiService.__init__'
45
46
self._init_objman(ident='taxiservice', parent=simulation,
47
name=name, info=info,
48
version=0.1,
49
**kwargs)
50
51
attrsman = self.set_attrsman(cm.Attrsman(self))
52
self._init_attributes()
53
self._init_constants()
54
55
# make TaxiService a demand object as link
56
self.get_scenario().demand.add_demandobject(obj=self)
57
58
def get_scenario(self):
59
return self.parent.parent
60
61
def _init_constants(self):
62
self._typemap = {}
63
self.get_attrsman().do_not_save_attrs(['_typemap', ])
64
65
def _init_attributes(self):
66
# print 'TaxiService._init_attributes',hasattr(self,'prttransit')
67
attrsman = self.get_attrsman()
68
scenario = self.get_scenario()
69
70
self.is_enabled = attrsman.add(cm.AttrConf('is_enabled', False,
71
groupnames=['options'],
72
name='Enabled',
73
info="""Enable taxi services.""",
74
))
75
76
self.dispatchalgorithm = attrsman.add(cm.AttrConf('dispatchalgorithm', 'greedy',
77
groupnames=['options'],
78
name='Dispatch Algorithm',
79
choices={'Assigns taxis to customers in the order of reservations': 'greedy',
80
'For each taxi assign closest customer': 'greedyClosest',
81
'Assigns taxis to customers in the order of reservations and pick up others on the way': 'greedyShared',
82
'Assigns taxis to customers in the order of reservations and make detours to pick up others': 'routeExtension',
83
'Algorithms managed by Traci': 'traci'},
84
info="Used dispatch Algorithm, see SUMO documentation.",
85
tag='device.taxi.dispatch-algorithm',
86
))
87
88
self.period_dispatch = attrsman.add(cm.AttrConf('period_dispatch', 1.0,
89
groupnames=['options'],
90
name='Dispatch period',
91
info="The period between successive calls to the dispatcher.",
92
unit='s',
93
tag='device.taxi.dispatch-period',
94
))
95
96
self.loss_abs = attrsman.add(cm.AttrConf('loss_abs', -1.0,
97
groupnames=['options'],
98
name='Absolute loss',
99
info="Absolute acceptable loss for detoures. Applies only to Dispatch Algorithm greedyShared.",
100
unit='s',
101
))
102
103
self.loss_rel = attrsman.add(cm.AttrConf('loss_rel', -1.0,
104
groupnames=['options'],
105
name='Relative loss',
106
info="Relative acceptable loss for detoures. Applies only to Dispatch Algorithm greedyShared.",
107
))
108
109
self.idlealgorithm = attrsman.add(cm.AttrConf('idlealgorithm', 'stop',
110
groupnames=['options'],
111
name='Idle Algorithm',
112
choices=['stop', 'randomCircling'],
113
info="Used Idle algorithm that determines the begavior when taxi has no passengers.",
114
tag='device.taxi.idle-algorithm',
115
))
116
117
# self.is_generate_taxi = attrsman.add(cm.AttrConf( 'is_generate_taxi',kwargs.get('is_generate_taxi',False),
118
# groupnames = ['options'],
119
# perm='rw',
120
# name = 'Generate taxi',
121
# info = """Generate a certain amount of taxis on all or specific zones. Mode is taxi and all taxi vtypes should have a taxi device.""",
122
# ))
123
124
# self.set_version(0.2)
125
126
def prepare_sim(self):
127
pass
128
129
def finish_sim(self):
130
pass
131
132
def write_config(self, fd, ident=0):
133
"""
134
Write taxi configuration to sumo configuration file feed.
135
"""
136
print 'TaxiService.write_config is_enabled', self.is_enabled
137
if self.is_enabled:
138
attrsman = self.get_attrsman()
139
140
fd.write(ident*' '+'<%s value="%s"/>\n' %
141
(attrsman.dispatchalgorithm.tag, str(attrsman.dispatchalgorithm.get_value())))
142
fd.write(ident*' '+'<%s value="%s"/>\n' %
143
(attrsman.period_dispatch.tag, str(attrsman.period_dispatch.get_value())))
144
145
if self.dispatchalgorithm == 'greedyShared':
146
fd.write(ident*' '+'<%s value="%s"/>\n' % ('relLossThreshold', str(attrsman.loss_rel.get_value())))
147
fd.write(ident*' '+'<%s value="%s"/>\n' % ('absLossThreshold', str(attrsman.loss_abs.get_value())))
148
149
fd.write(ident*' '+'<%s value="%s"/>\n' %
150
(attrsman.idlealgorithm.tag, str(attrsman.idlealgorithm.get_value())))
151
152