Path: blob/main/tests/complex/traci_java/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/// @author Jakob Erdmann18/// @date 201319///20//21/****************************************************************************/22import org.eclipse.sumo.libtraci.*;2324public class Main {25public static void main(String[] args) {26Simulation.preloadLibraries();27String sumo_bin = "sumo";28String config_file = "data/config.sumocfg";29double step_length = 0.1;30if (args.length > 0) {31sumo_bin = args[0];32}33if (args.length > 1) {34config_file = args[1];35}36Simulation.start(new StringVector(new String[] {sumo_bin,37"-c", config_file,38"--start",39"--step-length", "0.1"40}));4142for (int i = 0; i < 3600; i++) {43Simulation.step();44Vehicle.add("v" + i, "r1", "car", "now", "0", "0", "max", "current", "max", "current", "", "", "", 0, 0);45double timeSeconds = Simulation.getTime();46int tlsPhase = TrafficLight.getPhase("gneJ1");47String tlsPhaseName = TrafficLight.getPhaseName("gneJ1");48System.out.println(String.format("Step %s, tlsPhase %s (%s)", timeSeconds, tlsPhase, tlsPhaseName));4950TraCIVehicleDataVector vehData = InductionLoop.getVehicleData("loop1");51for (TraCIVehicleData d : vehData) {52System.out.println(String.format(" veh=%s len=%s entry=%s leave=%s type=%s",53d.getId(), d.getLength(), d.getEntryTime(), d.getLeaveTime(), d.getTypeID()));54}55}56Simulation.close();57}58}596061