Path: blob/main/tests/complex/traci/vehicle/getNeighborsSublane/runner.py
169712 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 sys2526if "SUMO_HOME" in os.environ:27sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))28import traci # noqa29import sumolib # noqa303132def step():33s = traci.simulation.getTime()34traci.simulationStep()35return s363738egoID = "ego"394041def printNeighInfo():42print("Neigh infos for ego:")43rightFollowers = traci.vehicle.getRightFollowers(egoID)44print(" rightFollowers:\n %s" % sorted(rightFollowers))45rightLeaders = traci.vehicle.getRightLeaders(egoID)46print(" rightLeaders:\n %s" % sorted(rightLeaders))47leftFollowers = traci.vehicle.getLeftFollowers(egoID)48print(" leftFollowers:\n %s" % sorted(leftFollowers))49leftLeaders = traci.vehicle.getLeftLeaders(egoID)50print(" leftLeaders:\n %s" % sorted(leftLeaders))51rightFollowersBlocking = traci.vehicle.getRightFollowers(egoID, True)52print(" rightFollowers (only blocking):\n %s" % sorted(rightFollowersBlocking))53rightLeadersBlocking = traci.vehicle.getRightLeaders(egoID, True)54print(" rightLeaders (only blocking):\n %s" % sorted(rightLeadersBlocking))55leftFollowersBlocking = traci.vehicle.getLeftFollowers(egoID, True)56print(" leftFollowers (only blocking):\n %s" % sorted(leftFollowersBlocking))57leftLeadersBlocking = traci.vehicle.getLeftLeaders(egoID, True)58print(" leftLeaders (only blocking):\n %s" % sorted(leftLeadersBlocking))59sys.stdout.flush()606162traci.start([sumolib.checkBinary('sumo'), "-c", "sumo.sumocfg"])63# ~ traci.init(port=12345)6465for i in range(1):66print("step", step())6768for vehID in traci.vehicle.getIDList():69traci.vehicle.changeLaneRelative(vehID, 0, 999)7071for i in range(2):72print("step", step())7374while egoID in traci.vehicle.getIDList():75if traci.simulation.getTime() == 10:76print("vehicle changes after ego")77traci.vehicle.changeLaneRelative("r0.0", 1, 999)78elif traci.simulation.getTime() == 15:79print("vehicle changes after ego")80traci.vehicle.changeLaneRelative("r0.0", -1, 999)81printNeighInfo()82print("step", step())83step()84# done85traci.close()868788