Eclipse SUMO - Simulation of Urban MObility
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-2024 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 
48 }
49 
50 
51 void
53  if (element == SUMO_TAG_TRIP || element == SUMO_TAG_VEHICLE) {
56  if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
58  } else if (attrs.hasAttribute(SUMO_ATTR_FROM_JUNCTION)) {
60  }
61 
62  }
64  if (attrs.hasAttribute(SUMO_ATTR_TO)) {
66  } else if (attrs.hasAttribute(SUMO_ATTR_TO_JUNCTION)) {
68  }
69  }
70  } else if (element == SUMO_TAG_PARAM && !myTazParamKeys.empty()) {
71  if (attrs.getString(SUMO_ATTR_KEY) == myTazParamKeys[0]) {
74  }
75  if (myTazParamKeys.size() > 1 && attrs.getString(SUMO_ATTR_KEY) == myTazParamKeys[1]) {
78  }
79  }
80 }
81 
82 
83 void
85  if (element == SUMO_TAG_TRIP || element == SUMO_TAG_VEHICLE) {
86  if (myVehicleParameter->fromTaz == "" || myVehicleParameter->toTaz == "") {
87  WRITE_WARNINGF(TL("No origin or no destination given, ignoring '%'!"), myVehicleParameter->id);
88  } else {
89  int quota = getScalingQuota(myScale, myNumLoaded);
90  for (int i = 0; i < quota; i++) {
92  veh.id = i == 0 ? myVehicleParameter->id : myVehicleParameter->id + "." + toString(i);
93  myMatrix.add(veh,
96  }
97  myNumLoaded += 1;
98  }
99  delete myVehicleParameter;
100  }
101 }
102 
103 
104 /****************************************************************************/
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define TL(string)
Definition: MsgHandler.h:315
const int VEHPARS_TO_TAZ_SET
const int VEHPARS_FROM_TAZ_SET
@ SUMO_TAG_VEHICLE
description of a vehicle
@ 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.
Definition: OptionsCont.cpp:60
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.
int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
std::string id
The vehicle's id.
bool wasSet(int what) const
Returns whether the given parameter was set.
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.