SUMO - Simulation of Urban MObility
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 "MSPersonControl.h"
47 #include "MSContainerControl.h"
55 #include "MSNet.h"
56 
58 #include <microsim/MSGlobals.h>
60 
61 #ifdef CHECK_MEMORY_LEAKS
62 #include <foreign/nvwa/debug_new.h>
63 #endif // CHECK_MEMORY_LEAKS
64 
65 
66 // ===========================================================================
67 // static members
68 // ===========================================================================
70 
71 
72 // ===========================================================================
73 // method definitions
74 // ===========================================================================
75 MSRouteHandler::MSRouteHandler(const std::string& file,
76  bool addVehiclesDirectly) :
77  SUMORouteHandler(file),
78  myActivePlan(0),
79  myActiveContainerPlan(0),
80  myAddVehiclesDirectly(addVehiclesDirectly),
81  myCurrentVTypeDistribution(0),
82  myCurrentRouteDistribution(0) {
83  myActiveRoute.reserve(100);
84 }
85 
86 
88 }
89 
90 void
92  MSTransportable::MSTransportablePlan::iterator i;
93  if (myActivePlan != 0) {
94  for (i = myActivePlan->begin(); i != myActivePlan->end(); i++) {
95  delete *i;
96  }
97  delete myActivePlan;
98  myActivePlan = NULL;
99  }
100  if (myActiveContainerPlan != 0) {
101  for (i = myActiveContainerPlan->begin(); i != myActiveContainerPlan->end(); i++) {
102  delete *i;
103  }
104  delete myActiveContainerPlan;
105  myActivePlan = NULL;
106  }
107 }
108 
109 
110 void
111 MSRouteHandler::parseFromViaTo(std::string element,
112  const SUMOSAXAttributes& attrs) {
113  myActiveRoute.clear();
114  bool useTaz = OptionsCont::getOptions().getBool("with-taz");
116  WRITE_WARNING("Taz usage was requested but no taz present in " + element + " '" + myVehicleParameter->id + "'!");
117  useTaz = false;
118  }
119  bool ok = true;
121  const MSEdge* fromTaz = MSEdge::dictionary(myVehicleParameter->fromTaz + "-source");
122  if (fromTaz == 0) {
123  throw ProcessError("Source taz '" + myVehicleParameter->fromTaz + "' not known for " + element + " '" + myVehicleParameter->id + "'!");
124  } else if (fromTaz->getNumSuccessors() == 0) {
125  throw ProcessError("Source taz '" + myVehicleParameter->fromTaz + "' has no outgoing edges for " + element + " '" + myVehicleParameter->id + "'!");
126  } else {
127  myActiveRoute.push_back(fromTaz);
128  }
129  } else {
130  MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok, "", true),
131  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
132  }
133  if (!attrs.hasAttribute(SUMO_ATTR_VIA) && !attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
134  myInsertStopEdgesAt = (int)myActiveRoute.size();
135  }
136  MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok, "", true),
137  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
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"));
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"));
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"));
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"));
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  size_t 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 = (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 != 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  unsigned int quota = vehControl.getQuota();
737  if (quota > 0) {
738  vehControl.addVehicle(myVehicleParameter->id, vehicle);
740  const MSEdge* const firstEdge = vehicle->getRoute().getEdges()[0];
741  static_cast<MSVehicle*>(vehicle)->setTentativeLaneAndPosition(firstEdge->getLanes()[0], myVehicleParameter->departPos);
742  vehControl.addWaiting(*route->begin(), vehicle);
743  vehControl.registerOneWaitingForPerson();
745  const MSEdge* const firstEdge = vehicle->getRoute().getEdges()[0];
746  static_cast<MSVehicle*>(vehicle)->setTentativeLaneAndPosition(firstEdge->getLanes()[0], myVehicleParameter->departPos);
747  vehControl.addWaiting(*route->begin(), vehicle);
748  vehControl.registerOneWaitingForContainer();
749  } else {
750  // !!! no upscaling for triggered vehicles yet
751  for (unsigned int i = 1; i < quota; i++) {
754  newPars->id = myVehicleParameter->id + "." + toString(i);
755  vehicle = vehControl.buildVehicle(newPars, route, vtype, !MSGlobals::gCheckRoutes);
756  vehControl.addVehicle(newPars->id, vehicle);
757  }
758  }
760  myVehicleParameter = 0;
761  } else {
762  vehControl.deleteVehicle(vehicle, true);
763  myVehicleParameter = 0;
764  vehicle = 0;
765  }
766  } else {
767  // strange: another vehicle with the same id already exists
769  // and was not loaded while loading a simulation state
770  // -> error
771  std::string veh_id = myVehicleParameter->id;
772  delete myVehicleParameter;
773  myVehicleParameter = 0;
774  throw ProcessError("Another vehicle with the id '" + veh_id + "' exists.");
775  } else {
776  // ok, it seems to be loaded previously while loading a simulation state
777  vehicle = 0;
778  }
779  }
780  // check whether the vehicle shall be added directly to the network or
781  // shall stay in the internal buffer
782  if (vehicle != 0) {
783  if (vehicle->getParameter().departProcedure == DEPART_GIVEN) {
785  }
786  }
787 }
788 
789 
790 void
793  try {
794  if (myActivePlan->size() == 0) {
795  throw ProcessError("Person '" + myVehicleParameter->id + "' has no plan.");
796  }
797  if (type == 0) {
798  throw ProcessError("The type '" + myVehicleParameter->vtypeid + "' for person '" + myVehicleParameter->id + "' is not known.");
799  }
800  } catch (ProcessError&) {
801  delete myVehicleParameter;
802  myVehicleParameter = 0;
804  throw;
805  }
807  // @todo: consider myScale?
809  if (MSNet::getInstance()->getPersonControl().add(myVehicleParameter->id, person)) {
812  } else {
813  ProcessError error("Another person with the id '" + myVehicleParameter->id + "' exists.");
814  delete person;
815  throw error;
816  }
817  } else {
818  // warning already given
819  delete person;
820  }
821  myVehicleParameter = 0;
822  myActivePlan = 0;
823 }
824 
825 void
827  if (myActiveContainerPlan->size() == 0) {
828  throw ProcessError("Container '" + myVehicleParameter->id + "' has no plan.");
829  }
831  if (type == 0) {
832  throw ProcessError("The type '" + myVehicleParameter->vtypeid + "' for container '" + myVehicleParameter->id + "' is not known.");
833  }
835  // @todo: consider myScale?
837  if (MSNet::getInstance()->getContainerControl().add(myVehicleParameter->id, container)) {
840  } else {
841  ProcessError error("Another container with the id '" + myVehicleParameter->id + "' exists.");
842  delete container;
843  throw error;
844  }
845  } else {
846  // warning already given
847  delete container;
848  }
849  myVehicleParameter = 0;
851 }
852 
853 void
856  return;
857  }
858  // let's check whether vehicles had to depart before the simulation starts
861  const SUMOTime offsetToBegin = string2time(OptionsCont::getOptions().getString("begin")) - myVehicleParameter->depart;
865  return;
866  }
867  }
868  }
869  if (MSNet::getInstance()->getVehicleControl().getVType(myVehicleParameter->vtypeid, &myParsingRNG) == 0) {
870  throw ProcessError("The vehicle type '" + myVehicleParameter->vtypeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
871  }
874  closeRoute(true);
875  }
877  throw ProcessError("The route '" + myVehicleParameter->routeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
878  }
879  myActiveRouteID = "";
880 
881  // check whether the vehicle shall be added directly to the network or
882  // shall stay in the internal buffer
884  if (MSNet::getInstance()->getInsertionControl().add(myVehicleParameter)) {
886  } else {
887  throw ProcessError("Another flow with the id '" + myVehicleParameter->id + "' exists.");
888  }
889  }
890  myVehicleParameter = 0;
891  myInsertStopEdgesAt = -1;
892 }
893 
894 
895 void
897  std::string errorSuffix;
898  if (myActivePlan != 0) {
899  errorSuffix = " in person '" + myVehicleParameter->id + "'.";
900  } else if (myVehicleParameter != 0) {
901  errorSuffix = " in vehicle '" + myVehicleParameter->id + "'.";
902  } else if (myActiveContainerPlan != 0) {
903  errorSuffix = " in container '" + myVehicleParameter->id + "'.";
904  } else {
905  errorSuffix = " in route '" + myActiveRouteID + "'.";
906  }
908  bool ok = parseStop(stop, attrs, errorSuffix, MsgHandler::getErrorInstance());
909  if (!ok) {
910  return;
911  }
912  const MSEdge* edge = 0;
913  // try to parse the assigned bus stop
914  if (stop.busstop != "") {
915  // ok, we have a bus stop
917  if (bs == 0) {
918  WRITE_ERROR("The bus stop '" + stop.busstop + "' is not known" + errorSuffix);
919  return;
920  }
921  const MSLane& l = bs->getLane();
922  stop.lane = l.getID();
923  stop.endPos = bs->getEndLanePosition();
924  stop.startPos = bs->getBeginLanePosition();
925  edge = &l.getEdge();
926  } //try to parse the assigned container stop
927  else if (stop.containerstop != "") {
928  // ok, we have obviously a container stop
930  if (cs == 0) {
931  WRITE_ERROR("The container stop '" + stop.containerstop + "' is not known" + errorSuffix);
932  return;
933  }
934  const MSLane& l = cs->getLane();
935  stop.lane = l.getID();
936  stop.endPos = cs->getEndLanePosition();
937  stop.startPos = cs->getBeginLanePosition();
938  edge = &l.getEdge();
939  } else if (stop.chargingStation != "") {
940  // ok, we have a Charging station
942  if (cs != 0) {
943  const MSLane& l = cs->getLane();
944  stop.lane = l.getID();
945  stop.endPos = cs->getEndLanePosition();
946  stop.startPos = cs->getBeginLanePosition();
947  } else {
948  WRITE_ERROR("The charging station '" + stop.chargingStation + "' is not known" + errorSuffix);
949  return;
950  }
951  } else {
952  // no, the lane and the position should be given
953  // get the lane
954  stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, "");
955  if (ok && stop.lane != "") {
956  if (MSLane::dictionary(stop.lane) == 0) {
957  WRITE_ERROR("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix);
958  return;
959  }
960  } else {
961  if (myActivePlan && !myActivePlan->empty()) {
962  const MSStoppingPlace* bs = myActivePlan->back()->getDestinationStop();
963  if (bs != 0) {
964  edge = &bs->getLane().getEdge();
965  stop.lane = bs->getLane().getID();
966  stop.endPos = bs->getEndLanePosition();
967  stop.startPos = bs->getBeginLanePosition();
968  } else {
969  edge = &myActivePlan->back()->getDestination();
970  stop.lane = edge->getLanes()[0]->getID();
971  stop.endPos = myActivePlan->back()->getArrivalPos();
972  stop.startPos = stop.endPos - POSITION_EPS;
973  }
974  } else {
975  WRITE_ERROR("A stop must be placed on a bus stop, a container stop or a lane" + errorSuffix);
976  return;
977  }
978  }
979  edge = &MSLane::dictionary(stop.lane)->getEdge();
980  if (myActivePlan &&
981  !myActivePlan->empty() &&
982  &myActivePlan->back()->getDestination() != edge) {
983  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + edge->getID() + "!=" + myActivePlan->back()->getDestination().getID() + ").");
984  }
985  if (myActivePlan && myActivePlan->empty()) {
987  *edge, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start"));
988  }
989  if (myActiveContainerPlan &&
990  !myActiveContainerPlan->empty() &&
991  &myActiveContainerPlan->back()->getDestination() != &MSLane::dictionary(stop.lane)->getEdge()) {
992  throw ProcessError("Disconnected plan for container '" + myVehicleParameter->id + "' (" + MSLane::dictionary(stop.lane)->getEdge().getID() + "!=" + myActiveContainerPlan->back()->getDestination().getID() + ").");
993  }
996  MSLane::dictionary(stop.lane)->getEdge(), -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start"));
997  }
998  stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ENDPOS, 0, ok, MSLane::dictionary(stop.lane)->getLength());
999  if (attrs.hasAttribute(SUMO_ATTR_POSITION)) {
1000  WRITE_WARNING("Deprecated attribute 'pos' in description of stop" + errorSuffix);
1001  stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_POSITION, 0, ok, stop.endPos);
1002  }
1003  stop.startPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_STARTPOS, 0, ok, MAX2((SUMOReal)0., stop.endPos - 2 * POSITION_EPS));
1004  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false);
1005  if (!ok || !checkStopPos(stop.startPos, stop.endPos, MSLane::dictionary(stop.lane)->getLength(), POSITION_EPS, friendlyPos)) {
1006  WRITE_ERROR("Invalid start or end position for stop on lane '" + stop.lane + "'" + errorSuffix);
1007  return;
1008  }
1009  }
1010  if (myActivePlan != 0) {
1011  std::string actType = attrs.getOpt<std::string>(SUMO_ATTR_ACTTYPE, 0, ok, "waiting");
1012  SUMOReal pos = (stop.startPos + stop.endPos) / 2.;
1013  if (!myActivePlan->empty()) {
1014  pos = myActivePlan->back()->getArrivalPos();
1015  }
1017  MSLane::dictionary(stop.lane)->getEdge(), stop.duration, stop.until, pos, actType));
1018  } else if (myActiveContainerPlan != 0) {
1019  std::string actType = attrs.getOpt<std::string>(SUMO_ATTR_ACTTYPE, 0, ok, "waiting");
1021  MSLane::dictionary(stop.lane)->getEdge(), stop.duration, stop.until, stop.startPos, actType));
1022  } else if (myVehicleParameter != 0) {
1023  myVehicleParameter->stops.push_back(stop);
1024  } else {
1025  myActiveRouteStops.push_back(stop);
1026  }
1027  if (myInsertStopEdgesAt >= 0) {
1028  myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
1030  }
1031 }
1032 
1033 
1034 void
1035 MSRouteHandler::parseWalkPositions(const SUMOSAXAttributes& attrs, const std::string& personID,
1036  const MSEdge* fromEdge, const MSEdge*& toEdge,
1037  SUMOReal& departPos, SUMOReal& arrivalPos, MSStoppingPlace*& bs, bool& ok) {
1038  const std::string description = "person '" + personID + "' walking from " + fromEdge->getID();
1039 
1040  departPos = parseWalkPos(SUMO_ATTR_DEPARTPOS, description, fromEdge,
1041  attrs.getOpt<std::string>(SUMO_ATTR_DEPARTPOS, description.c_str(), ok, "0"));
1042 
1043  std::string bsID = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, 0, ok, "");
1044  if (bsID != "") {
1045  bs = MSNet::getInstance()->getBusStop(bsID);
1046  if (bs == 0) {
1047  throw ProcessError("Unknown bus stop '" + bsID + "' for " + description + ".");
1048  }
1049  arrivalPos = bs->getEndLanePosition();
1050  if (toEdge == 0) {
1051  toEdge = &bs->getLane().getEdge();
1052  }
1053  if (!bs->hasAccess(toEdge)) {
1054  throw ProcessError("Bus stop '" + bsID + "' is not connected to arrival edge '" + toEdge->getID() + "' for " + description + ".");
1055  }
1056  arrivalPos = (bs->getBeginLanePosition() + bs->getEndLanePosition()) / 2.;
1057  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
1058  const SUMOReal arrPos = parseWalkPos(SUMO_ATTR_ARRIVALPOS, description, toEdge,
1059  attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok));
1060  if (arrPos >= bs->getBeginLanePosition() && arrPos < bs->getEndLanePosition()) {
1061  arrivalPos = arrPos;
1062  } else {
1063  WRITE_WARNING("Ignoring arrivalPos for " + description + " because it is outside the given stop '" + toString(SUMO_ATTR_BUS_STOP) + "'.");
1064  }
1065  }
1066  } else {
1067  if (toEdge == 0) {
1068  throw ProcessError("No destination edge for " + description + ".");
1069  }
1070  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
1071  arrivalPos = parseWalkPos(SUMO_ATTR_ARRIVALPOS, description, toEdge,
1072  attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok));
1073  } else {
1074  arrivalPos = -NUMERICAL_EPS;
1075  }
1076  }
1077 }
1078 
1079 
1080 SUMOReal
1081 MSRouteHandler::parseWalkPos(SumoXMLAttr attr, const std::string& id, const MSEdge* edge, const std::string& val) {
1082  SUMOReal result;
1083  std::string error;
1084  ArrivalPosDefinition proc;
1085  // only supports 'random' and 'max'
1086  if (!SUMOVehicleParameter::parseArrivalPos(val, toString(SUMO_TAG_WALK), id, result, proc, error)) {
1087  throw ProcessError(error);
1088  }
1089  if (proc == ARRIVAL_POS_RANDOM) {
1090  result = myParsingRNG.rand(edge->getLength());
1091  } else if (proc == ARRIVAL_POS_MAX) {
1092  result = edge->getLength();
1093  }
1094  return SUMOVehicleParameter::interpretEdgePos(result, edge->getLength(), attr, id);
1095 }
1096 
1097 
1098 /****************************************************************************/
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.
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&#39;s edge.
Definition: MSLane.h:467
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:80
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
SUMOReal getMaxSpeed() const
Get vehicle&#39;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&#39;s type id.
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.
virtual MSPerson * buildPerson(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan) const
Builds a new person.
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 MSContainer * buildContainer(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan) const
Builds a new container.
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&#39;s lanes.
Definition: MSEdge.h:185
SUMOVehicleParameter * myVehicleParameter
Parameter of the current vehicle, trip, person, container or flow.
The departure is container triggered.
unsigned int getNumPredecessors() const
Returns the number of edges this edge is connected to.
Definition: MSEdge.h:358
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:84
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:885
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:828
static SUMOReal _2SUMORealSec(const E *const data, SUMOReal def)
Definition: TplConvert.h:365
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
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.
void setDeparture(SUMOTime time, MSTransportable *container)
sets the arrival time for a waiting container
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn&#39;t already in the dictionary...
Definition: MSEdge.cpp:578
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&#39;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.
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:65
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:562
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:780
void closeRouteDistribution()
std::string routeid
The vehicle&#39;s route id.
Representation of a vehicle.
Definition: SUMOVehicle.h:65
static bool gCheckRoutes
Definition: MSGlobals.h:78
Encapsulated SAX-Attributes.
bool wasSet(int what) const
Returns whether the given parameter was set.
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...
virtual MSContainerControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:698
void closeContainer()
Ends the processing of a container.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:308
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&#39;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
#define POSITION_EPS
Definition: config.h:187
std::string fromTaz
The vehicle&#39;s origin zone (district)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:54
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::string myCurrentRouteDistributionID
The id of the currently parsed route distribution.
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:772
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;.
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:690
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:349
int setParameter
Information for the router which parameter were set.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle&#39;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:804
const std::string & getID() const
Returns the name of the vehicle type.
void setDeparture(SUMOTime time, MSPerson *person)
sets the arrival time for a waiting or walking person
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&#39;s color.
#define SUMOReal
Definition: config.h:213
ArrivalPosDefinition
Possible ways to choose the arrival position.
unsigned int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:335
#define NUMERICAL_EPS
Definition: config.h:160
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.
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
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:77
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:634
void closeRoute(const bool mayBeDisconnected=false)
unsigned int getQuota(SUMOReal frac=-1) const
Returns the number of instances of the current vehicle that shall be emitted considering that "frac" ...
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&#39;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.