SUMO - Simulation of Urban MObility
ROJTRTurnDefLoader.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Loader for the of turning percentages and source/sink definitions
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <set>
34 #include <string>
36 #include <utils/xml/XMLSubSys.h>
40 #include <utils/common/ToString.h>
42 #include <router/RONet.h>
43 #include "ROJTREdge.h"
44 #include "ROJTRTurnDefLoader.h"
45 
46 #ifdef CHECK_MEMORY_LEAKS
47 #include <foreign/nvwa/debug_new.h>
48 #endif // CHECK_MEMORY_LEAKS
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
55  : SUMOSAXHandler("turn-ratio-file"), myNet(net),
56  myIntervalBegin(0), myIntervalEnd(SUMOTime_MAX), myEdge(0) {}
57 
58 
60 
61 
62 void
64  const SUMOSAXAttributes& attrs) {
65  bool ok = true;
66  switch (element) {
67  case SUMO_TAG_INTERVAL:
69  myIntervalEnd = attrs.get<SUMOReal>(SUMO_ATTR_END, 0, ok);
70  break;
71  case SUMO_TAG_FROMEDGE:
72  beginFromEdge(attrs);
73  break;
74  case SUMO_TAG_TOEDGE:
75  addToEdge(attrs);
76  break;
77  case SUMO_TAG_SINK:
78  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
79  std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, 0, ok);
81  while (st.hasNext()) {
82  std::string id = st.next();
83  ROEdge* edge = myNet.getEdge(id);
84  if (edge == 0) {
85  throw ProcessError("The edge '" + id + "' declared as a sink is not known.");
86  }
87  edge->setType(ROEdge::ET_SINK);
88  }
89  }
90  break;
91  case SUMO_TAG_SOURCE:
92  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
93  std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, 0, ok);
95  while (st.hasNext()) {
96  std::string id = st.next();
97  ROEdge* edge = myNet.getEdge(id);
98  if (edge == 0) {
99  throw ProcessError("The edge '" + id + "' declared as a source is not known.");
100  }
101  edge->setType(ROEdge::ET_SOURCE);
102  }
103  }
104  break;
105  default:
106  break;
107  }
108 }
109 
110 
111 void
113  myEdge = 0;
114  bool ok = true;
115  // get the id, report an error if not given or empty...
116  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
117  if (!ok) {
118  return;
119  }
120  //
121  myEdge = static_cast<ROJTREdge*>(myNet.getEdge(id));
122  if (myEdge == 0) {
123  WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'from-edge' tag).");
124  return;
125  }
126 }
127 
128 
129 void
131  if (myEdge == 0) {
132  return;
133  }
134  bool ok = true;
135  // get the id, report an error if not given or empty...
136  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
137  if (!ok) {
138  return;
139  }
140  //
141  ROJTREdge* edge = static_cast<ROJTREdge*>(myNet.getEdge(id));
142  if (edge == 0) {
143  WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'to-edge' tag).");
144  return;
145  }
146  const SUMOReal probability = attrs.get<SUMOReal>(SUMO_ATTR_PROB, id.c_str(), ok);
147  if (ok) {
148  if (probability < 0) {
149  WRITE_ERROR("'probability' must be positive (in definition of to-edge '" + id + "').");
150  } else {
152  }
153  }
154 }
155 
156 
157 
158 /****************************************************************************/
159 
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
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:138
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.
An edge where vehicles are inserted at (no vehicle may come from back)
Definition: ROEdge.h:85
void setType(EdgeType type)
Sets the type of te edge.
Definition: ROEdge.cpp:225
the edges of a route
Encapsulated SAX-Attributes.
Incoming edge specification (jtrrouter)
An edge the jtr-router may route through.
Definition: ROJTREdge.h:58
RONet & myNet
The network to set the information into.
ROJTRTurnDefLoader(RONet &net)
Constructor.
A basic edge for routing applications.
Definition: ROEdge.h:73
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
The router's network representation.
Definition: RONet.h:72
SUMOReal myIntervalBegin
The begin and the end of the current interval.
#define SUMOTime_MAX
Definition: SUMOTime.h:44
#define SUMOReal
Definition: config.h:218
An edge where vehicles disappear (no vehicle may leave this edge)
Definition: ROEdge.h:87
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
void addFollowerProbability(ROJTREdge *follower, SUMOReal begTime, SUMOReal endTime, SUMOReal probability)
adds the information about the percentage of using a certain follower
Definition: ROJTREdge.cpp:71
~ROJTRTurnDefLoader()
Destructor.