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-2018 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 
void addToEdge(const SUMOSAXAttributes &attrs)
Parses the probability to use a certain outgoing edge.
void beginFromEdge(const SUMOSAXAttributes &attrs)
Begins the processing of a incoming edge definition.
Outgoing edge specification (jtrrouter)
ROJTREdge * myEdge
The current incoming edge the turning probabilities are set into.
static const int WHITECHARS
void setSource(const bool isSource=true)
Sets whether the edge is a source.
Definition: ROEdge.h:122
weights: time range begin
void setSink(const bool isSink=true)
Sets whether the edge is a sink.
Definition: ROEdge.h:130
double myIntervalBegin
The begin and the end of the current interval.
SAX-handler base for SUMO-files.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Sink(s) specification.
the edges of a route
Encapsulated SAX-Attributes.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
Incoming edge specification (jtrrouter)
An edge the jtr-router may route through.
Definition: ROJTREdge.h:51
RONet & myNet
The network to set the information into.
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(RONet &net)
Constructor.
A basic edge for routing applications.
Definition: ROEdge.h:72
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:247
The router&#39;s network representation.
Definition: RONet.h:68
#define SUMOTime_MAX
Definition: SUMOTime.h:37
weights: time range end
an aggreagated-output interval
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:157
~ROJTRTurnDefLoader()
Destructor.