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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Loader for the of turning percentages and source/sink definitions
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <set>
33 #include <string>
35 #include <utils/xml/XMLSubSys.h>
39 #include <utils/common/ToString.h>
41 #include <router/RONet.h>
42 #include "ROJTREdge.h"
43 #include "ROJTRTurnDefLoader.h"
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
50  : SUMOSAXHandler("turn-ratio-file"), myNet(net),
51  myIntervalBegin(0), myIntervalEnd(STEPS2TIME(SUMOTime_MAX)), myEdge(0) {}
52 
53 
55 
56 
57 void
59  const SUMOSAXAttributes& attrs) {
60  bool ok = true;
61  switch (element) {
62  case SUMO_TAG_INTERVAL:
63  myIntervalBegin = attrs.get<double>(SUMO_ATTR_BEGIN, 0, ok);
64  myIntervalEnd = attrs.get<double>(SUMO_ATTR_END, 0, ok);
65  break;
66  case SUMO_TAG_FROMEDGE:
67  beginFromEdge(attrs);
68  break;
69  case SUMO_TAG_TOEDGE:
70  addToEdge(attrs);
71  break;
72  case SUMO_TAG_SINK:
73  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
74  std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, 0, ok);
76  while (st.hasNext()) {
77  std::string id = st.next();
78  ROEdge* edge = myNet.getEdge(id);
79  if (edge == 0) {
80  throw ProcessError("The edge '" + id + "' declared as a sink is not known.");
81  }
82  edge->setSink();
83  }
84  }
85  break;
86  case SUMO_TAG_SOURCE:
87  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
88  std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, 0, ok);
90  while (st.hasNext()) {
91  std::string id = st.next();
92  ROEdge* edge = myNet.getEdge(id);
93  if (edge == 0) {
94  throw ProcessError("The edge '" + id + "' declared as a source is not known.");
95  }
96  edge->setSource();
97  }
98  }
99  break;
100  default:
101  break;
102  }
103 }
104 
105 
106 void
108  myEdge = 0;
109  bool ok = true;
110  // get the id, report an error if not given or empty...
111  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
112  if (!ok) {
113  return;
114  }
115  //
116  myEdge = static_cast<ROJTREdge*>(myNet.getEdge(id));
117  if (myEdge == 0) {
118  WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'from-edge' tag).");
119  return;
120  }
121 }
122 
123 
124 void
126  if (myEdge == 0) {
127  return;
128  }
129  bool ok = true;
130  // get the id, report an error if not given or empty...
131  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
132  if (!ok) {
133  return;
134  }
135  //
136  ROJTREdge* edge = static_cast<ROJTREdge*>(myNet.getEdge(id));
137  if (edge == 0) {
138  WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'to-edge' tag).");
139  return;
140  }
141  const double probability = attrs.get<double>(SUMO_ATTR_PROB, id.c_str(), ok);
142  if (ok) {
143  if (probability < 0) {
144  WRITE_ERROR("'probability' must be positive (in definition of to-edge '" + id + "').");
145  } else {
147  }
148  }
149 }
150 
151 
152 
153 /****************************************************************************/
154 
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:127
weights: time range begin
void setSink(const bool isSink=true)
Sets whether the edge is a sink.
Definition: ROEdge.h:135
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 SUMOTime_MAX
Definition: TraCIDefs.h:52
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
Incoming edge specification (jtrrouter)
An edge the jtr-router may route through.
Definition: ROJTREdge.h:57
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:66
ROJTRTurnDefLoader(RONet &net)
Constructor.
A basic edge for routing applications.
Definition: ROEdge.h:77
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
The router&#39;s network representation.
Definition: RONet.h:74
weights: time range end
an aggreagated-output interval
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:163
~ROJTRTurnDefLoader()
Destructor.