Path: blob/main/tests/complex/traas/multiclient/data/MultiClient1.java
169771 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/// @date 201918///19//20/****************************************************************************/21import it.polito.appeal.traci.SumoTraciConnection;22import de.tudresden.sumo.cmd.Simulation;23import de.tudresden.sumo.cmd.Vehicle;24import de.tudresden.sumo.cmd.Inductionloop;25import de.tudresden.sumo.cmd.Trafficlight;26import de.tudresden.sumo.objects.SumoVehicleData;2728public class MultiClient1 {29public static void main(String[] args) {30String sumo_bin = "sumo"; //"sumo-gui";31String config_file = "data/config.sumocfg";32double step_length = 0.1;3334if (args.length > 0) {35sumo_bin = args[0];36}37if (args.length > 1) {38config_file = args[1];39}4041try {42SumoTraciConnection conn = new SumoTraciConnection(sumo_bin, config_file);43conn.addOption("step-length", step_length + "");44conn.addOption("start", "true"); //start sumo immediately45conn.addOption("num-clients", "2");4647//start Traci Server48conn.runServer(9998);49conn.setOrder(1);5051int lastPhase = -1;52for (int i = 0; i < 3600; i++) {53conn.do_timestep();54conn.do_job_set(Vehicle.addFull("v" + i, "r1", "car", "now", "0", "0", "max", "current", "max", "current", "", "", "", 0, 0));55double timeSeconds = (double)conn.do_job_get(Simulation.getTime());56int tlsPhase = (int)conn.do_job_get(Trafficlight.getPhase("gneJ1"));57if (tlsPhase != lastPhase) {58String tlsPhaseName = (String)conn.do_job_get(Trafficlight.getPhaseName("gneJ1"));59System.out.println(String.format("Step %s, tlsPhase %s (%s)", timeSeconds, tlsPhase, tlsPhaseName));60lastPhase = tlsPhase;61}6263SumoVehicleData vehData = (SumoVehicleData)conn.do_job_get(Inductionloop.getVehicleData("loop1"));64for (SumoVehicleData.VehicleData d : vehData.ll) {65System.out.println(String.format(" veh=%s len=%s entry=%s leave=%s type=%s", d.vehID, d.length, d.entry_time, d.leave_time, d.typeID));66}67}6869conn.close();7071} catch (Exception ex) {72ex.printStackTrace();73}7475}7677}787980