Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci_java/simple/data/Main.java
169689 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2017-2025 German Aerospace Center (DLR) and others.
4
// TraaS module
5
// Copyright (C) 2013-2017 Dresden University of Technology
6
// This program and the accompanying materials are made available under the
7
// terms of the Eclipse Public License 2.0 which is available at
8
// https://www.eclipse.org/legal/epl-2.0/
9
// This Source Code may also be made available under the following Secondary
10
// Licenses when the conditions for such availability set forth in the Eclipse
11
// Public License 2.0 are satisfied: GNU General Public License, version 2
12
// or later which is available at
13
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
14
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
15
/****************************************************************************/
16
/// @file Main.java
17
/// @author Mario Krumnow
18
/// @author Jakob Erdmann
19
/// @date 2013
20
///
21
//
22
/****************************************************************************/
23
import org.eclipse.sumo.libtraci.*;
24
25
public class Main {
26
public static void main(String[] args) {
27
Simulation.preloadLibraries();
28
String sumo_bin = "sumo";
29
String config_file = "data/config.sumocfg";
30
double step_length = 0.1;
31
if (args.length > 0) {
32
sumo_bin = args[0];
33
}
34
if (args.length > 1) {
35
config_file = args[1];
36
}
37
Simulation.start(new StringVector(new String[] {sumo_bin,
38
"-c", config_file,
39
"--start",
40
"--step-length", "0.1"
41
}));
42
43
for (int i = 0; i < 3600; i++) {
44
Simulation.step();
45
Vehicle.add("v" + i, "r1", "car", "now", "0", "0", "max", "current", "max", "current", "", "", "", 0, 0);
46
double timeSeconds = Simulation.getTime();
47
int tlsPhase = TrafficLight.getPhase("gneJ1");
48
String tlsPhaseName = TrafficLight.getPhaseName("gneJ1");
49
System.out.println(String.format("Step %s, tlsPhase %s (%s)", timeSeconds, tlsPhase, tlsPhaseName));
50
51
TraCIVehicleDataVector vehData = InductionLoop.getVehicleData("loop1");
52
for (TraCIVehicleData d : vehData) {
53
System.out.println(String.format(" veh=%s len=%s entry=%s leave=%s type=%s",
54
d.getId(), d.getLength(), d.getEntryTime(), d.getLeaveTime(), d.getTypeID()));
55
}
56
}
57
Simulation.close();
58
}
59
}
60
61