Path: blob/main/tests/complex/tutorial/city_mobil/data/simpleManager.py
169708 views
#!/usr/bin/env python1# -*- coding: utf-8 -*-2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo3# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.4# 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 simpleManager.py15# @author Michael Behrisch16# @author Daniel Krajzewicz17# @date 2008-10-091819from __future__ import absolute_import20import vehicleControl21import statistics22from constants import DOUBLE_ROWS, WAIT_PER_PERSON232425class SimpleManager(vehicleControl.Manager):2627def __init__(self):28self.cyberCarLoad = {}29self.personsWaitingAt = {}3031def personArrived(self, personID, edge, target):32if edge not in self.personsWaitingAt:33self.personsWaitingAt[edge] = []34self.personsWaitingAt[edge].append((personID, target))3536def cyberCarArrived(self, vehicleID, edge):37step = vehicleControl.getStep()38footEdge = edge.replace("cyber", "footmain")39wait = 040load = []41for person, target in self.cyberCarLoad.get(vehicleID, []):42if target == footEdge:43statistics.personUnloaded(person, step)44wait += WAIT_PER_PERSON45else:46load.append((person, target))47while self.personsWaitingAt.get(footEdge, []) and len(load) < vehicleControl.getCapacity():48person, target = self.personsWaitingAt[footEdge].pop(0)49vehicleControl.leaveStop(person)50statistics.personLoaded(person, step)51load.append((person, target))52wait += WAIT_PER_PERSON53vehicleControl.leaveStop(vehicleID, delay=wait)54if edge == "cyberout" or edge == "cyberin":55row = -156else:57row = int(edge[5])58if row < DOUBLE_ROWS - 1:59vehicleControl.stopAt(60vehicleID, "cyber%sto%s" % (row + 1, row + 2))61else:62vehicleControl.stopAt(vehicleID, "cyberout")63self.cyberCarLoad[vehicleID] = load646566if __name__ == "__main__":67vehicleControl.init(SimpleManager())686970