Path: blob/main/tests/complex/traci/vehicle/distance_after_reroute/runner.py
169689 views
#!/usr/bin/env python1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.3# This program and the accompanying materials are made available under the4# terms of the Eclipse Public License 2.0 which is available at5# https://www.eclipse.org/legal/epl-2.0/6# This Source Code may also be made available under the following Secondary7# Licenses when the conditions for such availability set forth in the Eclipse8# Public License 2.0 are satisfied: GNU General Public License, version 29# or later which is available at10# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1213# @file runner.py14# @author Laura Bieker15# @author Michael Behrisch16# @date 2014-08-28171819from __future__ import print_function20from __future__ import absolute_import21import os22import sys2324if "SUMO_HOME" in os.environ:25sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))26import traci # noqa27import sumolib # noqa282930def main(args):31traci.start([sumolib.checkBinary('sumo'), "-c", "data/hello.sumocfg",32"--netstate-dump", "rawdump.xml",33"--no-step-log"] + sys.argv[1:])3435for step in range(162):36traci.simulationStep()37if step == 120:38print(traci.vehicle.getDistance('Stapler_00'))39traci.vehicle.setRoute('Stapler_00', ('ed1', 'ed5'))40print(traci.vehicle.getRoute('Stapler_00'))41# assert traci.vehicle.getRoute('Stapler_00') == ('ed0', 'ed1', 'ed5')42print(traci.vehicle.getDistance('Stapler_00'))43if step == 122:44# assert traci.vehicle.getRoute('Stapler_00') == ('ed0', 'ed1', 'ed5')45print(traci.vehicle.getDistance('Stapler_00'))46traci.vehicle.setRouteID('Stapler_00', "short")47print(traci.vehicle.getRoute('Stapler_00'))48print(traci.vehicle.getDistance('Stapler_00'))49# We assume, that we reach an internal lane at step 130,50# if distance calc is correct, there should be a51# 10m distance difference between the52# output of step 129 and 13053if step in (129, 130):54print(step, round(traci.vehicle.getDistance('Stapler_00'), 2))55traci.close()565758if __name__ == "__main__":59main(sys.argv[1:])606162