Path: blob/main/tests/complex/traas/simple/data/Main.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 Main.java16/// @author Mario Krumnow17/// @date 201318///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 Main {29public static void main(String[] args) {30String sumo_bin = "sumo";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 immediately4546//start Traci Server47conn.runServer();48conn.setOrder(1);4950for (int i = 0; i < 3600; i++) {5152conn.do_timestep();53conn.do_job_set(Vehicle.addFull("v" + i, "r1", "car", "now", "0", "0", "max", "current", "max", "current", "", "", "", 0, 0));54double timeSeconds = (double)conn.do_job_get(Simulation.getTime());55int tlsPhase = (int)conn.do_job_get(Trafficlight.getPhase("gneJ1"));56String tlsPhaseName = (String)conn.do_job_get(Trafficlight.getPhaseName("gneJ1"));57System.out.println(String.format("Step %s, tlsPhase %s (%s)", timeSeconds, tlsPhase, tlsPhaseName));5859SumoVehicleData vehData = (SumoVehicleData)conn.do_job_get(Inductionloop.getVehicleData("loop1"));60for (SumoVehicleData.VehicleData d : vehData.ll) {61System.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));62}63}6465conn.close();6667} catch (Exception ex) {68ex.printStackTrace();69}7071}7273}747576