Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ROMARouteHandler.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 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/****************************************************************************/
21// Parser and container for routes during their loading
22/****************************************************************************/
23#include <config.h>
24
29#include <od/ODMatrix.h>
30#include "ROMARouteHandler.h"
31
32
33// ===========================================================================
34// method definitions
35// ===========================================================================
37 SUMOSAXHandler(""), myMatrix(matrix),
38 myIgnoreTaz(OptionsCont::getOptions().getBool("ignore-taz")),
39 myScale(OptionsCont::getOptions().getFloat("scale")),
40 myNumLoaded(0) {
41 if (OptionsCont::getOptions().isSet("taz-param")) {
43 }
44}
45
46
49
50
51void
53 if (element == SUMO_TAG_TRIP || element == SUMO_TAG_VEHICLE || element == SUMO_TAG_FLOW) {
58 if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
60 } else if (attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION)) {
62 }
63
64 }
66 if (attrs.hasAttribute(SUMO_ATTR_TO)) {
68 } else if (attrs.hasAttribute(SUMO_ATTR_TO_JUNCTION)) {
70 }
71 }
72 } else if (element == SUMO_TAG_PARAM && !myTazParamKeys.empty()) {
73 if (attrs.getString(SUMO_ATTR_KEY) == myTazParamKeys[0]) {
76 }
77 if (myTazParamKeys.size() > 1 && attrs.getString(SUMO_ATTR_KEY) == myTazParamKeys[1]) {
80 }
81 }
82}
83
84
85void
87 if (element == SUMO_TAG_TRIP || element == SUMO_TAG_VEHICLE || element == SUMO_TAG_FLOW) {
89 WRITE_WARNINGF(TL("No origin or no destination given, ignoring '%'!"), myVehicleParameter->id);
90 } else {
91 int quota = 1;
92 SUMOTime departOffset = 0;
93 if (element == SUMO_TAG_FLOW) {
94 int flowSize = 1;
96 if (myVehicleParameter->repetitionNumber != std::numeric_limits<int>::max()) {
98 } else if (myVehicleParameter->poissonRate > 0) {
99 flowSize = (int)(flowDur * myVehicleParameter->poissonRate);
101 flowSize = (int)(flowDur * myVehicleParameter->repetitionProbability);
102 }
103 quota = (int)(flowSize * myScale + 0.5);
104 myNumLoaded += flowSize;
105 departOffset = TIME2STEPS(flowDur) / quota;
106 } else {
108 myNumLoaded += 1;
109 }
111 for (int i = 0; i < quota; i++) {
113 veh.id = i == 0 ? myVehicleParameter->id : myVehicleParameter->id + "." + toString(i);
114 veh.depart = depart;
115 myMatrix.add(veh,
118 depart += departOffset;
119 }
120 }
121 delete myVehicleParameter;
122 }
123}
124
125
126/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:288
#define TL(string)
Definition MsgHandler.h:305
#define STEPS2TIME(x)
Definition SUMOTime.h:55
#define TIME2STEPS(x)
Definition SUMOTime.h:57
const long long int VEHPARS_TO_TAZ_SET
const long long int VEHPARS_FROM_TAZ_SET
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_TAG_FLOW
a flow definition using from and to edges or a route
@ SUMO_TAG_PARAM
parameter associated to a certain key
@ SUMO_TAG_TRIP
a single trip definition (used by router)
@ SUMO_ATTR_FROM_JUNCTION
@ SUMO_ATTR_VALUE
@ SUMO_ATTR_TO_JUNCTION
@ SUMO_ATTR_TO
@ SUMO_ATTR_FROM
@ SUMO_ATTR_KEY
int getScalingQuota(double frac, int loaded)
Returns the number of instances of the current object that shall be emitted given the number of loade...
Definition StdDefs.cpp:61
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
An O/D (origin/destination) matrix.
Definition ODMatrix.h:68
bool add(double vehicleNumber, const std::pair< SUMOTime, SUMOTime > &beginEnd, const std::string &origin, const std::string &destination, const std::string &vehicleType, const bool originIsEdge=false, const bool destinationIsEdge=false, bool noScaling=false)
Builds a single cell from the given values, verifying them.
Definition ODMatrix.cpp:75
A storage for options typed value containers)
Definition OptionsCont.h:89
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
void myEndElement(int element)
Callback method for a closing tag to implement by derived classes.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
std::vector< std::string > myTazParamKeys
The keys for reading taz.
double myScale
scale for loading vehicles
ODMatrix & myMatrix
The matrix to fill.
SUMOVehicleParameter * myVehicleParameter
The current vehicle parameters.
ROMARouteHandler(ODMatrix &matrix)
standard constructor
virtual ~ROMARouteHandler()
standard destructor
const bool myIgnoreTaz
whether to ignore attributes fromTaz, toTaz
int myNumLoaded
number of parsed vehicles
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
SAX-handler base for SUMO-files.
Structure representing possible vehicle parameter.
double repetitionProbability
The probability for emitting a vehicle per second.
long long int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
double poissonRate
The rate for emitting vehicles with a poisson distribution.
SUMOTime repetitionEnd
The time at which the flow ends (only needed when using repetitionProbability)
bool wasSet(long long int what) const
Returns whether the given parameter was set.
std::string id
The vehicle's id.
std::string toTaz
The vehicle's destination zone (district)
std::string fromTaz
The vehicle's origin zone (district)
static SUMOVehicleParameter * parseVehicleAttributes(int element, const SUMOSAXAttributes &attrs, const bool hardFail, const bool optionalID=false, const bool skipDepart=false, const bool allowInternalRoutes=false)
Parses a vehicle's attributes.
static SUMOVehicleParameter * parseFlowAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs, const bool hardFail, const bool needID, const SUMOTime beginDefault, const SUMOTime endDefault, const bool allowInternalRoutes=false)
Parses a flow's attributes.