SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.sourceforge.net/
12 // Copyright (C) 2001-2012 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:
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.getStringReporting(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.getStringReporting(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.getStringReporting(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.getStringReporting(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  SUMOReal probability = attrs.getSUMORealReporting(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