Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/tutorial/city_mobil/data/simpleManager.py
169708 views
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
4
# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.
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 simpleManager.py
16
# @author Michael Behrisch
17
# @author Daniel Krajzewicz
18
# @date 2008-10-09
19
20
from __future__ import absolute_import
21
import vehicleControl
22
import statistics
23
from constants import DOUBLE_ROWS, WAIT_PER_PERSON
24
25
26
class SimpleManager(vehicleControl.Manager):
27
28
def __init__(self):
29
self.cyberCarLoad = {}
30
self.personsWaitingAt = {}
31
32
def personArrived(self, personID, edge, target):
33
if edge not in self.personsWaitingAt:
34
self.personsWaitingAt[edge] = []
35
self.personsWaitingAt[edge].append((personID, target))
36
37
def cyberCarArrived(self, vehicleID, edge):
38
step = vehicleControl.getStep()
39
footEdge = edge.replace("cyber", "footmain")
40
wait = 0
41
load = []
42
for person, target in self.cyberCarLoad.get(vehicleID, []):
43
if target == footEdge:
44
statistics.personUnloaded(person, step)
45
wait += WAIT_PER_PERSON
46
else:
47
load.append((person, target))
48
while self.personsWaitingAt.get(footEdge, []) and len(load) < vehicleControl.getCapacity():
49
person, target = self.personsWaitingAt[footEdge].pop(0)
50
vehicleControl.leaveStop(person)
51
statistics.personLoaded(person, step)
52
load.append((person, target))
53
wait += WAIT_PER_PERSON
54
vehicleControl.leaveStop(vehicleID, delay=wait)
55
if edge == "cyberout" or edge == "cyberin":
56
row = -1
57
else:
58
row = int(edge[5])
59
if row < DOUBLE_ROWS - 1:
60
vehicleControl.stopAt(
61
vehicleID, "cyber%sto%s" % (row + 1, row + 2))
62
else:
63
vehicleControl.stopAt(vehicleID, "cyberout")
64
self.cyberCarLoad[vehicleID] = load
65
66
67
if __name__ == "__main__":
68
vehicleControl.init(SimpleManager())
69
70