Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/traci-server/TraCIServerAPI_Edge.cpp
193678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2002-2026 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file TraCIServerAPI_Edge.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Jerome Haerri
18
/// @author Michael Behrisch
19
/// @author Laura Bieker
20
/// @author Mario Krumnow
21
/// @author Gregor Laemmel
22
/// @date Sept 2002
23
///
24
// APIs for getting/setting edge values via TraCI
25
/****************************************************************************/
26
#include <config.h>
27
28
#include <utils/common/StdDefs.h>
29
#include <microsim/MSNet.h>
30
#include <microsim/MSEdgeControl.h>
31
#include <microsim/MSEdge.h>
32
#include <microsim/MSLane.h>
33
#include <microsim/MSVehicle.h>
34
#include <microsim/transportables/MSPerson.h>
35
#include <libsumo/TraCIConstants.h>
36
#include "TraCIServerAPI_Edge.h"
37
#include <microsim/MSEdgeWeightsStorage.h>
38
#include <utils/emissions/HelpersHarmonoise.h>
39
#include <libsumo/StorageHelper.h>
40
#include <libsumo/Edge.h>
41
42
43
// ===========================================================================
44
// method definitions
45
// ===========================================================================
46
bool
47
TraCIServerAPI_Edge::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
48
tcpip::Storage& outputStorage) {
49
std::string warning; // additional description for response
50
// variable
51
int variable = inputStorage.readUnsignedByte();
52
if (variable != libsumo::VAR_EDGE_TRAVELTIME
53
&& variable != libsumo::VAR_EDGE_EFFORT
54
&& variable != libsumo::VAR_MAXSPEED
55
&& variable != libsumo::LANE_ALLOWED
56
&& variable != libsumo::LANE_DISALLOWED
57
&& variable != libsumo::VAR_FRICTION
58
&& variable != libsumo::VAR_PARAMETER) {
59
return server.writeErrorStatusCmd(libsumo::CMD_SET_EDGE_VARIABLE,
60
"Change Edge State: unsupported variable " + toHex(variable, 2)
61
+ " specified", outputStorage);
62
}
63
// id
64
std::string id = inputStorage.readString();
65
try {
66
// process
67
switch (variable) {
68
case libsumo::LANE_ALLOWED: {
69
// read and set allowed vehicle classes
70
const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Allowed vehicle classes must be given as a list of strings.");
71
libsumo::Edge::setAllowed(id, classes);
72
break;
73
}
74
case libsumo::LANE_DISALLOWED: {
75
// read and set disallowed vehicle classes
76
const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Not allowed vehicle classes must be given as a list of strings.");
77
libsumo::Edge::setDisallowed(id, classes);
78
break;
79
}
80
case libsumo::VAR_EDGE_TRAVELTIME: {
81
// read and set travel time
82
const int parameterCount = StoHelp::readCompound(inputStorage, -1, "Setting travel time requires a compound object.");
83
if (parameterCount == 3) {
84
// bound by time
85
const double begTime = StoHelp::readTypedDouble(inputStorage, "The first variable must be the begin time given as double.");
86
const double endTime = StoHelp::readTypedDouble(inputStorage, "The second variable must be the end time given as double.");
87
const double value = StoHelp::readTypedDouble(inputStorage, "The third variable must be the value given as double.");
88
libsumo::Edge::adaptTraveltime(id, value, begTime, endTime);
89
} else if (parameterCount == 1) {
90
// unbound
91
const double value = StoHelp::readTypedDouble(inputStorage, "The variable must be the value given as double.");
92
libsumo::Edge::adaptTraveltime(id, value, 0., std::numeric_limits<double>::max());
93
} else {
94
return server.writeErrorStatusCmd(libsumo::CMD_SET_EDGE_VARIABLE,
95
"Setting travel time requires either begin time, end time, and value, or only value as parameter.",
96
outputStorage);
97
}
98
break;
99
}
100
case libsumo::VAR_EDGE_EFFORT: {
101
// read and set effort
102
const int parameterCount = StoHelp::readCompound(inputStorage, -1, "Setting effort requires a compound object.");
103
if (parameterCount == 3) {
104
// bound by time
105
const double begTime = StoHelp::readTypedDouble(inputStorage, "The first variable must be the begin time given as double.");
106
const double endTime = StoHelp::readTypedDouble(inputStorage, "The second variable must be the end time given as double.");
107
const double value = StoHelp::readTypedDouble(inputStorage, "The third variable must be the value given as double.");
108
libsumo::Edge::setEffort(id, value, begTime, endTime);
109
} else if (parameterCount == 1) {
110
// unbound
111
const double value = StoHelp::readTypedDouble(inputStorage, "The variable must be the value given as double.");
112
libsumo::Edge::setEffort(id, value, 0., std::numeric_limits<double>::max());
113
} else {
114
return server.writeErrorStatusCmd(libsumo::CMD_SET_EDGE_VARIABLE,
115
"Setting effort requires either begin time, end time, and value, or only value as parameter.",
116
outputStorage);
117
}
118
break;
119
}
120
case libsumo::VAR_MAXSPEED: {
121
// read and set max. speed
122
const double value = StoHelp::readTypedDouble(inputStorage, "The speed must be given as a double.");
123
libsumo::Edge::setMaxSpeed(id, value);
124
break;
125
}
126
case libsumo::VAR_FRICTION: {
127
// read and set friction for entire edge
128
const double value = StoHelp::readTypedDouble(inputStorage, "The friction must be given as a double.");
129
libsumo::Edge::setFriction(id, value);
130
break;
131
}
132
case libsumo::VAR_PARAMETER: {
133
// read and check item number
134
StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");
135
const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");
136
const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");
137
libsumo::Edge::setParameter(id, name, value);
138
break;
139
}
140
default:
141
break;
142
}
143
} catch (libsumo::TraCIException& e) {
144
return server.writeErrorStatusCmd(libsumo::CMD_SET_EDGE_VARIABLE, e.what(), outputStorage);
145
}
146
server.writeStatusCmd(libsumo::CMD_SET_EDGE_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
147
return true;
148
}
149
150
151
/****************************************************************************/
152
153