Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traas/multiclient/data/MultiClient1.java
169771 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
/// @date 2019
19
///
20
//
21
/****************************************************************************/
22
import it.polito.appeal.traci.SumoTraciConnection;
23
import de.tudresden.sumo.cmd.Simulation;
24
import de.tudresden.sumo.cmd.Vehicle;
25
import de.tudresden.sumo.cmd.Inductionloop;
26
import de.tudresden.sumo.cmd.Trafficlight;
27
import de.tudresden.sumo.objects.SumoVehicleData;
28
29
public class MultiClient1 {
30
public static void main(String[] args) {
31
String sumo_bin = "sumo"; //"sumo-gui";
32
String config_file = "data/config.sumocfg";
33
double step_length = 0.1;
34
35
if (args.length > 0) {
36
sumo_bin = args[0];
37
}
38
if (args.length > 1) {
39
config_file = args[1];
40
}
41
42
try {
43
SumoTraciConnection conn = new SumoTraciConnection(sumo_bin, config_file);
44
conn.addOption("step-length", step_length + "");
45
conn.addOption("start", "true"); //start sumo immediately
46
conn.addOption("num-clients", "2");
47
48
//start Traci Server
49
conn.runServer(9998);
50
conn.setOrder(1);
51
52
int lastPhase = -1;
53
for (int i = 0; i < 3600; i++) {
54
conn.do_timestep();
55
conn.do_job_set(Vehicle.addFull("v" + i, "r1", "car", "now", "0", "0", "max", "current", "max", "current", "", "", "", 0, 0));
56
double timeSeconds = (double)conn.do_job_get(Simulation.getTime());
57
int tlsPhase = (int)conn.do_job_get(Trafficlight.getPhase("gneJ1"));
58
if (tlsPhase != lastPhase) {
59
String tlsPhaseName = (String)conn.do_job_get(Trafficlight.getPhaseName("gneJ1"));
60
System.out.println(String.format("Step %s, tlsPhase %s (%s)", timeSeconds, tlsPhase, tlsPhaseName));
61
lastPhase = tlsPhase;
62
}
63
64
SumoVehicleData vehData = (SumoVehicleData)conn.do_job_get(Inductionloop.getVehicleData("loop1"));
65
for (SumoVehicleData.VehicleData d : vehData.ll) {
66
System.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));
67
}
68
}
69
70
conn.close();
71
72
} catch (Exception ex) {
73
ex.printStackTrace();
74
}
75
76
}
77
78
}
79
80