Path: blob/main/tools/contributed/sumopy/coremodules/simulation/taxi.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 taxi.py15# @author Joerg Schweizer16# @date 20121718"""19taxi service module2021In order to use taxis, the at least one vtype needs to have the taxi device22"""23import os24import sys25import numpy as np262728from agilepy.lib_base.processes import Process29#from xml.sax import saxutils, parse, handler3031import agilepy.lib_base.classman as cm32import agilepy.lib_base.arrayman as am33import agilepy.lib_base.xmlman as xm34from coremodules.demand.demandbase import DemandobjMixin353637class TaxiService(DemandobjMixin, cm.BaseObjman):38def __init__(self, simulation,39name='Taxi service',40info='Taxi service configuration. In order to use vehicles as taxis, they must have the taxi device.',41version=0.1,42**kwargs):43# print 'TaxiService.__init__'4445self._init_objman(ident='taxiservice', parent=simulation,46name=name, info=info,47version=0.1,48**kwargs)4950attrsman = self.set_attrsman(cm.Attrsman(self))51self._init_attributes()52self._init_constants()5354# make TaxiService a demand object as link55self.get_scenario().demand.add_demandobject(obj=self)5657def get_scenario(self):58return self.parent.parent5960def _init_constants(self):61self._typemap = {}62self.get_attrsman().do_not_save_attrs(['_typemap', ])6364def _init_attributes(self):65# print 'TaxiService._init_attributes',hasattr(self,'prttransit')66attrsman = self.get_attrsman()67scenario = self.get_scenario()6869self.is_enabled = attrsman.add(cm.AttrConf('is_enabled', False,70groupnames=['options'],71name='Enabled',72info="""Enable taxi services.""",73))7475self.dispatchalgorithm = attrsman.add(cm.AttrConf('dispatchalgorithm', 'greedy',76groupnames=['options'],77name='Dispatch Algorithm',78choices={'Assigns taxis to customers in the order of reservations': 'greedy',79'For each taxi assign closest customer': 'greedyClosest',80'Assigns taxis to customers in the order of reservations and pick up others on the way': 'greedyShared',81'Assigns taxis to customers in the order of reservations and make detours to pick up others': 'routeExtension',82'Algorithms managed by Traci': 'traci'},83info="Used dispatch Algorithm, see SUMO documentation.",84tag='device.taxi.dispatch-algorithm',85))8687self.period_dispatch = attrsman.add(cm.AttrConf('period_dispatch', 1.0,88groupnames=['options'],89name='Dispatch period',90info="The period between successive calls to the dispatcher.",91unit='s',92tag='device.taxi.dispatch-period',93))9495self.loss_abs = attrsman.add(cm.AttrConf('loss_abs', -1.0,96groupnames=['options'],97name='Absolute loss',98info="Absolute acceptable loss for detoures. Applies only to Dispatch Algorithm greedyShared.",99unit='s',100))101102self.loss_rel = attrsman.add(cm.AttrConf('loss_rel', -1.0,103groupnames=['options'],104name='Relative loss',105info="Relative acceptable loss for detoures. Applies only to Dispatch Algorithm greedyShared.",106))107108self.idlealgorithm = attrsman.add(cm.AttrConf('idlealgorithm', 'stop',109groupnames=['options'],110name='Idle Algorithm',111choices=['stop', 'randomCircling'],112info="Used Idle algorithm that determines the begavior when taxi has no passengers.",113tag='device.taxi.idle-algorithm',114))115116# self.is_generate_taxi = attrsman.add(cm.AttrConf( 'is_generate_taxi',kwargs.get('is_generate_taxi',False),117# groupnames = ['options'],118# perm='rw',119# name = 'Generate taxi',120# info = """Generate a certain amount of taxis on all or specific zones. Mode is taxi and all taxi vtypes should have a taxi device.""",121# ))122123# self.set_version(0.2)124125def prepare_sim(self):126pass127128def finish_sim(self):129pass130131def write_config(self, fd, ident=0):132"""133Write taxi configuration to sumo configuration file feed.134"""135print 'TaxiService.write_config is_enabled', self.is_enabled136if self.is_enabled:137attrsman = self.get_attrsman()138139fd.write(ident*' '+'<%s value="%s"/>\n' %140(attrsman.dispatchalgorithm.tag, str(attrsman.dispatchalgorithm.get_value())))141fd.write(ident*' '+'<%s value="%s"/>\n' %142(attrsman.period_dispatch.tag, str(attrsman.period_dispatch.get_value())))143144if self.dispatchalgorithm == 'greedyShared':145fd.write(ident*' '+'<%s value="%s"/>\n' % ('relLossThreshold', str(attrsman.loss_rel.get_value())))146fd.write(ident*' '+'<%s value="%s"/>\n' % ('absLossThreshold', str(attrsman.loss_abs.get_value())))147148fd.write(ident*' '+'<%s value="%s"/>\n' %149(attrsman.idlealgorithm.tag, str(attrsman.idlealgorithm.get_value())))150151152