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-2016 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 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
51  : SUMOSAXHandler("turn-ratio-file"), myNet(net),
52  myIntervalBegin(0), myIntervalEnd(STEPS2TIME(SUMOTime_MAX)), myEdge(0) {}
53 
54 
56 
57 
58 void
60  const SUMOSAXAttributes& attrs) {
61  bool ok = true;
62  switch (element) {
63  case SUMO_TAG_INTERVAL:
64  myIntervalBegin = attrs.get<double>(SUMO_ATTR_BEGIN, 0, ok);
65  myIntervalEnd = attrs.get<double>(SUMO_ATTR_END, 0, ok);
66  break;
67  case SUMO_TAG_FROMEDGE:
68  beginFromEdge(attrs);
69  break;
70  case SUMO_TAG_TOEDGE:
71  addToEdge(attrs);
72  break;
73  case SUMO_TAG_SINK:
74  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
75  std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, 0, ok);
77  while (st.hasNext()) {
78  std::string id = st.next();
79  ROEdge* edge = myNet.getEdge(id);
80  if (edge == 0) {
81  throw ProcessError("The edge '" + id + "' declared as a sink is not known.");
82  }
83  edge->setFunc(ROEdge::ET_SINK);
84  }
85  }
86  break;
87  case SUMO_TAG_SOURCE:
88  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
89  std::string edges = attrs.get<std::string>(SUMO_ATTR_EDGES, 0, ok);
91  while (st.hasNext()) {
92  std::string id = st.next();
93  ROEdge* edge = myNet.getEdge(id);
94  if (edge == 0) {
95  throw ProcessError("The edge '" + id + "' declared as a source is not known.");
96  }
98  }
99  }
100  break;
101  default:
102  break;
103  }
104 }
105 
106 
107 void
109  myEdge = 0;
110  bool ok = true;
111  // get the id, report an error if not given or empty...
112  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
113  if (!ok) {
114  return;
115  }
116  //
117  myEdge = static_cast<ROJTREdge*>(myNet.getEdge(id));
118  if (myEdge == 0) {
119  WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'from-edge' tag).");
120  return;
121  }
122 }
123 
124 
125 void
127  if (myEdge == 0) {
128  return;
129  }
130  bool ok = true;
131  // get the id, report an error if not given or empty...
132  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
133  if (!ok) {
134  return;
135  }
136  //
137  ROJTREdge* edge = static_cast<ROJTREdge*>(myNet.getEdge(id));
138  if (edge == 0) {
139  WRITE_ERROR("The edge '" + id + "' is not known within the network (within a 'to-edge' tag).");
140  return;
141  }
142  const double probability = attrs.get<double>(SUMO_ATTR_PROB, id.c_str(), ok);
143  if (ok) {
144  if (probability < 0) {
145  WRITE_ERROR("'probability' must be positive (in definition of to-edge '" + id + "').");
146  } else {
148  }
149  }
150 }
151 
152 
153 
154 /****************************************************************************/
155 
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
weights: time range begin
void setFunc(EdgeFunc func)
Sets the function of the edge.
Definition: ROEdge.h:141
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
An edge where vehicles disappear (no vehicle may leave this edge)
Definition: ROEdge.h:91
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.
An edge where vehicles are inserted at (no vehicle may come from back)
Definition: ROEdge.h:89
#define SUMOTime_MAX
Definition: TraCIDefs.h:53
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
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.
void addFollowerProbability(ROJTREdge *follower, double begTime, double endTime, double probability)
adds the information about the percentage of using a certain follower
Definition: ROJTREdge.cpp:67
ROJTRTurnDefLoader(RONet &net)
Constructor.
A basic edge for routing applications.
Definition: ROEdge.h:77
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
The router&#39;s network representation.
Definition: RONet.h:76
weights: time range end
an aggreagated-output interval
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:165
~ROJTRTurnDefLoader()
Destructor.