Path: blob/main/tests/complex/traci_java/multiclient/data/MultiClient1.java
169689 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2017-2025 German Aerospace Center (DLR) and others.3// TraaS module4// Copyright (C) 2013-2017 Dresden University of Technology5// This program and the accompanying materials are made available under the6// terms of the Eclipse Public License 2.0 which is available at7// https://www.eclipse.org/legal/epl-2.0/8// This Source Code may also be made available under the following Secondary9// Licenses when the conditions for such availability set forth in the Eclipse10// Public License 2.0 are satisfied: GNU General Public License, version 211// or later which is available at12// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html13// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later14/****************************************************************************/15/// @file MultiClient1.java16/// @author Jakob Erdmann17/// @author Mirko Barthauer18/// @date 201919///20//21/****************************************************************************/22import org.eclipse.sumo.libtraci.*;2324public class MultiClient1 {25public static void main(String[] args) {26Simulation.preloadLibraries();27String sumo_bin = "sumo"; //"sumo-gui";28String config_file = "data/config.sumocfg";2930if (args.length > 0) {31sumo_bin = args[0];32}33if (args.length > 1) {34config_file = args[1];35}3637try {38Simulation.start(new StringVector(new String[] {sumo_bin,39"-c", config_file,40"--start", "true",41"--num-clients", "2",42"--step-length", "0.1"43}), 9999);4445//start Traci Server46Simulation.setOrder(1);4748int lastPhase = -1;49for (int i = 0; i < 3600; i++) {50Simulation.step();51Vehicle.add("v" + i, "r1", "car", "now", "0", "0", "max", "current", "max", "current", "", "", "", 0, 0);52double timeSeconds = Simulation.getTime();53int tlsPhase = TrafficLight.getPhase("gneJ1");54if (tlsPhase != lastPhase) {55String tlsPhaseName = TrafficLight.getPhaseName("gneJ1");56System.out.println(String.format("Step %s, tlsPhase %s (%s)", timeSeconds, tlsPhase, tlsPhaseName));57lastPhase = tlsPhase;58}5960TraCIVehicleDataVector vehData = InductionLoop.getVehicleData("loop1");61for (TraCIVehicleData d : vehData) {62System.out.println(String.format(" veh=%s len=%s entry=%s leave=%s type=%s", d.getId(), d.getLength(), d.getEntryTime(), d.getLeaveTime(), d.getTypeID()));63}64}6566Simulation.close();6768} catch (Exception ex) {69ex.printStackTrace();70}7172}7374}757677