Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci_java/multiclient/data/MultiClient1.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 MultiClient1.java
17
/// @author Jakob Erdmann
18
/// @author Mirko Barthauer
19
/// @date 2019
20
///
21
//
22
/****************************************************************************/
23
import org.eclipse.sumo.libtraci.*;
24
25
public class MultiClient1 {
26
public static void main(String[] args) {
27
Simulation.preloadLibraries();
28
String sumo_bin = "sumo"; //"sumo-gui";
29
String config_file = "data/config.sumocfg";
30
31
if (args.length > 0) {
32
sumo_bin = args[0];
33
}
34
if (args.length > 1) {
35
config_file = args[1];
36
}
37
38
try {
39
Simulation.start(new StringVector(new String[] {sumo_bin,
40
"-c", config_file,
41
"--start", "true",
42
"--num-clients", "2",
43
"--step-length", "0.1"
44
}), 9999);
45
46
//start Traci Server
47
Simulation.setOrder(1);
48
49
int lastPhase = -1;
50
for (int i = 0; i < 3600; i++) {
51
Simulation.step();
52
Vehicle.add("v" + i, "r1", "car", "now", "0", "0", "max", "current", "max", "current", "", "", "", 0, 0);
53
double timeSeconds = Simulation.getTime();
54
int tlsPhase = TrafficLight.getPhase("gneJ1");
55
if (tlsPhase != lastPhase) {
56
String tlsPhaseName = TrafficLight.getPhaseName("gneJ1");
57
System.out.println(String.format("Step %s, tlsPhase %s (%s)", timeSeconds, tlsPhase, tlsPhaseName));
58
lastPhase = tlsPhase;
59
}
60
61
TraCIVehicleDataVector vehData = InductionLoop.getVehicleData("loop1");
62
for (TraCIVehicleData d : vehData) {
63
System.out.println(String.format(" veh=%s len=%s entry=%s leave=%s type=%s", d.getId(), d.getLength(), d.getEntryTime(), d.getLeaveTime(), d.getTypeID()));
64
}
65
}
66
67
Simulation.close();
68
69
} catch (Exception ex) {
70
ex.printStackTrace();
71
}
72
73
}
74
75
}
76
77