Path: blob/main/tests/complex/traci/bugs/ticket2777/runner.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 runner.py15# @author Michael Behrisch16# @author Jakob Erdmann17# @author Daniel Krajzewicz18# @date 2011-03-04192021from __future__ import print_function22from __future__ import absolute_import23import os24import sys25if 'SUMO_HOME' in os.environ:26sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))27import traci # noqa28import sumolib # noqa293031def check(vehID, steps=1):32for i in range(steps):33if i > 0:34traci.simulationStep()35try:36print("%s vehicle %s on lane=%s pos=%s speed=%s" % (37traci.simulation.getTime(),38vehID,39traci.vehicle.getLaneID(vehID),40traci.vehicle.getLanePosition(vehID),41traci.vehicle.getSpeed(vehID)))42except traci.TraCIException:43pass44if steps > 1:45print()464748vehID = "v0"49traci.start([sumolib.checkBinary("sumo"), '-c', 'sumo.sumocfg'])50traci.simulationStep()51check(vehID)52try:53print("%s setStop for %s" % (traci.simulation.getTime(), vehID))54traci.vehicle.setStop(vehID, "beg", pos=1.0, laneIndex=0, duration=5)55except traci.TraCIException:56pass57check(vehID, 10)5859traci.simulationStep(21)60vehID = "v1"61check(vehID)62try:63print("%s setStop for %s" % (traci.simulation.getTime(), vehID))64traci.vehicle.setStop(vehID, "end", pos=1.0, laneIndex=0, duration=5)65except traci.TraCIException:66pass67check(vehID, 10)6869traci.simulationStep(41)70vehID = "v2"71check(vehID)72try:73print("%s setStop for %s" % (traci.simulation.getTime(), vehID))74traci.vehicle.setStop(vehID, "middle", pos=1.0, laneIndex=0, duration=5)75except traci.TraCIException:76pass77check(vehID, 10)7879traci.simulationStep(61)80vehID = "v3"81check(vehID)82try:83print("%s setStop for %s" % (traci.simulation.getTime(), vehID))84traci.vehicle.setStop(vehID, "middle", pos=1.0, laneIndex=0, duration=5)85except traci.TraCIException:86pass87check(vehID, 10)8889traci.close()909192