Eclipse SUMO - Simulation of Urban MObility
ROJTRTurnDefLoader.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Loader for the of turning percentages and source/sink definitions
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <set>
26 #include <string>
28 #include <utils/xml/XMLSubSys.h>
32 #include <utils/common/ToString.h>
34 #include <router/RONet.h>
35 #include "ROJTREdge.h"
36 #include "ROJTRTurnDefLoader.h"
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
43  : SUMOSAXHandler("turn-ratio-file"), myNet(net),
44  myIntervalBegin(0), myIntervalEnd(STEPS2TIME(SUMOTime_MAX)), myEdge(nullptr) {}
45 
46 
48 
49 
50 void
52  const SUMOSAXAttributes& attrs) {
53  bool ok = true;
54  switch (element) {
55  case SUMO_TAG_INTERVAL:
56  myIntervalBegin = attrs.get<double>(SUMO_ATTR_BEGIN, nullptr, ok);
57  myIntervalEnd = attrs.get<double>(SUMO_ATTR_END, nullptr, ok);
58  break;
59  case SUMO_TAG_FROMEDGE:
60  beginFromEdge(attrs);
61  break;
62  case SUMO_TAG_TOEDGE:
63  addToEdge(attrs);
64  break;
65  case SUMO_TAG_SINK:
66  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
67  std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, nullptr, ok);
69  while (st.hasNext()) {
70  std::string id = st.next();
71  ROEdge* edge = myNet.getEdge(id);
72  if (edge == nullptr) {
73  throw ProcessError("The edge '" + id + "' declared as a sink is not known.");
74  }
75  edge->setSink();
76  }
77  }
78  break;
79  case SUMO_TAG_SOURCE:
80  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
81  std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, nullptr, ok);
83  while (st.hasNext()) {
84  std::string id = st.next();
85  ROEdge* edge = myNet.getEdge(id);
86  if (edge == nullptr) {
87  throw ProcessError("The edge '" + id + "' declared as a source is not known.");
88  }
89  edge->setSource();
90  }
91  }
92  break;
93  default:
94  break;
95  }
96 }
97 
98 
99 void
101  myEdge = nullptr;
102  bool ok = true;
103  // get the id, report an error if not given or empty...
104  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
105  if (!ok) {
106  return;
107  }
108  //
109  myEdge = static_cast<ROJTREdge*>(myNet.getEdge(id));
110  if (myEdge == nullptr) {
111  WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'from-edge' tag).");
112  return;
113  }
114 }
115 
116 
117 void
119  if (myEdge == nullptr) {
120  return;
121  }
122  bool ok = true;
123  // get the id, report an error if not given or empty...
124  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
125  if (!ok) {
126  return;
127  }
128  //
129  ROJTREdge* edge = static_cast<ROJTREdge*>(myNet.getEdge(id));
130  if (edge == nullptr) {
131  WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'to-edge' tag).");
132  return;
133  }
134  const double probability = attrs.get<double>(SUMO_ATTR_PROB, id.c_str(), ok);
135  if (ok) {
136  if (probability < 0) {
137  WRITE_ERROR("'probability' must be positive (in definition of to-edge '" + id + "').");
138  } else {
140  }
141  }
142 }
143 
144 
145 
146 /****************************************************************************/
147 
ToString.h
SUMOSAXAttributes::hasAttribute
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
SUMO_TAG_SOURCE
a source
Definition: SUMOXMLDefinitions.h:131
SUMOSAXHandler
SAX-handler base for SUMO-files.
Definition: SUMOSAXHandler.h:41
ROJTRTurnDefLoader::ROJTRTurnDefLoader
ROJTRTurnDefLoader(RONet &net)
Constructor.
Definition: ROJTRTurnDefLoader.cpp:42
RONet::getEdge
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:152
SUMOSAXAttributes::get
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
Definition: SUMOSAXAttributes.h:492
MsgHandler.h
FileHelpers.h
ROJTREdge.h
RONet
The router's network representation.
Definition: RONet.h:63
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
StringTokenizer::WHITECHARS
static const int WHITECHARS
identifier for splitting the given string at all whitespace characters
Definition: StringTokenizer.h:67
ROJTRTurnDefLoader::myStartElement
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Definition: ROJTRTurnDefLoader.cpp:51
ROEdge::setSource
void setSource(const bool isSource=true)
Sets whether the edge is a source.
Definition: ROEdge.h:122
ROJTRTurnDefLoader::myIntervalBegin
double myIntervalBegin
The begin and the end of the current interval.
Definition: ROJTRTurnDefLoader.h:117
ROJTRTurnDefLoader::myEdge
ROJTREdge * myEdge
The current incoming edge the turning probabilities are set into.
Definition: ROJTRTurnDefLoader.h:120
SUMO_ATTR_BEGIN
weights: time range begin
Definition: SUMOXMLDefinitions.h:678
SUMO_ATTR_PROB
Definition: SUMOXMLDefinitions.h:629
ROJTREdge
An edge the jtr-router may route through.
Definition: ROJTREdge.h:50
ROJTRTurnDefLoader::addToEdge
void addToEdge(const SUMOSAXAttributes &attrs)
Parses the probability to use a certain outgoing edge.
Definition: ROJTRTurnDefLoader.cpp:118
RONet.h
StringTokenizer
Definition: StringTokenizer.h:61
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
SUMO_ATTR_EDGES
the edges of a route
Definition: SUMOXMLDefinitions.h:427
ROEdge::setSink
void setSink(const bool isSink=true)
Sets whether the edge is a sink.
Definition: ROEdge.h:130
ProcessError
Definition: UtilExceptions.h:39
UtilExceptions.h
SUMO_TAG_SINK
Sink(s) specification.
Definition: SUMOXMLDefinitions.h:167
SUMO_TAG_TOEDGE
Outgoing edge specification (jtrrouter)
Definition: SUMOXMLDefinitions.h:165
ROJTRTurnDefLoader::myIntervalEnd
double myIntervalEnd
Definition: ROJTRTurnDefLoader.h:117
StringUtils.h
ROJTREdge::addFollowerProbability
void addFollowerProbability(ROJTREdge *follower, double begTime, double endTime, double probability)
adds the information about the percentage of using a certain follower
Definition: ROJTREdge.cpp:59
ROJTRTurnDefLoader.h
ROEdge
A basic edge for routing applications.
Definition: ROEdge.h:72
config.h
SUMO_ATTR_END
weights: time range end
Definition: SUMOXMLDefinitions.h:680
SUMO_TAG_FROMEDGE
Incoming edge specification (jtrrouter)
Definition: SUMOXMLDefinitions.h:163
SUMO_TAG_INTERVAL
an aggreagated-output interval
Definition: SUMOXMLDefinitions.h:159
SUMOTime_MAX
#define SUMOTime_MAX
Definition: SUMOTime.h:35
ROJTRTurnDefLoader::myNet
RONet & myNet
The network to set the information into.
Definition: ROJTRTurnDefLoader.h:114
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:56
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283
ROJTRTurnDefLoader::beginFromEdge
void beginFromEdge(const SUMOSAXAttributes &attrs)
Begins the processing of a incoming edge definition.
Definition: ROJTRTurnDefLoader.cpp:100
SUMOXMLDefinitions.h
ROJTRTurnDefLoader::~ROJTRTurnDefLoader
~ROJTRTurnDefLoader()
Destructor.
Definition: ROJTRTurnDefLoader.cpp:47
XMLSubSys.h