SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSRouteHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Parser and container for routes during their loading
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <map>
36 #include <vector>
37 #include <microsim/MSRoute.h>
38 #include <microsim/MSEdge.h>
39 #include <microsim/MSJunction.h>
40 #include <microsim/MSVehicleType.h>
41 #include <microsim/MSVehicle.h>
44 #include <microsim/MSLane.h>
45 #include "MSRouteHandler.h"
46 #include "MSTransportableControl.h"
54 #include "MSNet.h"
55 
57 #include <microsim/MSGlobals.h>
59 
60 #ifdef CHECK_MEMORY_LEAKS
61 #include <foreign/nvwa/debug_new.h>
62 #endif // CHECK_MEMORY_LEAKS
63 
64 
65 // ===========================================================================
66 // static members
67 // ===========================================================================
69 
70 
71 // ===========================================================================
72 // method definitions
73 // ===========================================================================
74 MSRouteHandler::MSRouteHandler(const std::string& file,
75  bool addVehiclesDirectly) :
76  SUMORouteHandler(file),
77  myActivePlan(0),
78  myActiveContainerPlan(0),
79  myAddVehiclesDirectly(addVehiclesDirectly),
80  myCurrentVTypeDistribution(0),
81  myCurrentRouteDistribution(0) {
82  myActiveRoute.reserve(100);
83 }
84 
85 
87 }
88 
89 void
91  MSTransportable::MSTransportablePlan::iterator i;
92  if (myActivePlan != 0) {
93  for (i = myActivePlan->begin(); i != myActivePlan->end(); i++) {
94  delete *i;
95  }
96  delete myActivePlan;
97  myActivePlan = NULL;
98  }
99  if (myActiveContainerPlan != 0) {
100  for (i = myActiveContainerPlan->begin(); i != myActiveContainerPlan->end(); i++) {
101  delete *i;
102  }
103  delete myActiveContainerPlan;
104  myActivePlan = NULL;
105  }
106 }
107 
108 
109 void
110 MSRouteHandler::parseFromViaTo(std::string element,
111  const SUMOSAXAttributes& attrs) {
112  myActiveRoute.clear();
113  bool useTaz = OptionsCont::getOptions().getBool("with-taz");
115  WRITE_WARNING("Taz usage was requested but no taz present in " + element + " '" + myVehicleParameter->id + "'!");
116  useTaz = false;
117  }
118  bool ok = true;
120  const MSEdge* fromTaz = MSEdge::dictionary(myVehicleParameter->fromTaz + "-source");
121  if (fromTaz == 0) {
122  throw ProcessError("Source taz '" + myVehicleParameter->fromTaz + "' not known for " + element + " '" + myVehicleParameter->id + "'!");
123  } else if (fromTaz->getNumSuccessors() == 0) {
124  throw ProcessError("Source taz '" + myVehicleParameter->fromTaz + "' has no outgoing edges for " + element + " '" + myVehicleParameter->id + "'!");
125  } else {
126  myActiveRoute.push_back(fromTaz);
127  }
128  } else {
129  MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok, "", true),
130  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
131  }
132  if (!attrs.hasAttribute(SUMO_ATTR_VIA) && !attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
133  myInsertStopEdgesAt = (int)myActiveRoute.size();
134  }
135  MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok, "", true),
136  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
137  myVehicleParameter->via = StringTokenizer(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok, "", true)).getVector();
139  const MSEdge* toTaz = MSEdge::dictionary(myVehicleParameter->toTaz + "-sink");
140  if (toTaz == 0) {
141  throw ProcessError("Sink taz '" + myVehicleParameter->toTaz + "' not known for " + element + " '" + myVehicleParameter->id + "'!");
142  } else if (toTaz->getNumPredecessors() == 0) {
143  throw ProcessError("Sink taz '" + myVehicleParameter->toTaz + "' has no incoming edges for " + element + " '" + myVehicleParameter->id + "'!");
144  } else {
145  myActiveRoute.push_back(toTaz);
146  }
147  } else {
148  MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "", true),
149  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
150  }
152  if (myVehicleParameter->routeid == "") {
154  }
155 }
156 
157 
158 void
160  const SUMOSAXAttributes& attrs) {
161  SUMORouteHandler::myStartElement(element, attrs);
162  try {
163  switch (element) {
164  case SUMO_TAG_PERSON:
166  break;
167  case SUMO_TAG_CONTAINER:
169  break;
170  case SUMO_TAG_RIDE: {
171  const std::string pid = myVehicleParameter->id;
172  bool ok = true;
173  MSEdge* from = 0;
174  const std::string desc = attrs.get<std::string>(SUMO_ATTR_LINES, pid.c_str(), ok);
175  StringTokenizer st(desc);
176  std::string bsID = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, 0, ok, "");
177  MSStoppingPlace* bs = 0;
178  MSEdge* to = 0;
179  if (bsID != "") {
180  bs = MSNet::getInstance()->getBusStop(bsID);
181  if (bs == 0) {
182  throw ProcessError("Unknown bus stop '" + bsID + "' for person '" + myVehicleParameter->id + "'.");
183  }
184  to = &bs->getLane().getEdge();
185  }
186  if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
187  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, pid.c_str(), ok);
188  from = MSEdge::dictionary(fromID);
189  if (from == 0) {
190  throw ProcessError("The from edge '" + fromID + "' within a ride of person '" + pid + "' is not known.");
191  }
192  if (!myActivePlan->empty() && &myActivePlan->back()->getDestination() != from) {
193  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + fromID + "!=" + myActivePlan->back()->getDestination().getID() + ").");
194  }
195  if (myActivePlan->empty()) {
197  *from, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
198  }
199  } else if (myActivePlan->empty()) {
200  throw ProcessError("The start edge for person '" + pid + "' is not known.");
201  }
202  if (to == 0) {
203  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, pid.c_str(), ok);
204  to = MSEdge::dictionary(toID);
205  if (to == 0) {
206  throw ProcessError("The to edge '" + toID + "' within a ride of person '" + pid + "' is not known.");
207  }
208  }
209  myActivePlan->push_back(new MSPerson::MSPersonStage_Driving(*to, bs, -NUMERICAL_EPS, st.getVector()));
210  break;
211  }
212  case SUMO_TAG_WALK:
213  try {
214  myActiveRoute.clear();
215  bool ok = true;
216  const SUMOTime duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, 0, ok, -1);
217  if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
218  throw ProcessError("Non-positive walking duration for '" + myVehicleParameter->id + "'.");
219  }
222  // need to check for explicitly set speed since we might have // DEFAULT_VEHTYPE
223  if (vtype != 0 && vtype->wasSet(VTYPEPARS_MAXSPEED_SET)) {
224  speed = vtype->getMaxSpeed();
225  }
226  speed = attrs.getOpt<SUMOReal>(SUMO_ATTR_SPEED, 0, ok, speed);
227  if (speed <= 0) {
228  throw ProcessError("Non-positive walking speed for '" + myVehicleParameter->id + "'.");
229  }
230  SUMOReal departPos = 0;
231  SUMOReal arrivalPos = 0;
232  MSStoppingPlace* bs = 0;
233  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
235  parseWalkPositions(attrs, myVehicleParameter->id, myActiveRoute.front(), myActiveRoute.back(), departPos, arrivalPos, bs, ok);
236  } else {
237  const std::string fromID = attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok, "");
238  const MSEdge* from = fromID != "" || myActivePlan->empty() ? MSEdge::dictionary(fromID) : &myActivePlan->back()->getDestination();
239  if (from == 0) {
240  throw ProcessError("The from edge '" + fromID + "' within a walk of person '" + myVehicleParameter->id + "' is not known.");
241  }
242  const std::string toID = attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "");
243  const MSEdge* to = MSEdge::dictionary(toID);
244  if (toID != "" && to == 0) {
245  throw ProcessError("The to edge '" + toID + "' within a walk of person '" + myVehicleParameter->id + "' is not known.");
246  }
247  parseWalkPositions(attrs, myVehicleParameter->id, from, to, departPos, arrivalPos, bs, ok);
248  MSNet::getInstance()->getPedestrianRouter().compute(from, to, departPos, arrivalPos,
249  speed, 0, 0, myActiveRoute);
250  if (myActiveRoute.empty()) {
251  const std::string error = "No connection found between '" + from->getID() + "' and '" + to->getID() + "' for person '" + myVehicleParameter->id + "'.";
253  myActiveRoute.push_back(from);
254  myActiveRoute.push_back(to); // pedestrian will teleport
255  //WRITE_WARNING(error);
256  } else {
257  throw ProcessError(error);
258  }
259  }
260  //std::cout << myVehicleParameter->id << " edges=" << toString(myActiveRoute) << "\n";
261  }
262  if (myActiveRoute.empty()) {
263  throw ProcessError("No edges to walk for person '" + myVehicleParameter->id + "'.");
264  }
265  if (!myActivePlan->empty() && &myActivePlan->back()->getDestination() != myActiveRoute.front()) {
266  if (myActivePlan->back()->getDestinationStop() == 0 || !myActivePlan->back()->getDestinationStop()->hasAccess(myActiveRoute.front())) {
267  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + myActiveRoute.front()->getID() + " != " + myActivePlan->back()->getDestination().getID() + ").");
268  }
269  }
270  if (myActivePlan->empty()) {
272  *myActiveRoute.front(), -1, myVehicleParameter->depart, departPos, "start", true));
273  }
274  myActivePlan->push_back(new MSPerson::MSPersonStage_Walking(myActiveRoute, bs, duration, speed, departPos, arrivalPos));
275  myActiveRoute.clear();
276  } catch (ProcessError&) {
278  throw;
279  }
280  break;
281  case SUMO_TAG_TRANSPORT:
282  try {
283  const std::string containerId = myVehicleParameter->id;
284  bool ok = true;
285  MSEdge* from = 0;
286  const std::string desc = attrs.get<std::string>(SUMO_ATTR_LINES, containerId.c_str(), ok);
287  StringTokenizer st(desc);
288  std::string csID = attrs.getOpt<std::string>(SUMO_ATTR_CONTAINER_STOP, 0, ok, "");
289  MSStoppingPlace* cs = 0;
290  if (csID != "") {
291  cs = MSNet::getInstance()->getContainerStop(csID);
292  if (cs == 0) {
293  throw ProcessError("Unknown container stop '" + csID + "' for container '" + myVehicleParameter->id + "'.");
294  }
295  }
296  if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
297  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, containerId.c_str(), ok);
298  from = MSEdge::dictionary(fromID);
299  if (from == 0) {
300  throw ProcessError("The from edge '" + fromID + "' within a transport of container '" + containerId + "' is not known.");
301  }
302  if (!myActiveContainerPlan->empty() && &myActiveContainerPlan->back()->getDestination() != from) {
303  throw ProcessError("Disconnected plan for container '" + myVehicleParameter->id + "' (" + fromID + "!=" + myActiveContainerPlan->back()->getDestination().getID() + ").");
304  }
305  if (myActiveContainerPlan->empty()) {
307  *from, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
308  }
309  } else if (myActiveContainerPlan->empty()) {
310  throw ProcessError("The start edge within a transport of container '" + containerId + "' is not known.");
311  }
312  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, containerId.c_str(), ok);
313  MSEdge* to = MSEdge::dictionary(toID);
314  if (to == 0) {
315  throw ProcessError("The to edge '" + toID + "' within a transport of container '" + containerId + "' is not known.");
316  }
317  myActiveContainerPlan->push_back(new MSContainer::MSContainerStage_Driving(*to, cs, -NUMERICAL_EPS, st.getVector()));
318 
319  } catch (ProcessError&) {
321  throw;
322  }
323  break;
324  case SUMO_TAG_TRANSHIP: {
325  myActiveRoute.clear();
326  bool ok = true;
327  SUMOReal departPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_DEPARTPOS, myVehicleParameter->id.c_str(), ok, 0);
328  SUMOReal arrivalPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ARRIVALPOS, myVehicleParameter->id.c_str(), ok, -NUMERICAL_EPS);
331  // need to check for explicitly set speed since we might have // DEFAULT_VEHTYPE
332  if (vtype != 0 && vtype->wasSet(VTYPEPARS_MAXSPEED_SET)) {
333  speed = vtype->getMaxSpeed();
334  }
335  speed = attrs.getOpt<SUMOReal>(SUMO_ATTR_SPEED, 0, ok, speed);
336  if (speed <= 0) {
337  throw ProcessError("Non-positive tranship speed for container '" + myVehicleParameter->id + "'.");
338  }
339  std::string csID = attrs.getOpt<std::string>(SUMO_ATTR_CONTAINER_STOP, 0, ok, "");
340  MSStoppingPlace* cs = 0;
341  if (csID != "") {
342  cs = MSNet::getInstance()->getContainerStop(csID);
343  if (cs == 0) {
344  throw ProcessError("Unknown container stop '" + csID + "' for container '" + myVehicleParameter->id + "'.");
345  }
346  arrivalPos = cs->getEndLanePosition();
347  }
348  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
350  } else {
351  if (attrs.hasAttribute(SUMO_ATTR_FROM) && attrs.hasAttribute(SUMO_ATTR_TO)) {
352  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok);
353  MSEdge* from = MSEdge::dictionary(fromID);
354  if (from == 0) {
355  throw ProcessError("The from edge '" + fromID + "' within a tranship of container '" + myVehicleParameter->id + "' is not known.");
356  }
357  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok);
358  MSEdge* to = MSEdge::dictionary(toID);
359  if (to == 0) {
360  throw ProcessError("The to edge '" + toID + "' within a tranship of container '" + myVehicleParameter->id + "' is not known.");
361  }
362  //the route of the container's tranship stage consists only of the 'from' and the 'to' edge
363  myActiveRoute.push_back(from);
364  myActiveRoute.push_back(to);
365  if (myActiveRoute.empty()) {
366  const std::string error = "No connection found between '" + from->getID() + "' and '" + to->getID() + "' for container '" + myVehicleParameter->id + "'.";
368  myActiveRoute.push_back(from);
369  } else {
370  WRITE_ERROR(error);
371  }
372  }
373  }
374  }
375  if (myActiveRoute.empty()) {
376  throw ProcessError("No edges to tranship container '" + myVehicleParameter->id + "'.");
377  }
378  if (!myActiveContainerPlan->empty() && &myActiveContainerPlan->back()->getDestination() != myActiveRoute.front()) {
379  throw ProcessError("Disconnected plan for container '" + myVehicleParameter->id + "' (" + myActiveRoute.front()->getID() + "!=" + myActiveContainerPlan->back()->getDestination().getID() + ").");
380  }
381  if (myActiveContainerPlan->empty()) {
383  *myActiveRoute.front(), -1, myVehicleParameter->depart, departPos, "start", true));
384  }
385  myActiveContainerPlan->push_back(new MSContainer::MSContainerStage_Tranship(myActiveRoute, cs, speed, departPos, arrivalPos));
386  myActiveRoute.clear();
387  break;
388  }
389  case SUMO_TAG_FLOW:
390  parseFromViaTo("flow", attrs);
391  break;
392  case SUMO_TAG_TRIP:
393  parseFromViaTo("trip", attrs);
394  break;
395  default:
396  break;
397  }
398  // parse embedded vtype information
399  if (myCurrentVType != 0 && element != SUMO_TAG_VTYPE && element != SUMO_TAG_PARAM) {
401  return;
402  }
403  } catch (ProcessError&) {
404  delete myVehicleParameter;
405  myVehicleParameter = 0;
406  throw;
407  }
408 }
409 
410 
411 void
413  bool ok = true;
414  myCurrentVTypeDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
415  if (ok) {
417  if (attrs.hasAttribute(SUMO_ATTR_VTYPES)) {
418  const std::string vTypes = attrs.get<std::string>(SUMO_ATTR_VTYPES, myCurrentVTypeDistributionID.c_str(), ok);
419  StringTokenizer st(vTypes);
420  while (st.hasNext()) {
421  std::string vtypeID = st.next();
423  if (type == 0) {
424  throw ProcessError("Unknown vtype '" + vtypeID + "' in distribution '" + myCurrentVTypeDistributionID + "'.");
425  }
427  }
428  }
429  }
430 }
431 
432 
433 void
435  if (myCurrentVTypeDistribution != 0) {
436  if (MSGlobals::gStateLoaded && MSNet::getInstance()->getVehicleControl().hasVTypeDistribution(myCurrentVTypeDistributionID)) {
438  return;
439  }
442  throw ProcessError("Vehicle type distribution '" + myCurrentVTypeDistributionID + "' is empty.");
443  }
444  if (!MSNet::getInstance()->getVehicleControl().addVTypeDistribution(myCurrentVTypeDistributionID, myCurrentVTypeDistribution)) {
446  throw ProcessError("Another vehicle type (or distribution) with the id '" + myCurrentVTypeDistributionID + "' exists.");
447  }
449  }
450 }
451 
452 
453 void
455  myActiveRoute.clear();
456  myInsertStopEdgesAt = -1;
457  // check whether the id is really necessary
458  std::string rid;
459  if (myCurrentRouteDistribution != 0) {
461  rid = "distribution '" + myCurrentRouteDistributionID + "'";
462  } else if (myVehicleParameter != 0) {
463  // ok, a vehicle is wrapping the route,
464  // we may use this vehicle's id as default
465  myActiveRouteID = "!" + myVehicleParameter->id; // !!! document this
466  if (attrs.hasAttribute(SUMO_ATTR_ID)) {
467  WRITE_WARNING("Ids of internal routes are ignored (vehicle '" + myVehicleParameter->id + "').");
468  }
469  } else {
470  bool ok = true;
471  myActiveRouteID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok, false);
472  if (!ok) {
473  return;
474  }
475  rid = "'" + myActiveRouteID + "'";
476  }
477  if (myVehicleParameter != 0) { // have to do this here for nested route distributions
478  rid = "for vehicle '" + myVehicleParameter->id + "'";
479  }
480  bool ok = true;
481  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
482  MSEdge::parseEdgesList(attrs.get<std::string>(SUMO_ATTR_EDGES, myActiveRouteID.c_str(), ok), myActiveRoute, rid);
483  }
484  myActiveRouteRefID = attrs.getOpt<std::string>(SUMO_ATTR_REFID, myActiveRouteID.c_str(), ok, "");
486  WRITE_ERROR("Invalid reference to route '" + myActiveRouteRefID + "' in route " + rid + ".");
487  }
490  myCurrentCosts = attrs.getOpt<SUMOReal>(SUMO_ATTR_COST, myActiveRouteID.c_str(), ok, -1);
491  if (ok && myCurrentCosts != -1 && myCurrentCosts < 0) {
492  WRITE_ERROR("Invalid cost for route '" + myActiveRouteID + "'.");
493  }
494 }
495 
496 
497 void
500  switch (element) {
501  case SUMO_TAG_VTYPE: {
503  delete myCurrentVType;
504  myCurrentVType = 0;
505  if (!MSNet::getInstance()->getVehicleControl().addVType(vehType)) {
506  const std::string id = vehType->getID();
507  delete vehType;
509  throw ProcessError("Another vehicle type (or distribution) with the id '" + id + "' exists.");
510  }
511  } else {
512  if (myCurrentVTypeDistribution != 0) {
514  }
515  }
516  }
517  break;
518  case SUMO_TAG_TRIP:
520  closeRoute(true);
521  closeVehicle();
522  delete myVehicleParameter;
523  myVehicleParameter = 0;
524  myInsertStopEdgesAt = -1;
525  break;
526  default:
527  break;
528  }
529 }
530 
531 
532 void
533 MSRouteHandler::closeRoute(const bool mayBeDisconnected) {
534  std::string type = "vehicle";
535  if (mayBeDisconnected) {
537  type = "flow";
538  } else {
539  type = "trip";
540  }
541  }
542 
543  try {
544  if (myActiveRoute.size() == 0) {
545  delete myActiveRouteColor;
546  myActiveRouteColor = 0;
549  if (route != 0) {
551  route->addReference();
552  }
553  }
554  myActiveRouteID = "";
555  myActiveRouteRefID = "";
556  return;
557  }
558  if (myVehicleParameter != 0) {
559  throw ProcessError("The route for " + type + " '" + myVehicleParameter->id + "' has no edges.");
560  } else {
561  throw ProcessError("Route '" + myActiveRouteID + "' has no edges.");
562  }
563  }
564  if (myActiveRoute.size() == 1 && myActiveRoute.front()->getPurpose() == MSEdge::EDGEFUNCTION_DISTRICT) {
565  throw ProcessError("The routing information for " + type + " '" + myVehicleParameter->id + "' is insufficient.");
566  }
570  route->setCosts(myCurrentCosts);
571  myActiveRoute.clear();
572  if (!MSRoute::dictionary(myActiveRouteID, route)) {
573  delete route;
575  if (myVehicleParameter != 0) {
576  if (MSNet::getInstance()->getVehicleControl().getVehicle(myVehicleParameter->id) == 0) {
577  throw ProcessError("Another route for " + type + " '" + myVehicleParameter->id + "' exists.");
578  } else {
579  throw ProcessError("A vehicle with id '" + myVehicleParameter->id + "' already exists.");
580  }
581  } else {
582  throw ProcessError("Another route (or distribution) with the id '" + myActiveRouteID + "' exists.");
583  }
584  }
585  } else {
586  if (myCurrentRouteDistribution != 0) {
588  route->addReference();
589  }
590  }
591  }
592  myActiveRouteID = "";
593  myActiveRouteColor = 0;
594  myActiveRouteStops.clear();
595  } catch (ProcessError&) {
596  delete myVehicleParameter;
597  throw;
598  }
599 }
600 
601 
602 void
604  // check whether the id is really necessary
605  bool ok = true;
606  if (myVehicleParameter != 0) {
607  // ok, a vehicle is wrapping the route,
608  // we may use this vehicle's id as default
609  myCurrentRouteDistributionID = "!" + myVehicleParameter->id; // !!! document this
610  } else {
611  myCurrentRouteDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
612  if (!ok) {
613  return;
614  }
615  }
617  std::vector<SUMOReal> probs;
618  if (attrs.hasAttribute(SUMO_ATTR_PROBS)) {
619  bool ok = true;
620  StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_PROBS, myCurrentRouteDistributionID.c_str(), ok));
621  while (st.hasNext()) {
622  probs.push_back(TplConvert::_2SUMORealSec(st.next().c_str(), 1.0));
623  }
624  }
625  if (attrs.hasAttribute(SUMO_ATTR_ROUTES)) {
626  bool ok = true;
627  StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_ROUTES, myCurrentRouteDistributionID.c_str(), ok));
628  int probIndex = 0;
629  while (st.hasNext()) {
630  std::string routeID = st.next();
631  const MSRoute* route = MSRoute::dictionary(routeID, &myParsingRNG);
632  if (route == 0) {
633  throw ProcessError("Unknown route '" + routeID + "' in distribution '" + myCurrentRouteDistributionID + "'.");
634  }
635  const SUMOReal prob = ((int)probs.size() > probIndex ? probs[probIndex] : 1.0);
636  if (myCurrentRouteDistribution->add(prob, route, false)) {
637  route->addReference();
638  }
639  probIndex++;
640  }
641  if (probs.size() > 0 && probIndex != (int)probs.size()) {
642  WRITE_WARNING("Got " + toString(probs.size()) + " probabilities for " + toString(probIndex) +
643  " routes in routeDistribution '" + myCurrentRouteDistributionID + "'");
644  }
645  }
646 }
647 
648 
649 void
651  if (myCurrentRouteDistribution != 0) {
652  const bool haveSameID = MSRoute::dictionary(myCurrentRouteDistributionID, &myParsingRNG) != 0;
653  if (MSGlobals::gStateLoaded && haveSameID) {
655  return;
656  }
657  if (haveSameID) {
659  throw ProcessError("Another route (or distribution) with the id '" + myCurrentRouteDistributionID + "' exists.");
660  }
663  throw ProcessError("Route distribution '" + myCurrentRouteDistributionID + "' is empty.");
664  }
667  }
668 }
669 
670 
671 void
673  // get nested route
677  // let's check whether this vehicle had to depart before the simulation starts
679  if (route != 0) {
680  route->addReference();
681  route->release();
682  }
683  return;
684  }
685  }
686 
687  // get the vehicle's type
688  MSVehicleType* vtype = 0;
689 
690  try {
691  if (myVehicleParameter->vtypeid != "") {
692  vtype = vehControl.getVType(myVehicleParameter->vtypeid, &myParsingRNG);
693  if (vtype == 0) {
694  throw ProcessError("The vehicle type '" + myVehicleParameter->vtypeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
695  }
696  } else {
697  // there should be one (at least the default one)
698  vtype = vehControl.getVType(DEFAULT_VTYPE_ID, &myParsingRNG);
699  }
700  if (route == 0) {
701  // if there is no nested route, try via the (hopefully) given route-id
703  }
704  if (route == 0) {
705  // nothing found? -> error
706  if (myVehicleParameter->routeid != "") {
707  throw ProcessError("The route '" + myVehicleParameter->routeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
708  } else {
709  throw ProcessError("Vehicle '" + myVehicleParameter->id + "' has no route.");
710  }
711  }
712  myActiveRouteID = "";
713 
714  } catch (ProcessError&) {
715  delete myVehicleParameter;
716  throw;
717  }
718 
719  // try to build the vehicle
720  SUMOVehicle* vehicle = 0;
721  if (vehControl.getVehicle(myVehicleParameter->id) == 0) {
722  try {
723  vehicle = vehControl.buildVehicle(myVehicleParameter, route, vtype, !MSGlobals::gCheckRoutes);
724  } catch (const ProcessError& e) {
726  WRITE_WARNING(e.what());
727  vehControl.deleteVehicle(0, true);
728  myVehicleParameter = 0;
729  vehicle = 0;
730  return;
731  } else {
732  throw e;
733  }
734  }
735  // maybe we do not want this vehicle to be inserted due to scaling
736  int quota = vehControl.getQuota();
737  if (quota > 0) {
738  vehControl.addVehicle(myVehicleParameter->id, vehicle);
740  const MSEdge* const firstEdge = vehicle->getRoute().getEdges()[0];
741  if (!MSGlobals::gUseMesoSim) {
742  // position will be checked against person position later
743  static_cast<MSVehicle*>(vehicle)->setTentativeLaneAndPosition(firstEdge->getLanes()[0], myVehicleParameter->departPos);
744  }
745  vehControl.addWaiting(*route->begin(), vehicle);
746  vehControl.registerOneWaitingForPerson();
748  const MSEdge* const firstEdge = vehicle->getRoute().getEdges()[0];
749  if (!MSGlobals::gUseMesoSim) {
750  // position will be checked against container position later
751  static_cast<MSVehicle*>(vehicle)->setTentativeLaneAndPosition(firstEdge->getLanes()[0], myVehicleParameter->departPos);
752  }
753  vehControl.addWaiting(*route->begin(), vehicle);
754  vehControl.registerOneWaitingForContainer();
755  } else {
756  // !!! no upscaling for triggered vehicles yet
757  for (int i = 1; i < quota; i++) {
760  newPars->id = myVehicleParameter->id + "." + toString(i);
761  vehicle = vehControl.buildVehicle(newPars, route, vtype, !MSGlobals::gCheckRoutes);
762  vehControl.addVehicle(newPars->id, vehicle);
763  }
764  }
766  myVehicleParameter = 0;
767  } else {
768  vehControl.deleteVehicle(vehicle, true);
769  myVehicleParameter = 0;
770  vehicle = 0;
771  }
772  } else {
773  // strange: another vehicle with the same id already exists
775  // and was not loaded while loading a simulation state
776  // -> error
777  std::string veh_id = myVehicleParameter->id;
778  delete myVehicleParameter;
779  myVehicleParameter = 0;
780  throw ProcessError("Another vehicle with the id '" + veh_id + "' exists.");
781  } else {
782  // ok, it seems to be loaded previously while loading a simulation state
783  vehicle = 0;
784  }
785  }
786  // check whether the vehicle shall be added directly to the network or
787  // shall stay in the internal buffer
788  if (vehicle != 0) {
789  if (vehicle->getParameter().departProcedure == DEPART_GIVEN) {
791  }
792  }
793 }
794 
795 
796 void
799  try {
800  if (myActivePlan->size() == 0) {
801  throw ProcessError("Person '" + myVehicleParameter->id + "' has no plan.");
802  }
803  if (type == 0) {
804  throw ProcessError("The type '" + myVehicleParameter->vtypeid + "' for person '" + myVehicleParameter->id + "' is not known.");
805  }
806  } catch (ProcessError&) {
807  delete myVehicleParameter;
808  myVehicleParameter = 0;
810  throw;
811  }
813  // @todo: consider myScale?
815  if (MSNet::getInstance()->getPersonControl().add(person)) {
817  } else {
818  ProcessError error("Another person with the id '" + myVehicleParameter->id + "' exists.");
819  delete person;
820  throw error;
821  }
822  } else {
823  // warning already given
824  delete person;
825  }
826  myVehicleParameter = 0;
827  myActivePlan = 0;
828 }
829 
830 void
832  if (myActiveContainerPlan->size() == 0) {
833  throw ProcessError("Container '" + myVehicleParameter->id + "' has no plan.");
834  }
836  if (type == 0) {
837  throw ProcessError("The type '" + myVehicleParameter->vtypeid + "' for container '" + myVehicleParameter->id + "' is not known.");
838  }
840  // @todo: consider myScale?
842  if (MSNet::getInstance()->getContainerControl().add(container)) {
844  } else {
845  ProcessError error("Another container with the id '" + myVehicleParameter->id + "' exists.");
846  delete container;
847  throw error;
848  }
849  } else {
850  // warning already given
851  delete container;
852  }
853  myVehicleParameter = 0;
855 }
856 
857 void
860  return;
861  }
862  // let's check whether vehicles had to depart before the simulation starts
865  const SUMOTime offsetToBegin = string2time(OptionsCont::getOptions().getString("begin")) - myVehicleParameter->depart;
869  return;
870  }
871  }
872  }
873  if (MSNet::getInstance()->getVehicleControl().getVType(myVehicleParameter->vtypeid, &myParsingRNG) == 0) {
874  throw ProcessError("The vehicle type '" + myVehicleParameter->vtypeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
875  }
878  closeRoute(true);
879  }
881  throw ProcessError("The route '" + myVehicleParameter->routeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
882  }
883  myActiveRouteID = "";
884 
885  // check whether the vehicle shall be added directly to the network or
886  // shall stay in the internal buffer
888  if (MSNet::getInstance()->getInsertionControl().add(myVehicleParameter)) {
890  } else {
891  throw ProcessError("Another flow with the id '" + myVehicleParameter->id + "' exists.");
892  }
893  }
894  myVehicleParameter = 0;
895  myInsertStopEdgesAt = -1;
896 }
897 
898 
899 void
901  std::string errorSuffix;
902  if (myActivePlan != 0) {
903  errorSuffix = " in person '" + myVehicleParameter->id + "'.";
904  } else if (myVehicleParameter != 0) {
905  errorSuffix = " in vehicle '" + myVehicleParameter->id + "'.";
906  } else if (myActiveContainerPlan != 0) {
907  errorSuffix = " in container '" + myVehicleParameter->id + "'.";
908  } else {
909  errorSuffix = " in route '" + myActiveRouteID + "'.";
910  }
912  bool ok = parseStop(stop, attrs, errorSuffix, MsgHandler::getErrorInstance());
913  if (!ok) {
914  return;
915  }
916  const MSEdge* edge = 0;
917  // try to parse the assigned bus stop
918  if (stop.busstop != "") {
919  // ok, we have a bus stop
921  if (bs == 0) {
922  WRITE_ERROR("The bus stop '" + stop.busstop + "' is not known" + errorSuffix);
923  return;
924  }
925  const MSLane& l = bs->getLane();
926  stop.lane = l.getID();
927  stop.endPos = bs->getEndLanePosition();
928  stop.startPos = bs->getBeginLanePosition();
929  edge = &l.getEdge();
930  } //try to parse the assigned container stop
931  else if (stop.containerstop != "") {
932  // ok, we have obviously a container stop
934  if (cs == 0) {
935  WRITE_ERROR("The container stop '" + stop.containerstop + "' is not known" + errorSuffix);
936  return;
937  }
938  const MSLane& l = cs->getLane();
939  stop.lane = l.getID();
940  stop.endPos = cs->getEndLanePosition();
941  stop.startPos = cs->getBeginLanePosition();
942  edge = &l.getEdge();
943  } else if (stop.chargingStation != "") {
944  // ok, we have a charging station
946  if (cs != 0) {
947  const MSLane& l = cs->getLane();
948  stop.lane = l.getID();
949  stop.endPos = cs->getEndLanePosition();
950  stop.startPos = cs->getBeginLanePosition();
951  } else {
952  WRITE_ERROR("The charging station '" + stop.chargingStation + "' is not known" + errorSuffix);
953  return;
954  }
955  } else {
956  // no, the lane and the position should be given
957  // get the lane
958  stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, "");
959  if (ok && stop.lane != "") {
960  if (MSLane::dictionary(stop.lane) == 0) {
961  WRITE_ERROR("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix);
962  return;
963  }
964  } else {
965  if (myActivePlan && !myActivePlan->empty()) {
966  const MSStoppingPlace* bs = myActivePlan->back()->getDestinationStop();
967  if (bs != 0) {
968  edge = &bs->getLane().getEdge();
969  stop.lane = bs->getLane().getID();
970  stop.endPos = bs->getEndLanePosition();
971  stop.startPos = bs->getBeginLanePosition();
972  } else {
973  edge = &myActivePlan->back()->getDestination();
974  stop.lane = edge->getLanes()[0]->getID();
975  stop.endPos = myActivePlan->back()->getArrivalPos();
976  stop.startPos = stop.endPos - POSITION_EPS;
977  }
978  } else {
979  WRITE_ERROR("A stop must be placed on a bus stop, a charging station, a container stop or a lane" + errorSuffix);
980  return;
981  }
982  }
983  edge = &MSLane::dictionary(stop.lane)->getEdge();
984  if (myActivePlan &&
985  !myActivePlan->empty() &&
986  &myActivePlan->back()->getDestination() != edge) {
987  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + edge->getID() + "!=" + myActivePlan->back()->getDestination().getID() + ").");
988  }
989  if (myActivePlan && myActivePlan->empty()) {
991  *edge, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
992  }
993  if (myActiveContainerPlan &&
994  !myActiveContainerPlan->empty() &&
995  &myActiveContainerPlan->back()->getDestination() != &MSLane::dictionary(stop.lane)->getEdge()) {
996  throw ProcessError("Disconnected plan for container '" + myVehicleParameter->id + "' (" + MSLane::dictionary(stop.lane)->getEdge().getID() + "!=" + myActiveContainerPlan->back()->getDestination().getID() + ").");
997  }
1000  MSLane::dictionary(stop.lane)->getEdge(), -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
1001  }
1002  stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ENDPOS, 0, ok, MSLane::dictionary(stop.lane)->getLength());
1003  if (attrs.hasAttribute(SUMO_ATTR_POSITION)) {
1004  WRITE_WARNING("Deprecated attribute 'pos' in description of stop" + errorSuffix);
1005  stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_POSITION, 0, ok, stop.endPos);
1006  }
1007  stop.startPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_STARTPOS, 0, ok, MAX2((SUMOReal)0., stop.endPos - 2 * POSITION_EPS));
1008  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false);
1009  if (!ok || !checkStopPos(stop.startPos, stop.endPos, MSLane::dictionary(stop.lane)->getLength(), POSITION_EPS, friendlyPos)) {
1010  WRITE_ERROR("Invalid start or end position for stop on lane '" + stop.lane + "'" + errorSuffix);
1011  return;
1012  }
1013  }
1014  if (myActivePlan != 0) {
1015  std::string actType = attrs.getOpt<std::string>(SUMO_ATTR_ACTTYPE, 0, ok, "waiting");
1016  SUMOReal pos = (stop.startPos + stop.endPos) / 2.;
1017  if (!myActivePlan->empty()) {
1018  pos = myActivePlan->back()->getArrivalPos();
1019  }
1021  MSLane::dictionary(stop.lane)->getEdge(), stop.duration, stop.until, pos, actType, false));
1022  } else if (myActiveContainerPlan != 0) {
1023  std::string actType = attrs.getOpt<std::string>(SUMO_ATTR_ACTTYPE, 0, ok, "waiting");
1025  MSLane::dictionary(stop.lane)->getEdge(), stop.duration, stop.until, stop.startPos, actType, false));
1026  } else if (myVehicleParameter != 0) {
1027  myVehicleParameter->stops.push_back(stop);
1028  } else {
1029  myActiveRouteStops.push_back(stop);
1030  }
1031  if (myInsertStopEdgesAt >= 0) {
1032  myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
1034  }
1035 }
1036 
1037 
1038 void
1039 MSRouteHandler::parseWalkPositions(const SUMOSAXAttributes& attrs, const std::string& personID,
1040  const MSEdge* fromEdge, const MSEdge*& toEdge,
1041  SUMOReal& departPos, SUMOReal& arrivalPos, MSStoppingPlace*& bs, bool& ok) {
1042  const std::string description = "person '" + personID + "' walking from " + fromEdge->getID();
1043 
1044  departPos = parseWalkPos(SUMO_ATTR_DEPARTPOS, description, fromEdge,
1045  attrs.getOpt<std::string>(SUMO_ATTR_DEPARTPOS, description.c_str(), ok, "0"));
1046 
1047  std::string bsID = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, 0, ok, "");
1048  if (bsID != "") {
1049  bs = MSNet::getInstance()->getBusStop(bsID);
1050  if (bs == 0) {
1051  throw ProcessError("Unknown bus stop '" + bsID + "' for " + description + ".");
1052  }
1053  arrivalPos = bs->getEndLanePosition();
1054  if (toEdge == 0) {
1055  toEdge = &bs->getLane().getEdge();
1056  }
1057  if (!bs->hasAccess(toEdge)) {
1058  throw ProcessError("Bus stop '" + bsID + "' is not connected to arrival edge '" + toEdge->getID() + "' for " + description + ".");
1059  }
1060  arrivalPos = (bs->getBeginLanePosition() + bs->getEndLanePosition()) / 2.;
1061  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
1062  const SUMOReal arrPos = parseWalkPos(SUMO_ATTR_ARRIVALPOS, description, toEdge,
1063  attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok));
1064  if (arrPos >= bs->getBeginLanePosition() && arrPos < bs->getEndLanePosition()) {
1065  arrivalPos = arrPos;
1066  } else {
1067  WRITE_WARNING("Ignoring arrivalPos for " + description + " because it is outside the given stop '" + toString(SUMO_ATTR_BUS_STOP) + "'.");
1068  }
1069  }
1070  } else {
1071  if (toEdge == 0) {
1072  throw ProcessError("No destination edge for " + description + ".");
1073  }
1074  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
1075  arrivalPos = parseWalkPos(SUMO_ATTR_ARRIVALPOS, description, toEdge,
1076  attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok));
1077  } else {
1078  arrivalPos = -NUMERICAL_EPS;
1079  }
1080  }
1081 }
1082 
1083 
1084 SUMOReal
1085 MSRouteHandler::parseWalkPos(SumoXMLAttr attr, const std::string& id, const MSEdge* edge, const std::string& val) {
1086  SUMOReal result;
1087  std::string error;
1088  ArrivalPosDefinition proc;
1089  // only supports 'random' and 'max'
1090  if (!SUMOVehicleParameter::parseArrivalPos(val, toString(SUMO_TAG_WALK), id, result, proc, error)) {
1091  throw ProcessError(error);
1092  }
1093  if (proc == ARRIVAL_POS_RANDOM) {
1094  result = myParsingRNG.rand(edge->getLength());
1095  } else if (proc == ARRIVAL_POS_MAX) {
1096  result = edge->getLength();
1097  }
1098  return SUMOVehicleParameter::interpretEdgePos(result, edge->getLength(), attr, id);
1099 }
1100 
1101 
1102 /****************************************************************************/
The departure is person triggered.
void addStop(const SUMOSAXAttributes &attrs)
Processing of a stop.
const int VTYPEPARS_MAXSPEED_SET
const int VEHPARS_TO_TAZ_SET
MSRouteHandler(const std::string &file, bool addVehiclesDirectly)
standard constructor
bool wasSet(int what) const
Returns whether the given parameter was set.
Definition: MSVehicleType.h:91
SUMOReal repetitionProbability
The probability for emitting a vehicle per second.
virtual MSTransportable * buildPerson(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan) const
Builds a new person.
void addWaiting(const MSEdge *const edge, SUMOVehicle *vehicle)
Adds a vehicle to the list of waiting vehiclse to a given edge.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
SUMOReal myCurrentCosts
The currently parsed route costs.
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:571
double rand()
virtual void myEndElement(int element)
Called when a closing tag occurs.
ConstMSEdgeVector myActiveRoute
The current route.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
SUMOReal getMaxSpeed() const
Get vehicle's maximum speed [m/s].
long long int SUMOTime
Definition: SUMOTime.h:43
const int VEHPARS_FORCE_REROUTE
const SUMOReal DEFAULT_CONTAINER_TRANSHIP_SPEED
void parseFromViaTo(std::string element, const SUMOSAXAttributes &attrs)
Called for parsing from and to and the corresponding taz attributes.
RandomDistributor< const MSRoute * > * myCurrentRouteDistribution
The currently parsed distribution of routes (probability->route)
const std::vector< SUMOReal > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
The time is given.
std::string next()
std::string containerstop
(Optional) container stop if one is assigned to the stop
int repetitionNumber
The number of times the vehicle shall be repeatedly inserted.
std::string vtypeid
The vehicle's type id.
int getQuota(SUMOReal frac=-1) const
Returns the number of instances of the current vehicle that shall be emitted considering that "frac" ...
void closeVehicle()
Ends the processing of a vehicle.
static bool parseArrivalPos(const std::string &val, const std::string &element, const std::string &id, SUMOReal &pos, ArrivalPosDefinition &apd, std::string &error)
Validates a given arrivalPos value.
static MTRand myParsingRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
static void parseVTypeEmbedded(SUMOVTypeParameter &into, int element, const SUMOSAXAttributes &attrs, bool fromVType=false)
Parses an element embedded in vtype definition.
virtual const MSRoute & getRoute() const =0
Returns the current route.
bool compute(const E *from, const E *to, SUMOReal departPos, SUMOReal arrivalPos, SUMOReal speed, SUMOTime msTime, const N *onlyNode, std::vector< const E * > &into, bool allEdges=false)
Builds the route between the given edges using the minimum effort at the given time The definition of...
A lane area vehicles can halt at.
bool myAddVehiclesDirectly
Information whether vehicles shall be directly added to the network or kept within the buffer...
SUMOTime duration
The stopping duration.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:192
SUMOVehicleParameter * myVehicleParameter
Parameter of the current vehicle, trip, person, container or flow.
The departure is container triggered.
bool add(SUMOReal prob, T val, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static bool checkStopPos(SUMOReal &startPos, SUMOReal &endPos, const SUMOReal laneLength, const SUMOReal minLength, const bool friendlyPos)
check start and end position of a stop
static bool gStateLoaded
Information whether a state has been loaded.
Definition: MSGlobals.h:92
SUMOVTypeParameter * myCurrentVType
The currently parsed vehicle type.
void closePerson()
Ends the processing of a person.
int repetitionsDone
The number of times the vehicle was already inserted.
const SUMOReal DEFAULT_PEDESTRIAN_SPEED
void openRoute(const SUMOSAXAttributes &attrs)
MSPedestrianRouterDijkstra & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:894
SUMOReal getEndLanePosition() const
Returns the end position of this stop.
MSChargingStation * getChargingStation(const std::string &id) const
Returns the named charging station.
Definition: MSNet.cpp:837
static SUMOReal _2SUMORealSec(const E *const data, SUMOReal def)
converts a 0-terminated char-type array into the SUMOReal value described by it
Definition: TplConvert.h:348
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
T MAX2(T a, T b)
Definition: StdDefs.h:75
void setCosts(SUMOReal costs)
Sets the costs of the route.
Definition: MSRoute.h:174
const SUMOReal DEFAULT_VEH_PROB
SUMOReal myActiveRouteProbability
The probability of the current route.
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary...
Definition: MSEdge.cpp:673
SUMOTime until
The time at which the vehicle may continue its journey.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void registerLastDepart()
save last depart (only to be used if vehicle is not discarded)
std::string myActiveRouteID
The id of the current route.
int myInsertStopEdgesAt
where stop edges can be inserted into the current route (-1 means no insertion)
const std::string DEFAULT_VTYPE_ID
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
static MSVehicleType * build(SUMOVTypeParameter &from)
Builds the microsim vehicle type described by the given parameter.
void error(const XERCES_CPP_NAMESPACE::SAXParseException &exception)
Handler for XML-errors.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
The car-following model and parameter.
Definition: MSVehicleType.h:74
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
std::string toTaz
The vehicle's destination zone (district)
std::vector< Stop > stops
List of the stops the vehicle will make.
SUMOTime getOptSUMOTimeReporting(int attr, const char *objectid, bool &ok, SUMOTime defaultValue, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:707
static SUMOReal interpretEdgePos(SUMOReal pos, SUMOReal maximumValue, SumoXMLAttr attr, const std::string &id)
Interprets negative edge positions and fits them onto a given edge.
std::string busstop
(Optional) bus stop if one is assigned to the stop
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A road/street connecting two junctions.
Definition: MSEdge.h:80
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
SUMOReal getLength() const
return the length of the edge
Definition: MSEdge.h:591
RandomDistributor< MSVehicleType * > * myCurrentVTypeDistribution
The currently parsed distribution of vehicle types (probability->vehicle type)
const MSLane & getLane() const
Returns the lane this stop is located at.
SUMOReal startPos
The stopping position start.
The edge is a district edge.
Definition: MSEdge.h:99
the edges of a route
MSStoppingPlace * getBusStop(const std::string &id) const
Returns the named bus stop.
Definition: MSNet.cpp:789
void closeRouteDistribution()
std::string routeid
The vehicle's route id.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
static bool gCheckRoutes
Definition: MSGlobals.h:83
Encapsulated SAX-Attributes.
bool wasSet(int what) const
Returns whether the given parameter was set.
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:699
std::string chargingStation
(Optional) charging station if one is assigned to the stop
SUMOReal endPos
The stopping position end.
void deleteActivePlans()
delete already created MSTransportablePlans if error occurs before handing over responsibility to a M...
void closeContainer()
Ends the processing of a container.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:307
void closeVehicleTypeDistribution()
SUMOReal parseWalkPos(SumoXMLAttr attr, const std::string &id, const MSEdge *edge, const std::string &val)
bool hasAccess(const MSEdge *edge) const
checks whether this stop provides access to the given edge
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, const MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true)
Builds a vehicle, increases the number of built vehicles.
SUMOTime depart
The vehicle's departure time.
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:128
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:46
int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:346
#define POSITION_EPS
Definition: config.h:188
std::string fromTaz
The vehicle's origin zone (district)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:103
const int VEHPARS_FROM_TAZ_SET
void registerOneWaitingForPerson()
increases the count of vehicles waiting for a person to allow recogniztion of person related deadlock...
MSTransportable::MSTransportablePlan * myActivePlan
The plan of the current person.
std::string lane
The lane to stop at.
Parser for routes during their loading.
std::vector< std::string > via
List of the via-edges the vehicle must visit.
std::string myCurrentRouteDistributionID
The id of the currently parsed route distribution.
virtual MSTransportable * buildContainer(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan) const
Builds a new container.
std::vector< std::string > getVector()
void parseWalkPositions(const SUMOSAXAttributes &attrs, const std::string &personID, const MSEdge *fromEdge, const MSEdge *&toEdge, SUMOReal &departPos, SUMOReal &arrivalPos, MSStoppingPlace *&bs, bool &ok)
@ brief parse depart- and arrival positions of a walk
void openRouteDistribution(const SUMOSAXAttributes &attrs)
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
virtual void myEndElement(int element)
Called when a closing tag occurs.
SUMOReal getOverallProb() const
Return the sum of the probabilites assigned to the members.
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:1286
void registerOneWaitingForContainer()
increases the count of vehicles waiting for a container to allow recogniztion of container related de...
std::vector< SUMOVehicleParameter::Stop > myActiveRouteStops
List of the stops on the parsed route.
Structure representing possible vehicle parameter.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:360
int setParameter
Information for the router which parameter were set.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
std::string myCurrentVTypeDistributionID
The id of the currently parsed vehicle type distribution.
Definition of vehicle stop (position and duration)
SUMOReal getBeginLanePosition() const
Returns the begin position of this stop.
bool parseStop(SUMOVehicleParameter::Stop &stop, const SUMOSAXAttributes &attrs, std::string errorSuffix, MsgHandler *const errorOutput)
parses attributes common to all stops
SUMOReal getDefaultProbability() const
Get the default probability of this vehicle type.
MSStoppingPlace * getContainerStop(const std::string &id) const
Returns the named container stop.
Definition: MSNet.cpp:813
const std::string & getID() const
Returns the name of the vehicle type.
SUMOReal departPos
(optional) The position the vehicle shall depart from
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
const RGBColor * myActiveRouteColor
The currently parsed route's color.
#define SUMOReal
Definition: config.h:214
ArrivalPosDefinition
Possible ways to choose the arrival position.
#define NUMERICAL_EPS
Definition: config.h:161
virtual ~MSRouteHandler()
standard destructor
void openVehicleTypeDistribution(const SUMOSAXAttributes &attrs)
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
The class responsible for building and deletion of vehicles.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
void release() const
deletes the route if there are no further references to it
Definition: MSRoute.cpp:109
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, MTRand *rng=0)
Returns the named vehicle type or a sample from the named distribution.
int getNumPredecessors() const
Returns the number of edges this edge is connected to.
Definition: MSEdge.h:369
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
static bool gUseMesoSim
Definition: MSGlobals.h:95
bool checkLastDepart()
Checks whether the route file is sorted by departure time if needed.
std::string myActiveRouteRefID
The id of the route the current route references to.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
A color information.
The maximum arrival position is used.
static void parseEdgesList(const std::string &desc, ConstMSEdgeVector &into, const std::string &rid)
Parses the given string assuming it contains a list of edge ids divided by spaces.
Definition: MSEdge.cpp:729
void closeRoute(const bool mayBeDisconnected=false)
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:78
void closeFlow()
Ends the processing of a flow.
MSTransportable::MSTransportablePlan * myActiveContainerPlan
The plan of the current container.
std::string id
The vehicle's id.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:122
The arrival position is chosen randomly.