Path: blob/main/src/traci-server/TraCIServerAPI_Edge.cpp
193678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2002-2026 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file TraCIServerAPI_Edge.cpp14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Jerome Haerri17/// @author Michael Behrisch18/// @author Laura Bieker19/// @author Mario Krumnow20/// @author Gregor Laemmel21/// @date Sept 200222///23// APIs for getting/setting edge values via TraCI24/****************************************************************************/25#include <config.h>2627#include <utils/common/StdDefs.h>28#include <microsim/MSNet.h>29#include <microsim/MSEdgeControl.h>30#include <microsim/MSEdge.h>31#include <microsim/MSLane.h>32#include <microsim/MSVehicle.h>33#include <microsim/transportables/MSPerson.h>34#include <libsumo/TraCIConstants.h>35#include "TraCIServerAPI_Edge.h"36#include <microsim/MSEdgeWeightsStorage.h>37#include <utils/emissions/HelpersHarmonoise.h>38#include <libsumo/StorageHelper.h>39#include <libsumo/Edge.h>404142// ===========================================================================43// method definitions44// ===========================================================================45bool46TraCIServerAPI_Edge::processSet(TraCIServer& server, tcpip::Storage& inputStorage,47tcpip::Storage& outputStorage) {48std::string warning; // additional description for response49// variable50int variable = inputStorage.readUnsignedByte();51if (variable != libsumo::VAR_EDGE_TRAVELTIME52&& variable != libsumo::VAR_EDGE_EFFORT53&& variable != libsumo::VAR_MAXSPEED54&& variable != libsumo::LANE_ALLOWED55&& variable != libsumo::LANE_DISALLOWED56&& variable != libsumo::VAR_FRICTION57&& variable != libsumo::VAR_PARAMETER) {58return server.writeErrorStatusCmd(libsumo::CMD_SET_EDGE_VARIABLE,59"Change Edge State: unsupported variable " + toHex(variable, 2)60+ " specified", outputStorage);61}62// id63std::string id = inputStorage.readString();64try {65// process66switch (variable) {67case libsumo::LANE_ALLOWED: {68// read and set allowed vehicle classes69const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Allowed vehicle classes must be given as a list of strings.");70libsumo::Edge::setAllowed(id, classes);71break;72}73case libsumo::LANE_DISALLOWED: {74// read and set disallowed vehicle classes75const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Not allowed vehicle classes must be given as a list of strings.");76libsumo::Edge::setDisallowed(id, classes);77break;78}79case libsumo::VAR_EDGE_TRAVELTIME: {80// read and set travel time81const int parameterCount = StoHelp::readCompound(inputStorage, -1, "Setting travel time requires a compound object.");82if (parameterCount == 3) {83// bound by time84const double begTime = StoHelp::readTypedDouble(inputStorage, "The first variable must be the begin time given as double.");85const double endTime = StoHelp::readTypedDouble(inputStorage, "The second variable must be the end time given as double.");86const double value = StoHelp::readTypedDouble(inputStorage, "The third variable must be the value given as double.");87libsumo::Edge::adaptTraveltime(id, value, begTime, endTime);88} else if (parameterCount == 1) {89// unbound90const double value = StoHelp::readTypedDouble(inputStorage, "The variable must be the value given as double.");91libsumo::Edge::adaptTraveltime(id, value, 0., std::numeric_limits<double>::max());92} else {93return server.writeErrorStatusCmd(libsumo::CMD_SET_EDGE_VARIABLE,94"Setting travel time requires either begin time, end time, and value, or only value as parameter.",95outputStorage);96}97break;98}99case libsumo::VAR_EDGE_EFFORT: {100// read and set effort101const int parameterCount = StoHelp::readCompound(inputStorage, -1, "Setting effort requires a compound object.");102if (parameterCount == 3) {103// bound by time104const double begTime = StoHelp::readTypedDouble(inputStorage, "The first variable must be the begin time given as double.");105const double endTime = StoHelp::readTypedDouble(inputStorage, "The second variable must be the end time given as double.");106const double value = StoHelp::readTypedDouble(inputStorage, "The third variable must be the value given as double.");107libsumo::Edge::setEffort(id, value, begTime, endTime);108} else if (parameterCount == 1) {109// unbound110const double value = StoHelp::readTypedDouble(inputStorage, "The variable must be the value given as double.");111libsumo::Edge::setEffort(id, value, 0., std::numeric_limits<double>::max());112} else {113return server.writeErrorStatusCmd(libsumo::CMD_SET_EDGE_VARIABLE,114"Setting effort requires either begin time, end time, and value, or only value as parameter.",115outputStorage);116}117break;118}119case libsumo::VAR_MAXSPEED: {120// read and set max. speed121const double value = StoHelp::readTypedDouble(inputStorage, "The speed must be given as a double.");122libsumo::Edge::setMaxSpeed(id, value);123break;124}125case libsumo::VAR_FRICTION: {126// read and set friction for entire edge127const double value = StoHelp::readTypedDouble(inputStorage, "The friction must be given as a double.");128libsumo::Edge::setFriction(id, value);129break;130}131case libsumo::VAR_PARAMETER: {132// read and check item number133StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");134const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");135const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");136libsumo::Edge::setParameter(id, name, value);137break;138}139default:140break;141}142} catch (libsumo::TraCIException& e) {143return server.writeErrorStatusCmd(libsumo::CMD_SET_EDGE_VARIABLE, e.what(), outputStorage);144}145server.writeStatusCmd(libsumo::CMD_SET_EDGE_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);146return true;147}148149150/****************************************************************************/151152153