Path: blob/main/tests/complex/traci/inductionloop/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 = "0"333435def check():36print("%s timeSinceDet=%s occupancy=%s vehNum=%s vehIDs=%s meanLength=%s meanSpeed=%s vehData=%s" % (37traci.simulation.getTime(),38traci.inductionloop.getTimeSinceDetection(loopID),39traci.inductionloop.getLastStepOccupancy(loopID),40traci.inductionloop.getLastStepVehicleNumber(loopID),41traci.inductionloop.getLastStepVehicleIDs(loopID),42traci.inductionloop.getLastStepMeanLength(loopID),43traci.inductionloop.getLastStepMeanSpeed(loopID),44traci.inductionloop.getVehicleData(loopID)))454647def ovr(time):48print("override %s" % time)49traci.inductionloop.overrideTimeSinceDetection(loopID, time)505152for step in range(3):53check()54traci.simulationStep()55ovr(0)5657for step in range(3):58check()59traci.simulationStep()60ovr(0.5)6162for step in range(3):63check()64traci.simulationStep()65ovr(1)6667for step in range(3):68check()69traci.simulationStep()70ovr(2)7172for step in range(3):73check()74traci.simulationStep()75ovr(-1)7677for step in range(3):78check()79traci.simulationStep()8081traci.close()828384