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 /****************************************************************************/
17 // Loader for the of turning percentages and source/sink definitions
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <set>
27 #include <string>
29 #include <utils/xml/XMLSubSys.h>
33 #include <utils/common/ToString.h>
35 #include <router/RONet.h>
36 #include "ROJTREdge.h"
37 #include "ROJTRTurnDefLoader.h"
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
44  : SUMOSAXHandler("turn-ratio-file"), myNet(net),
45  myIntervalBegin(0), myIntervalEnd(STEPS2TIME(SUMOTime_MAX)), myEdge(nullptr) {}
46 
47 
49 
50 
51 void
53  const SUMOSAXAttributes& attrs) {
54  bool ok = true;
55  switch (element) {
56  case SUMO_TAG_INTERVAL:
57  myIntervalBegin = attrs.get<double>(SUMO_ATTR_BEGIN, nullptr, ok);
58  myIntervalEnd = attrs.get<double>(SUMO_ATTR_END, nullptr, ok);
59  break;
60  case SUMO_TAG_FROMEDGE:
61  beginFromEdge(attrs);
62  break;
63  case SUMO_TAG_TOEDGE:
64  addToEdge(attrs);
65  break;
66  case SUMO_TAG_SINK:
67  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
68  std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, nullptr, ok);
70  while (st.hasNext()) {
71  std::string id = st.next();
72  ROEdge* edge = myNet.getEdge(id);
73  if (edge == nullptr) {
74  throw ProcessError("The edge '" + id + "' declared as a sink is not known.");
75  }
76  edge->setSink();
77  }
78  }
79  break;
80  case SUMO_TAG_SOURCE:
81  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
82  std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, nullptr, ok);
84  while (st.hasNext()) {
85  std::string id = st.next();
86  ROEdge* edge = myNet.getEdge(id);
87  if (edge == nullptr) {
88  throw ProcessError("The edge '" + id + "' declared as a source is not known.");
89  }
90  edge->setSource();
91  }
92  }
93  break;
94  default:
95  break;
96  }
97 }
98 
99 
100 void
102  myEdge = nullptr;
103  bool ok = true;
104  // get the id, report an error if not given or empty...
105  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
106  if (!ok) {
107  return;
108  }
109  //
110  myEdge = static_cast<ROJTREdge*>(myNet.getEdge(id));
111  if (myEdge == nullptr) {
112  WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'from-edge' tag).");
113  return;
114  }
115 }
116 
117 
118 void
120  if (myEdge == nullptr) {
121  return;
122  }
123  bool ok = true;
124  // get the id, report an error if not given or empty...
125  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
126  if (!ok) {
127  return;
128  }
129  //
130  ROJTREdge* edge = static_cast<ROJTREdge*>(myNet.getEdge(id));
131  if (edge == nullptr) {
132  WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'to-edge' tag).");
133  return;
134  }
135  const double probability = attrs.get<double>(SUMO_ATTR_PROB, id.c_str(), ok);
136  if (ok) {
137  if (probability < 0) {
138  WRITE_ERROR("'probability' must be positive (in definition of to-edge '" + id + "').");
139  } else {
141  }
142  }
143 }
144 
145 
146 
147 /****************************************************************************/
148 
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:132
SUMOSAXHandler
SAX-handler base for SUMO-files.
Definition: SUMOSAXHandler.h:42
ROJTRTurnDefLoader::ROJTRTurnDefLoader
ROJTRTurnDefLoader(RONet &net)
Constructor.
Definition: ROJTRTurnDefLoader.cpp:43
RONet::getEdge
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:153
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:493
MsgHandler.h
FileHelpers.h
ROJTREdge.h
RONet
The router's network representation.
Definition: RONet.h:64
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
StringTokenizer::WHITECHARS
static const int WHITECHARS
identifier for splitting the given string at all whitespace characters
Definition: StringTokenizer.h:68
ROJTRTurnDefLoader::myStartElement
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Definition: ROJTRTurnDefLoader.cpp:52
ROEdge::setSource
void setSource(const bool isSource=true)
Sets whether the edge is a source.
Definition: ROEdge.h:123
ROJTRTurnDefLoader::myIntervalBegin
double myIntervalBegin
The begin and the end of the current interval.
Definition: ROJTRTurnDefLoader.h:118
ROJTRTurnDefLoader::myEdge
ROJTREdge * myEdge
The current incoming edge the turning probabilities are set into.
Definition: ROJTRTurnDefLoader.h:121
SUMO_ATTR_BEGIN
weights: time range begin
Definition: SUMOXMLDefinitions.h:675
SUMO_ATTR_PROB
Definition: SUMOXMLDefinitions.h:627
ROJTREdge
An edge the jtr-router may route through.
Definition: ROJTREdge.h:51
ROJTRTurnDefLoader::addToEdge
void addToEdge(const SUMOSAXAttributes &attrs)
Parses the probability to use a certain outgoing edge.
Definition: ROJTRTurnDefLoader.cpp:119
RONet.h
StringTokenizer
Definition: StringTokenizer.h:62
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
SUMO_ATTR_EDGES
the edges of a route
Definition: SUMOXMLDefinitions.h:428
ROEdge::setSink
void setSink(const bool isSink=true)
Sets whether the edge is a sink.
Definition: ROEdge.h:131
ProcessError
Definition: UtilExceptions.h:40
UtilExceptions.h
SUMO_TAG_SINK
Sink(s) specification.
Definition: SUMOXMLDefinitions.h:168
SUMO_TAG_TOEDGE
Outgoing edge specification (jtrrouter)
Definition: SUMOXMLDefinitions.h:166
ROJTRTurnDefLoader::myIntervalEnd
double myIntervalEnd
Definition: ROJTRTurnDefLoader.h:118
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:60
ROJTRTurnDefLoader.h
ROEdge
A basic edge for routing applications.
Definition: ROEdge.h:73
config.h
SUMO_ATTR_END
weights: time range end
Definition: SUMOXMLDefinitions.h:677
SUMO_TAG_FROMEDGE
Incoming edge specification (jtrrouter)
Definition: SUMOXMLDefinitions.h:164
SUMO_TAG_INTERVAL
an aggreagated-output interval
Definition: SUMOXMLDefinitions.h:160
SUMOTime_MAX
#define SUMOTime_MAX
Definition: SUMOTime.h:36
ROJTRTurnDefLoader::myNet
RONet & myNet
The network to set the information into.
Definition: ROJTRTurnDefLoader.h:115
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:57
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:245
ROJTRTurnDefLoader::beginFromEdge
void beginFromEdge(const SUMOSAXAttributes &attrs)
Begins the processing of a incoming edge definition.
Definition: ROJTRTurnDefLoader.cpp:101
SUMOXMLDefinitions.h
ROJTRTurnDefLoader::~ROJTRTurnDefLoader
~ROJTRTurnDefLoader()
Destructor.
Definition: ROJTRTurnDefLoader.cpp:48
XMLSubSys.h