Path: blob/main/tests/complex/traci/contextSubscriptions/matrix_test/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 Daniel Krajzewicz15# @author Michael Behrisch16# @date 2012-10-191718from __future__ import absolute_import19from __future__ import print_function2021import os22import sys2324if "SUMO_HOME" in os.environ:25sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))26import sumolib # noqa27import traci # noqa282930def runSingle(viewRange, domain, domain2, varIDs):31name = domain._name if hasattr(domain, "_name") else domain.__name__32name2 = domain2._name if hasattr(domain2, "_name") else domain2.__name__33ids = domain.getIDList() if name != "simulation" else [""]34if not ids:35print("No objects for domain '%s' at time %s" %36(name, traci.simulation.getTime()))37return38egoID = ids[0]3940print("trying to subscribe to %s around %s '%s' at time %s" % (41name2, name, egoID, traci.simulation.getTime()))42domain.subscribeContext(egoID, domain2.DOMAIN_ID, viewRange,43varIDs)44traci.simulationStep()45responses = domain.getAllContextSubscriptionResults()46print(" found %s objects" % len(responses))4748domain.unsubscribeContext(egoID, domain2.DOMAIN_ID, viewRange)49traci.simulationStep()50responses = domain.getAllContextSubscriptionResults()51if responses:52print("Error: Unsubscribe did not work", responses)53else:54print("Ok: Unsubscribe successful")55sys.stdout.flush()565758# main59try:60traci.start([sumolib.checkBinary(sys.argv[1]),61'-Q', "-c", "sumo.sumocfg",62'-a', 'input_additional.add.xml'])63traci.simulationStep()6465varIDs = None if "--defaults" in sys.argv else [traci.constants.TRACI_ID_LIST]66for domain in traci.DOMAINS:67for domain2 in traci.DOMAINS:68try:69runSingle(100, domain, domain2, varIDs)70except traci.TraCIException:71pass72finally:73traci.close()747576