Path: blob/main/tests/complex/traci/lanearea/override/runner.py
169689 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 Daniel Krajzewicz17# @date 2011-03-04181920from __future__ import print_function21from __future__ import absolute_import22import os23import sys2425if "SUMO_HOME" in os.environ:26sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))27import traci # noqa28import sumolib # noqa2930traci.start([sumolib.checkBinary('sumo'), "-c", "sumo.sumocfg"] + sys.argv[1:])3132loopID = "detect_0"333435def check():36t = traci.simulation.getTime()37print("step", t)38if int(t) == t:39# only report at full seconds to simplify comparison of different step-lengths40for detID in traci.lanearea.getIDList():41print(" examining", detID)42print(" pos", traci.lanearea.getPosition(detID))43print(" length", traci.lanearea.getLength(detID))44print(" lane", traci.lanearea.getLaneID(detID))45print(" vehNum", traci.lanearea.getLastStepVehicleNumber(detID))46print(" haltNum", traci.lanearea.getLastStepHaltingNumber(detID))47print(" meanSpeed", traci.lanearea.getLastStepMeanSpeed(detID))48print(" vehIDs", traci.lanearea.getLastStepVehicleIDs(detID))49print(" occupancy", traci.lanearea.getLastStepOccupancy(detID))50print(" jamLengthVeh", traci.lanearea.getJamLengthVehicle(detID))51print(" jamLengthMet", traci.lanearea.getJamLengthMeters(detID))525354def ovr(vehNumber):55print("override %s" % vehNumber)56traci.lanearea.overrideVehicleNumber(loopID, vehNumber)575859for step in range(3):60check()61traci.simulationStep()62ovr(0)6364for step in range(3):65check()66traci.simulationStep()67ovr(1)6869for step in range(3):70check()71traci.simulationStep()72ovr(4)7374for step in range(3):75check()76traci.simulationStep()77ovr(10)7879for step in range(3):80check()81traci.simulationStep()82ovr(-1)8384for step in range(3):85check()86traci.simulationStep()8788traci.close()899091