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-2017 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 
56 #include "MSParkingArea.h"
57 #include "MSStoppingPlace.h"
58 #include <microsim/MSGlobals.h>
61 
62 
63 // ===========================================================================
64 // static members
65 // ===========================================================================
66 std::mt19937 MSRouteHandler::myParsingRNG;
67 
68 
69 // ===========================================================================
70 // method definitions
71 // ===========================================================================
72 MSRouteHandler::MSRouteHandler(const std::string& file,
73  bool addVehiclesDirectly) :
74  SUMORouteHandler(file),
75  myActivePlan(0),
76  myActiveContainerPlan(0),
77  myAddVehiclesDirectly(addVehiclesDirectly),
78  myCurrentVTypeDistribution(0),
79  myCurrentRouteDistribution(0),
80  myAmLoadingState(false) {
81  myActiveRoute.reserve(100);
82  // check for valid value has been performed in MSFrame
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 + "'");
138  myVehicleParameter->via = StringTokenizer(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok, "", true)).getVector();
140  const MSEdge* toTaz = MSEdge::dictionary(myVehicleParameter->toTaz + "-sink");
141  if (toTaz == 0) {
142  throw ProcessError("Sink taz '" + myVehicleParameter->toTaz + "' not known for " + element + " '" + myVehicleParameter->id + "'!");
143  } else if (toTaz->getNumPredecessors() == 0) {
144  throw ProcessError("Sink taz '" + myVehicleParameter->toTaz + "' has no incoming edges for " + element + " '" + myVehicleParameter->id + "'!");
145  } else {
146  myActiveRoute.push_back(toTaz);
147  }
148  } else {
149  MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "", true),
150  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
151  }
153  if (myVehicleParameter->routeid == "") {
155  }
156 }
157 
158 
159 void
161  const SUMOSAXAttributes& attrs) {
162  SUMORouteHandler::myStartElement(element, attrs);
163  try {
164  switch (element) {
165  case SUMO_TAG_PERSON:
167  break;
168  case SUMO_TAG_CONTAINER:
170  break;
171  case SUMO_TAG_RIDE: {
172  const std::string pid = myVehicleParameter->id;
173  bool ok = true;
174  MSEdge* from = 0;
175  const std::string desc = attrs.get<std::string>(SUMO_ATTR_LINES, pid.c_str(), ok);
176  StringTokenizer st(desc);
177  std::string bsID = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, 0, ok, "");
178  MSStoppingPlace* bs = 0;
179  MSEdge* to = 0;
180  if (bsID != "") {
181  bs = MSNet::getInstance()->getBusStop(bsID);
182  if (bs == 0) {
183  throw ProcessError("Unknown bus stop '" + bsID + "' for person '" + myVehicleParameter->id + "'.");
184  }
185  to = &bs->getLane().getEdge();
186  }
187  double arrivalPos = attrs.getOpt<double>(SUMO_ATTR_ARRIVALPOS, myVehicleParameter->id.c_str(), ok,
188  bs == 0 ? -NUMERICAL_EPS : bs->getEndLanePosition());
189  if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
190  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, pid.c_str(), ok);
191  from = MSEdge::dictionary(fromID);
192  if (from == 0) {
193  throw ProcessError("The from edge '" + fromID + "' within a ride of person '" + pid + "' is not known.");
194  }
195  if (!myActivePlan->empty() && &myActivePlan->back()->getDestination() != from) {
196  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + fromID + "!=" + myActivePlan->back()->getDestination().getID() + ").");
197  }
198  if (myActivePlan->empty()) {
200  *from, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
201  }
202  } else if (myActivePlan->empty()) {
203  throw ProcessError("The start edge for person '" + pid + "' is not known.");
204  }
205  if (to == 0) {
206  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, pid.c_str(), ok);
207  to = MSEdge::dictionary(toID);
208  if (to == 0) {
209  throw ProcessError("The to edge '" + toID + "' within a ride of person '" + pid + "' is not known.");
210  }
211  }
212  myActivePlan->push_back(new MSPerson::MSPersonStage_Driving(*to, bs, arrivalPos, st.getVector()));
213  break;
214  }
215  case SUMO_TAG_WALK:
216  try {
217  myActiveRoute.clear();
218  bool ok = true;
219  const SUMOTime duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, 0, ok, -1);
220  if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
221  throw ProcessError("Non-positive walking duration for '" + myVehicleParameter->id + "'.");
222  }
223  double speed = DEFAULT_PEDESTRIAN_SPEED;
225  // need to check for explicitly set speed since we might have // DEFAULT_VEHTYPE
226  if (vtype != 0) {
227  speed = vtype->getMaxSpeed() * vtype->computeChosenSpeedDeviation(&myParsingRNG);
228  }
229  speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, 0, ok, speed);
230  if (speed <= 0) {
231  throw ProcessError("Non-positive walking speed for '" + myVehicleParameter->id + "'.");
232  }
233  double departPos = 0;
234  double arrivalPos = 0;
235  MSStoppingPlace* bs = 0;
236  if (attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
237  const std::string routeID = attrs.get<std::string>(SUMO_ATTR_ROUTE, myVehicleParameter->id.c_str(), ok);
238  const MSRoute* route = MSRoute::dictionary(routeID, &myParsingRNG);
239  if (route == 0) {
240  throw ProcessError("The route '" + routeID + "' for walk of person '" + myVehicleParameter->id + "' is not known.");
241  }
242  myActiveRoute = route->getEdges();
243  parseWalkPositions(attrs, myVehicleParameter->id, myActiveRoute.front(), myActiveRoute.back(), departPos, arrivalPos, bs, ok);
244  } else if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
246  parseWalkPositions(attrs, myVehicleParameter->id, myActiveRoute.front(), myActiveRoute.back(), departPos, arrivalPos, bs, ok);
247  } else {
248  const std::string fromID = attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok, "");
249  const MSEdge* from = fromID != "" || myActivePlan->empty() ? MSEdge::dictionary(fromID) : &myActivePlan->back()->getDestination();
250  if (from == 0) {
251  throw ProcessError("The from edge '" + fromID + "' within a walk of person '" + myVehicleParameter->id + "' is not known.");
252  }
253  const std::string toID = attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "");
254  const MSEdge* to = MSEdge::dictionary(toID);
255  if (toID != "" && to == 0) {
256  throw ProcessError("The to edge '" + toID + "' within a walk of person '" + myVehicleParameter->id + "' is not known.");
257  }
258  parseWalkPositions(attrs, myVehicleParameter->id, from, to, departPos, arrivalPos, bs, ok);
259  MSNet::getInstance()->getPedestrianRouter().compute(from, to, departPos, arrivalPos,
260  speed, 0, 0, myActiveRoute);
261  if (myActiveRoute.empty()) {
262  const std::string error = "No connection found between '" + from->getID() + "' and '" + to->getID() + "' for person '" + myVehicleParameter->id + "'.";
264  myActiveRoute.push_back(from);
265  myActiveRoute.push_back(to); // pedestrian will teleport
266  //WRITE_WARNING(error);
267  } else {
268  throw ProcessError(error);
269  }
270  }
271  //std::cout << myVehicleParameter->id << " edges=" << toString(myActiveRoute) << "\n";
272  }
273  if (myActiveRoute.empty()) {
274  throw ProcessError("No edges to walk for person '" + myVehicleParameter->id + "'.");
275  }
276  if (!myActivePlan->empty() && &myActivePlan->back()->getDestination() != myActiveRoute.front()) {
277  if (myActivePlan->back()->getDestinationStop() == 0 || !myActivePlan->back()->getDestinationStop()->hasAccess(myActiveRoute.front())) {
278  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + myActiveRoute.front()->getID() + " != " + myActivePlan->back()->getDestination().getID() + ").");
279  }
280  }
281  if (myActivePlan->empty()) {
283  *myActiveRoute.front(), -1, myVehicleParameter->depart, departPos, "start", true));
284  }
285  const double departPosLat = attrs.getOpt<double>(SUMO_ATTR_DEPARTPOS_LAT, 0, ok, 0);
286  myActivePlan->push_back(new MSPerson::MSPersonStage_Walking(myActiveRoute, bs, duration, speed, departPos, arrivalPos, departPosLat));
287  myActiveRoute.clear();
288  } catch (ProcessError&) {
290  throw;
291  }
292  break;
293  case SUMO_TAG_TRANSPORT:
294  try {
295  const std::string containerId = myVehicleParameter->id;
296  bool ok = true;
297  MSEdge* from = 0;
298  const std::string desc = attrs.get<std::string>(SUMO_ATTR_LINES, containerId.c_str(), ok);
299  StringTokenizer st(desc);
300  std::string csID = attrs.getOpt<std::string>(SUMO_ATTR_CONTAINER_STOP, 0, ok, "");
301  MSStoppingPlace* cs = 0;
302  if (csID != "") {
303  cs = MSNet::getInstance()->getContainerStop(csID);
304  if (cs == 0) {
305  throw ProcessError("Unknown container stop '" + csID + "' for container '" + myVehicleParameter->id + "'.");
306  }
307  }
308  double arrivalPos = attrs.getOpt<double>(SUMO_ATTR_ARRIVALPOS, myVehicleParameter->id.c_str(), ok,
309  cs == 0 ? -NUMERICAL_EPS : cs->getEndLanePosition());
310  if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
311  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, containerId.c_str(), ok);
312  from = MSEdge::dictionary(fromID);
313  if (from == 0) {
314  throw ProcessError("The from edge '" + fromID + "' within a transport of container '" + containerId + "' is not known.");
315  }
316  if (!myActiveContainerPlan->empty() && &myActiveContainerPlan->back()->getDestination() != from) {
317  throw ProcessError("Disconnected plan for container '" + myVehicleParameter->id + "' (" + fromID + "!=" + myActiveContainerPlan->back()->getDestination().getID() + ").");
318  }
319  if (myActiveContainerPlan->empty()) {
321  *from, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
322  }
323  } else if (myActiveContainerPlan->empty()) {
324  throw ProcessError("The start edge within a transport of container '" + containerId + "' is not known.");
325  }
326  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, containerId.c_str(), ok);
327  MSEdge* to = MSEdge::dictionary(toID);
328  if (to == 0) {
329  throw ProcessError("The to edge '" + toID + "' within a transport of container '" + containerId + "' is not known.");
330  }
331  myActiveContainerPlan->push_back(new MSContainer::MSContainerStage_Driving(*to, cs, arrivalPos, st.getVector()));
332 
333  } catch (ProcessError&) {
335  throw;
336  }
337  break;
338  case SUMO_TAG_TRANSHIP: {
339  myActiveRoute.clear();
340  bool ok = true;
341  double departPos = attrs.getOpt<double>(SUMO_ATTR_DEPARTPOS, myVehicleParameter->id.c_str(), ok, 0);
342  double arrivalPos = attrs.getOpt<double>(SUMO_ATTR_ARRIVALPOS, myVehicleParameter->id.c_str(), ok, -NUMERICAL_EPS);
343  double speed = DEFAULT_CONTAINER_TRANSHIP_SPEED;
345  // need to check for explicitly set speed since we might have // DEFAULT_VEHTYPE
346  if (vtype != 0 && vtype->wasSet(VTYPEPARS_MAXSPEED_SET)) {
347  speed = vtype->getMaxSpeed();
348  }
349  speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, 0, ok, speed);
350  if (speed <= 0) {
351  throw ProcessError("Non-positive tranship speed for container '" + myVehicleParameter->id + "'.");
352  }
353  std::string csID = attrs.getOpt<std::string>(SUMO_ATTR_CONTAINER_STOP, 0, ok, "");
354  MSStoppingPlace* cs = 0;
355  if (csID != "") {
356  cs = MSNet::getInstance()->getContainerStop(csID);
357  if (cs == 0) {
358  throw ProcessError("Unknown container stop '" + csID + "' for container '" + myVehicleParameter->id + "'.");
359  }
360  arrivalPos = cs->getEndLanePosition();
361  }
362  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
364  } else {
365  if (attrs.hasAttribute(SUMO_ATTR_FROM) && attrs.hasAttribute(SUMO_ATTR_TO)) {
366  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok);
367  MSEdge* from = MSEdge::dictionary(fromID);
368  if (from == 0) {
369  throw ProcessError("The from edge '" + fromID + "' within a tranship of container '" + myVehicleParameter->id + "' is not known.");
370  }
371  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok);
372  MSEdge* to = MSEdge::dictionary(toID);
373  if (to == 0) {
374  throw ProcessError("The to edge '" + toID + "' within a tranship of container '" + myVehicleParameter->id + "' is not known.");
375  }
376  //the route of the container's tranship stage consists only of the 'from' and the 'to' edge
377  myActiveRoute.push_back(from);
378  myActiveRoute.push_back(to);
379  if (myActiveRoute.empty()) {
380  const std::string error = "No connection found between '" + from->getID() + "' and '" + to->getID() + "' for container '" + myVehicleParameter->id + "'.";
382  myActiveRoute.push_back(from);
383  } else {
384  WRITE_ERROR(error);
385  }
386  }
387  }
388  }
389  if (myActiveRoute.empty()) {
390  throw ProcessError("No edges to tranship container '" + myVehicleParameter->id + "'.");
391  }
392  if (!myActiveContainerPlan->empty() && &myActiveContainerPlan->back()->getDestination() != myActiveRoute.front()) {
393  throw ProcessError("Disconnected plan for container '" + myVehicleParameter->id + "' (" + myActiveRoute.front()->getID() + "!=" + myActiveContainerPlan->back()->getDestination().getID() + ").");
394  }
395  if (myActiveContainerPlan->empty()) {
397  *myActiveRoute.front(), -1, myVehicleParameter->depart, departPos, "start", true));
398  }
399  myActiveContainerPlan->push_back(new MSContainer::MSContainerStage_Tranship(myActiveRoute, cs, speed, departPos, arrivalPos));
400  myActiveRoute.clear();
401  break;
402  }
403  case SUMO_TAG_FLOW:
404  parseFromViaTo("flow", attrs);
405  break;
406  case SUMO_TAG_TRIP:
407  parseFromViaTo("trip", attrs);
408  break;
409  default:
410  break;
411  }
412  } catch (ProcessError&) {
413  delete myVehicleParameter;
414  myVehicleParameter = 0;
415  throw;
416  }
417 }
418 
419 
420 void
422  bool ok = true;
423  myCurrentVTypeDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
424  if (ok) {
426  if (attrs.hasAttribute(SUMO_ATTR_VTYPES)) {
427  const std::string vTypes = attrs.get<std::string>(SUMO_ATTR_VTYPES, myCurrentVTypeDistributionID.c_str(), ok);
428  StringTokenizer st(vTypes);
429  while (st.hasNext()) {
430  std::string vtypeID = st.next();
432  if (type == 0) {
433  throw ProcessError("Unknown vtype '" + vtypeID + "' in distribution '" + myCurrentVTypeDistributionID + "'.");
434  }
436  }
437  }
438  }
439 }
440 
441 
442 void
444  if (myCurrentVTypeDistribution != 0) {
445  if (MSGlobals::gStateLoaded && MSNet::getInstance()->getVehicleControl().hasVTypeDistribution(myCurrentVTypeDistributionID)) {
447  return;
448  }
451  throw ProcessError("Vehicle type distribution '" + myCurrentVTypeDistributionID + "' is empty.");
452  }
453  if (!MSNet::getInstance()->getVehicleControl().addVTypeDistribution(myCurrentVTypeDistributionID, myCurrentVTypeDistribution)) {
455  throw ProcessError("Another vehicle type (or distribution) with the id '" + myCurrentVTypeDistributionID + "' exists.");
456  }
458  }
459 }
460 
461 
462 void
464  myActiveRoute.clear();
465  myInsertStopEdgesAt = -1;
466  // check whether the id is really necessary
467  std::string rid;
468  if (myCurrentRouteDistribution != 0) {
470  rid = "distribution '" + myCurrentRouteDistributionID + "'";
471  } else if (myVehicleParameter != 0) {
472  // ok, a vehicle is wrapping the route,
473  // we may use this vehicle's id as default
474  myActiveRouteID = "!" + myVehicleParameter->id; // !!! document this
475  if (attrs.hasAttribute(SUMO_ATTR_ID)) {
476  WRITE_WARNING("Ids of internal routes are ignored (vehicle '" + myVehicleParameter->id + "').");
477  }
478  } else {
479  bool ok = true;
480  myActiveRouteID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok, false);
481  if (!ok) {
482  return;
483  }
484  rid = "'" + myActiveRouteID + "'";
485  }
486  if (myVehicleParameter != 0) { // have to do this here for nested route distributions
487  rid = "for vehicle '" + myVehicleParameter->id + "'";
488  }
489  bool ok = true;
490  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
491  MSEdge::parseEdgesList(attrs.get<std::string>(SUMO_ATTR_EDGES, myActiveRouteID.c_str(), ok), myActiveRoute, rid);
492  }
493  myActiveRouteRefID = attrs.getOpt<std::string>(SUMO_ATTR_REFID, myActiveRouteID.c_str(), ok, "");
495  WRITE_ERROR("Invalid reference to route '" + myActiveRouteRefID + "' in route " + rid + ".");
496  }
499  myCurrentCosts = attrs.getOpt<double>(SUMO_ATTR_COST, myActiveRouteID.c_str(), ok, -1);
500  if (ok && myCurrentCosts != -1 && myCurrentCosts < 0) {
501  WRITE_ERROR("Invalid cost for route '" + myActiveRouteID + "'.");
502  }
503 }
504 
505 
506 void
509  switch (element) {
510  case SUMO_TAG_VTYPE: {
512  delete myCurrentVType;
513  myCurrentVType = 0;
514  if (!MSNet::getInstance()->getVehicleControl().addVType(vehType)) {
515  const std::string id = vehType->getID();
516  delete vehType;
518  throw ProcessError("Another vehicle type (or distribution) with the id '" + id + "' exists.");
519  }
520  } else {
521  if (myCurrentVTypeDistribution != 0) {
523  }
524  }
525  }
526  break;
527  case SUMO_TAG_TRIP:
529  closeRoute(true);
530  closeVehicle();
531  delete myVehicleParameter;
532  myVehicleParameter = 0;
533  myInsertStopEdgesAt = -1;
534  break;
535  default:
536  break;
537  }
538 }
539 
540 
541 void
542 MSRouteHandler::closeRoute(const bool mayBeDisconnected) {
543  std::string type = "vehicle";
544  if (mayBeDisconnected) {
546  type = "flow";
547  } else {
548  type = "trip";
549  }
550  }
551 
552  try {
553  if (myActiveRoute.size() == 0) {
554  delete myActiveRouteColor;
555  myActiveRouteColor = 0;
558  if (route != 0) {
560  route->addReference();
561  }
562  }
563  myActiveRouteID = "";
564  myActiveRouteRefID = "";
565  return;
566  }
567  if (myVehicleParameter != 0) {
568  throw ProcessError("The route for " + type + " '" + myVehicleParameter->id + "' has no edges.");
569  } else {
570  throw ProcessError("Route '" + myActiveRouteID + "' has no edges.");
571  }
572  }
573  if (myActiveRoute.size() == 1 && myActiveRoute.front()->isTazConnector()) {
574  throw ProcessError("The routing information for " + type + " '" + myVehicleParameter->id + "' is insufficient.");
575  }
579  route->setCosts(myCurrentCosts);
580  myActiveRoute.clear();
581  if (!MSRoute::dictionary(myActiveRouteID, route)) {
582  delete route;
584  if (myVehicleParameter != 0) {
585  if (MSNet::getInstance()->getVehicleControl().getVehicle(myVehicleParameter->id) == 0) {
586  throw ProcessError("Another route for " + type + " '" + myVehicleParameter->id + "' exists.");
587  } else {
588  throw ProcessError("A vehicle with id '" + myVehicleParameter->id + "' already exists.");
589  }
590  } else {
591  throw ProcessError("Another route (or distribution) with the id '" + myActiveRouteID + "' exists.");
592  }
593  }
594  } else {
595  if (myCurrentRouteDistribution != 0) {
597  route->addReference();
598  }
599  }
600  }
601  myActiveRouteID = "";
602  myActiveRouteColor = 0;
603  myActiveRouteStops.clear();
604  } catch (ProcessError&) {
605  delete myVehicleParameter;
606  throw;
607  }
608 }
609 
610 
611 void
613  // check whether the id is really necessary
614  bool ok = true;
615  if (myVehicleParameter != 0) {
616  // ok, a vehicle is wrapping the route,
617  // we may use this vehicle's id as default
618  myCurrentRouteDistributionID = "!" + myVehicleParameter->id; // !!! document this
619  } else {
620  myCurrentRouteDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
621  if (!ok) {
622  return;
623  }
624  }
626  std::vector<double> probs;
627  if (attrs.hasAttribute(SUMO_ATTR_PROBS)) {
628  bool ok = true;
629  StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_PROBS, myCurrentRouteDistributionID.c_str(), ok));
630  while (st.hasNext()) {
631  probs.push_back(TplConvert::_2doubleSec(st.next().c_str(), 1.0));
632  }
633  }
634  if (attrs.hasAttribute(SUMO_ATTR_ROUTES)) {
635  bool ok = true;
636  StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_ROUTES, myCurrentRouteDistributionID.c_str(), ok));
637  int probIndex = 0;
638  while (st.hasNext()) {
639  std::string routeID = st.next();
640  const MSRoute* route = MSRoute::dictionary(routeID, &myParsingRNG);
641  if (route == 0) {
642  throw ProcessError("Unknown route '" + routeID + "' in distribution '" + myCurrentRouteDistributionID + "'.");
643  }
644  const double prob = ((int)probs.size() > probIndex ? probs[probIndex] : 1.0);
645  if (myCurrentRouteDistribution->add(route, prob, false)) {
646  route->addReference();
647  }
648  probIndex++;
649  }
650  if (probs.size() > 0 && probIndex != (int)probs.size()) {
651  WRITE_WARNING("Got " + toString(probs.size()) + " probabilities for " + toString(probIndex) +
652  " routes in routeDistribution '" + myCurrentRouteDistributionID + "'");
653  }
654  }
655 }
656 
657 
658 void
660  if (myCurrentRouteDistribution != 0) {
661  const bool haveSameID = MSRoute::dictionary(myCurrentRouteDistributionID, &myParsingRNG) != 0;
662  if (MSGlobals::gStateLoaded && haveSameID) {
664  return;
665  }
666  if (haveSameID) {
668  throw ProcessError("Another route (or distribution) with the id '" + myCurrentRouteDistributionID + "' exists.");
669  }
672  throw ProcessError("Route distribution '" + myCurrentRouteDistributionID + "' is empty.");
673  }
676  }
677 }
678 
679 
680 void
682  // get nested route
686  // let's check whether this vehicle had to depart before the simulation starts
688  if (route != 0) {
689  route->addReference();
690  route->release();
691  }
692  return;
693  }
694  }
695 
696  // get the vehicle's type
697  MSVehicleType* vtype = 0;
698 
699  try {
700  if (myVehicleParameter->vtypeid != "") {
701  vtype = vehControl.getVType(myVehicleParameter->vtypeid, &myParsingRNG);
702  if (vtype == 0) {
703  throw ProcessError("The vehicle type '" + myVehicleParameter->vtypeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
704  }
705  if (vtype->getVehicleClass() == SVC_PEDESTRIAN) {
706  WRITE_WARNING("Vehicle type '" + vtype->getID() + "' with vClass=pedestrian should only be used for persons and not for vehicle '" + myVehicleParameter->id + "'.");
707  }
708  } else {
709  // there should be one (at least the default one)
710  vtype = vehControl.getVType(DEFAULT_VTYPE_ID, &myParsingRNG);
711  }
713  // if the route id was given, prefer that one
714  if (route != 0 && !myAmLoadingState) {
715  WRITE_WARNING("Ignoring child element 'route' for vehicle '" + myVehicleParameter->id + "' because attribute 'route' is set.");
716  }
718  }
719  if (route == 0) {
720  // nothing found? -> error
721  if (myVehicleParameter->routeid != "") {
722  throw ProcessError("The route '" + myVehicleParameter->routeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
723  } else {
724  throw ProcessError("Vehicle '" + myVehicleParameter->id + "' has no route.");
725  }
726  }
727  myActiveRouteID = "";
728 
729  } catch (ProcessError&) {
730  delete myVehicleParameter;
731  throw;
732  }
733 
734  // try to build the vehicle
735  SUMOVehicle* vehicle = 0;
736  if (vehControl.getVehicle(myVehicleParameter->id) == 0) {
737  try {
738  vehicle = vehControl.buildVehicle(myVehicleParameter, route, vtype, !MSGlobals::gCheckRoutes);
739  } catch (const ProcessError& e) {
741  WRITE_WARNING(e.what());
742  vehControl.deleteVehicle(0, true);
743  myVehicleParameter = 0;
744  vehicle = 0;
745  return;
746  } else {
747  throw e;
748  }
749  }
750  // maybe we do not want this vehicle to be inserted due to scaling
751  int quota = myAmLoadingState ? 1 : vehControl.getQuota();
752  if (quota > 0) {
753  vehControl.addVehicle(myVehicleParameter->id, vehicle);
755  const MSEdge* const firstEdge = vehicle->getRoute().getEdges()[0];
756  if (!MSGlobals::gUseMesoSim) {
757  // position will be checked against person position later
758  static_cast<MSVehicle*>(vehicle)->setTentativeLaneAndPosition(firstEdge->getLanes()[0], myVehicleParameter->departPos);
759  }
760  vehControl.addWaiting(*route->begin(), vehicle);
761  vehControl.registerOneWaitingForPerson();
763  const MSEdge* const firstEdge = vehicle->getRoute().getEdges()[0];
764  if (!MSGlobals::gUseMesoSim) {
765  // position will be checked against container position later
766  static_cast<MSVehicle*>(vehicle)->setTentativeLaneAndPosition(firstEdge->getLanes()[0], myVehicleParameter->departPos);
767  }
768  vehControl.addWaiting(*route->begin(), vehicle);
769  vehControl.registerOneWaitingForContainer();
770  } else {
771  // !!! no upscaling for triggered vehicles yet
772  for (int i = 1; i < quota; i++) {
775  newPars->id = myVehicleParameter->id + "." + toString(i);
776  vehicle = vehControl.buildVehicle(newPars, route, vtype, !MSGlobals::gCheckRoutes);
777  vehControl.addVehicle(newPars->id, vehicle);
778  }
779  }
781  myVehicleParameter = 0;
782  } else {
783  vehControl.deleteVehicle(vehicle, true);
784  myVehicleParameter = 0;
785  vehicle = 0;
786  }
787  } else {
788  // strange: another vehicle with the same id already exists
790  // and was not loaded while loading a simulation state
791  // -> error
792  std::string veh_id = myVehicleParameter->id;
793  delete myVehicleParameter;
794  myVehicleParameter = 0;
795  throw ProcessError("Another vehicle with the id '" + veh_id + "' exists.");
796  } else {
797  // ok, it seems to be loaded previously while loading a simulation state
798  vehicle = 0;
799  }
800  }
801  // check whether the vehicle shall be added directly to the network or
802  // shall stay in the internal buffer
803  if (vehicle != 0) {
804  if (vehicle->getParameter().departProcedure == DEPART_GIVEN) {
806  }
807  }
808 }
809 
810 
811 void
814  try {
815  if (myActivePlan->size() == 0) {
816  throw ProcessError("Person '" + myVehicleParameter->id + "' has no plan.");
817  }
818  if (type == 0) {
819  throw ProcessError("The type '" + myVehicleParameter->vtypeid + "' for person '" + myVehicleParameter->id + "' is not known.");
820  }
821  } catch (ProcessError&) {
822  delete myVehicleParameter;
823  myVehicleParameter = 0;
825  throw;
826  }
827  // let's check whether this person had to depart before the simulation starts
830  delete myVehicleParameter;
831  myVehicleParameter = 0;
833  return;
834  }
836  // @todo: consider myScale?
837  if (MSNet::getInstance()->getPersonControl().add(person)) {
839  } else {
840  ProcessError error("Another person with the id '" + myVehicleParameter->id + "' exists.");
841  delete person;
842  throw error;
843  }
844  myVehicleParameter = 0;
845  myActivePlan = 0;
846 }
847 
848 void
850  if (myActiveContainerPlan->size() == 0) {
851  throw ProcessError("Container '" + myVehicleParameter->id + "' has no plan.");
852  }
854  if (type == 0) {
855  throw ProcessError("The type '" + myVehicleParameter->vtypeid + "' for container '" + myVehicleParameter->id + "' is not known.");
856  }
858  // @todo: consider myScale?
860  if (MSNet::getInstance()->getContainerControl().add(container)) {
862  } else {
863  ProcessError error("Another container with the id '" + myVehicleParameter->id + "' exists.");
864  delete container;
865  throw error;
866  }
867  } else {
868  // warning already given
869  delete container;
870  }
871  myVehicleParameter = 0;
873 }
874 
875 void
877  myInsertStopEdgesAt = -1;
879  delete myVehicleParameter;
880  myVehicleParameter = 0;
881  return;
882  }
883  // let's check whether vehicles had to depart before the simulation starts
886  const SUMOTime offsetToBegin = string2time(OptionsCont::getOptions().getString("begin")) - myVehicleParameter->depart;
890  delete myVehicleParameter;
891  myVehicleParameter = 0;
892  return;
893  }
894  }
895  }
896  if (MSNet::getInstance()->getVehicleControl().getVType(myVehicleParameter->vtypeid, &myParsingRNG) == 0) {
897  throw ProcessError("The vehicle type '" + myVehicleParameter->vtypeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
898  }
901  closeRoute(true);
902  }
904  throw ProcessError("The route '" + myVehicleParameter->routeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
905  }
906  myActiveRouteID = "";
907 
908  // check whether the vehicle shall be added directly to the network or
909  // shall stay in the internal buffer
911  if (MSNet::getInstance()->getInsertionControl().add(myVehicleParameter)) {
913  } else {
914  throw ProcessError("Another flow with the id '" + myVehicleParameter->id + "' exists.");
915  }
916  }
917  myVehicleParameter = 0;
918 }
919 
920 
921 void
923  std::string errorSuffix;
924  if (myActivePlan != 0) {
925  errorSuffix = " in person '" + myVehicleParameter->id + "'.";
926  } else if (myVehicleParameter != 0) {
927  errorSuffix = " in vehicle '" + myVehicleParameter->id + "'.";
928  } else if (myActiveContainerPlan != 0) {
929  errorSuffix = " in container '" + myVehicleParameter->id + "'.";
930  } else {
931  errorSuffix = " in route '" + myActiveRouteID + "'.";
932  }
934  bool ok = parseStop(stop, attrs, errorSuffix, MsgHandler::getErrorInstance());
935  if (!ok) {
936  return;
937  }
938  const MSEdge* edge = 0;
939  // try to parse the assigned bus stop
940  if (stop.busstop != "") {
941  // ok, we have a bus stop
943  if (bs == 0) {
944  WRITE_ERROR("The busStop '" + stop.busstop + "' is not known" + errorSuffix);
945  return;
946  }
947  const MSLane& l = bs->getLane();
948  stop.lane = l.getID();
949  stop.endPos = bs->getEndLanePosition();
950  stop.startPos = bs->getBeginLanePosition();
951  edge = &l.getEdge();
952  } //try to parse the assigned container stop
953  else if (stop.containerstop != "") {
954  // ok, we have obviously a container stop
956  if (cs == 0) {
957  WRITE_ERROR("The containerStop '" + stop.containerstop + "' is not known" + errorSuffix);
958  return;
959  }
960  const MSLane& l = cs->getLane();
961  stop.lane = l.getID();
962  stop.endPos = cs->getEndLanePosition();
963  stop.startPos = cs->getBeginLanePosition();
964  edge = &l.getEdge();
965  } //try to parse the assigned parking area
966  else if (stop.parkingarea != "") {
967  // ok, we have obviously a parking area
969  if (pa == 0) {
970  WRITE_ERROR("The parkingArea '" + stop.parkingarea + "' is not known" + errorSuffix);
971  return;
972  }
973  const MSLane& l = pa->getLane();
974  stop.lane = l.getID();
975  stop.endPos = pa->getEndLanePosition();
976  stop.startPos = pa->getBeginLanePosition();
977  edge = &l.getEdge();
978  } else if (stop.chargingStation != "") {
979  // ok, we have a charging station
981  if (cs != 0) {
982  const MSLane& l = cs->getLane();
983  stop.lane = l.getID();
984  stop.endPos = cs->getEndLanePosition();
985  stop.startPos = cs->getBeginLanePosition();
986  } else {
987  WRITE_ERROR("The chargingStation '" + stop.chargingStation + "' is not known" + errorSuffix);
988  return;
989  }
990  } else {
991  // no, the lane and the position should be given
992  // get the lane
993  stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, "");
994  if (ok && stop.lane != "") {
995  if (MSLane::dictionary(stop.lane) == 0) {
996  WRITE_ERROR("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix);
997  return;
998  }
999  } else {
1000  if (myActivePlan && !myActivePlan->empty()) {
1001  const MSStoppingPlace* bs = myActivePlan->back()->getDestinationStop();
1002  if (bs != 0) {
1003  edge = &bs->getLane().getEdge();
1004  stop.lane = bs->getLane().getID();
1005  stop.endPos = bs->getEndLanePosition();
1006  stop.startPos = bs->getBeginLanePosition();
1007  } else {
1008  edge = &myActivePlan->back()->getDestination();
1009  stop.lane = edge->getLanes()[0]->getID();
1010  stop.endPos = myActivePlan->back()->getArrivalPos();
1011  stop.startPos = stop.endPos - POSITION_EPS;
1012  }
1013  } else {
1014  WRITE_ERROR("A stop must be placed on a busStop, a chargingStation, a containerStop a parkingArea or a lane" + errorSuffix);
1015  return;
1016  }
1017  }
1018  edge = &MSLane::dictionary(stop.lane)->getEdge();
1019  if (myActivePlan &&
1020  !myActivePlan->empty() &&
1021  &myActivePlan->back()->getDestination() != edge) {
1022  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + edge->getID() + "!=" + myActivePlan->back()->getDestination().getID() + ").");
1023  }
1024  if (myActivePlan && myActivePlan->empty()) {
1026  *edge, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
1027  }
1028  if (myActiveContainerPlan &&
1029  !myActiveContainerPlan->empty() &&
1030  &myActiveContainerPlan->back()->getDestination() != &MSLane::dictionary(stop.lane)->getEdge()) {
1031  throw ProcessError("Disconnected plan for container '" + myVehicleParameter->id + "' (" + MSLane::dictionary(stop.lane)->getEdge().getID() + "!=" + myActiveContainerPlan->back()->getDestination().getID() + ").");
1032  }
1033  if (myActiveContainerPlan && myActiveContainerPlan->empty()) {
1035  MSLane::dictionary(stop.lane)->getEdge(), -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
1036  }
1037  stop.endPos = attrs.getOpt<double>(SUMO_ATTR_ENDPOS, 0, ok, MSLane::dictionary(stop.lane)->getLength());
1038  if (attrs.hasAttribute(SUMO_ATTR_POSITION)) {
1039  WRITE_WARNING("Deprecated attribute 'pos' in description of stop" + errorSuffix);
1040  stop.endPos = attrs.getOpt<double>(SUMO_ATTR_POSITION, 0, ok, stop.endPos);
1041  }
1042  stop.startPos = attrs.getOpt<double>(SUMO_ATTR_STARTPOS, 0, ok, MAX2(0., stop.endPos - 2 * POSITION_EPS));
1043  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false);
1044  if (!ok || !checkStopPos(stop.startPos, stop.endPos, MSLane::dictionary(stop.lane)->getLength(), POSITION_EPS, friendlyPos)) {
1045  WRITE_ERROR("Invalid start or end position for stop on lane '" + stop.lane + "'" + errorSuffix);
1046  return;
1047  }
1048  }
1049  if (myActivePlan != 0) {
1050  std::string actType = attrs.getOpt<std::string>(SUMO_ATTR_ACTTYPE, 0, ok, "waiting");
1051  double pos = (stop.startPos + stop.endPos) / 2.;
1052  if (!myActivePlan->empty()) {
1053  pos = myActivePlan->back()->getArrivalPos();
1054  }
1056  MSLane::dictionary(stop.lane)->getEdge(), stop.duration, stop.until, pos, actType, false));
1057  } else if (myActiveContainerPlan != 0) {
1058  std::string actType = attrs.getOpt<std::string>(SUMO_ATTR_ACTTYPE, 0, ok, "waiting");
1060  MSLane::dictionary(stop.lane)->getEdge(), stop.duration, stop.until, stop.startPos, actType, false));
1061  } else if (myVehicleParameter != 0) {
1062  myVehicleParameter->stops.push_back(stop);
1063  } else {
1064  myActiveRouteStops.push_back(stop);
1065  }
1066  if (myInsertStopEdgesAt >= 0) {
1067  myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
1069  }
1070 }
1071 
1072 
1073 void
1074 MSRouteHandler::parseWalkPositions(const SUMOSAXAttributes& attrs, const std::string& personID,
1075  const MSEdge* fromEdge, const MSEdge*& toEdge,
1076  double& departPos, double& arrivalPos, MSStoppingPlace*& bs, bool& ok) {
1077  const std::string description = "person '" + personID + "' walking from " + fromEdge->getID();
1078 
1079  departPos = SUMOVehicleParserHelper::parseWalkPos(SUMO_ATTR_DEPARTPOS, description, fromEdge->getLength(),
1080  attrs.getOpt<std::string>(SUMO_ATTR_DEPARTPOS, description.c_str(), ok, "0"), &myParsingRNG);
1081 
1082  std::string bsID = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, 0, ok, "");
1083  if (bsID != "") {
1084  bs = MSNet::getInstance()->getBusStop(bsID);
1085  if (bs == 0) {
1086  throw ProcessError("Unknown bus stop '" + bsID + "' for " + description + ".");
1087  }
1088  arrivalPos = bs->getEndLanePosition();
1089  if (toEdge == 0) {
1090  toEdge = &bs->getLane().getEdge();
1091  }
1092  if (!bs->hasAccess(toEdge)) {
1093  throw ProcessError("Bus stop '" + bsID + "' is not connected to arrival edge '" + toEdge->getID() + "' for " + description + ".");
1094  }
1095  arrivalPos = (bs->getBeginLanePosition() + bs->getEndLanePosition()) / 2.;
1096  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
1097  const double arrPos = SUMOVehicleParserHelper::parseWalkPos(SUMO_ATTR_ARRIVALPOS, description, toEdge->getLength(),
1098  attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok), &myParsingRNG);
1099  if (arrPos >= bs->getBeginLanePosition() && arrPos < bs->getEndLanePosition()) {
1100  arrivalPos = arrPos;
1101  } else {
1102  WRITE_WARNING("Ignoring arrivalPos for " + description + " because it is outside the given stop '" + toString(SUMO_ATTR_BUS_STOP) + "'.");
1103  }
1104  }
1105  } else {
1106  if (toEdge == 0) {
1107  throw ProcessError("No destination edge for " + description + ".");
1108  }
1109  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
1110  arrivalPos = SUMOVehicleParserHelper::parseWalkPos(SUMO_ATTR_ARRIVALPOS, description, toEdge->getLength(),
1111  attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok), &myParsingRNG);
1112  } else {
1113  arrivalPos = -NUMERICAL_EPS;
1114  }
1115  }
1116 }
1117 
1118 
1119 /****************************************************************************/
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:90
double getLength() const
return the length of the edge
Definition: MSEdge.h:570
static StringBijection< SumoXMLTag > CarFollowModels
car following models
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:76
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:582
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:83
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
const int VEHPARS_FORCE_REROUTE
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
void parseFromViaTo(std::string element, const SUMOSAXAttributes &attrs)
Called for parsing from and to and the corresponding taz attributes.
description of a vehicle type
RandomDistributor< const MSRoute * > * myCurrentRouteDistribution
The currently parsed distribution of routes (probability->route)
The time is given.
is a pedestrian
std::string next()
static double _2doubleSec(const E *const data, double def)
converts a 0-terminated char-type array into the double value described by it
Definition: TplConvert.h:372
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.
virtual void closeVehicle()
Ends the processing of a vehicle.
MSParkingArea * getParkingArea(const std::string &id) const
Returns the named parking area.
Definition: MSNet.cpp:911
a flow definition (used by router)
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:168
SUMOVehicleParameter * myVehicleParameter
Parameter of the current vehicle, trip, person, container or flow.
The departure is container triggered.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
double repetitionProbability
The probability for emitting a vehicle per second.
static bool gStateLoaded
Information whether a state has been loaded.
Definition: MSGlobals.h:95
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.
void openRoute(const SUMOSAXAttributes &attrs)
MSPedestrianRouterDijkstra & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:993
double getDefaultProbability() const
Get the default probability of this vehicle type.
double myActiveRouteProbability
The probability of the current route.
MSChargingStation * getChargingStation(const std::string &id) const
Returns the named charging station.
Definition: MSNet.cpp:934
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:169
T MAX2(T a, T b)
Definition: StdDefs.h:74
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
double getEndLanePosition() const
Returns the end position of this stop.
virtual MSTransportable * buildPerson(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan) const
Builds a new person.
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:745
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.
const std::vector< double > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
void registerLastDepart()
save last depart (only to be used if vehicle is not discarded)
const double DEFAULT_VEH_PROB
std::string myActiveRouteID
The id of the current route.
void setCosts(double costs)
Sets the costs of the route.
Definition: MSRoute.h:174
int myInsertStopEdgesAt
where stop edges can be inserted into the current route (-1 means no insertion)
const std::string DEFAULT_VTYPE_ID
static MSVehicleType * build(SUMOVTypeParameter &from)
Builds the microsim vehicle type described by the given parameter.
static double parseWalkPos(SumoXMLAttr attr, const std::string &id, double maxPos, const std::string &val, std::mt19937 *rng=0)
parse departPos or arrivalPos for a walk
std::string parkingarea
(Optional) parking area if one is assigned to the stop
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:73
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
std::string toTaz
The vehicle&#39;s destination zone (district)
double computeChosenSpeedDeviation(std::mt19937 *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
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:775
int getQuota(double frac=-1) const
Returns the number of instances of the current vehicle that shall be emitted considering that "frac" ...
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:81
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
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.
the edges of a route
MSStoppingPlace * getBusStop(const std::string &id) const
Returns the named bus stop.
Definition: MSNet.cpp:864
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
void closeRouteDistribution()
std::string routeid
The vehicle&#39;s route id.
Representation of a vehicle.
Definition: SUMOVehicle.h:67
static bool gCheckRoutes
Definition: MSGlobals.h:86
double startPos
The stopping position start.
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:767
std::string chargingStation
(Optional) charging station if one is assigned to the stop
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:305
void closeVehicleTypeDistribution()
const double DEFAULT_CONTAINER_TRANSHIP_SPEED
bool hasAccess(const MSEdge *edge) const
checks whether this stop provides access to the given edge
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:47
int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:313
const int VEHPARS_ROUTE_SET
#define POSITION_EPS
Definition: config.h:176
std::string fromTaz
The vehicle&#39;s origin zone (district)
virtual MSTransportable * buildContainer(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan) const
Builds a new container.
double endPos
The stopping position end.
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:99
bool compute(const E *from, const E *to, double departPos, double arrivalPos, double 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...
SumoXMLTag myDefaultCFModel
the default car following model
const int VEHPARS_FROM_TAZ_SET
void registerOneWaitingForPerson()
increases the count of vehicles waiting for a person to allow recogniztion of person related deadlock...
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
MSTransportable::MSTransportablePlan * myActivePlan
The plan of the current person.
std::string lane
The lane to stop at.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, std::mt19937 *rng=0)
Returns the named vehicle type or a sample from the named distribution.
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.
std::vector< std::string > getVector()
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
void openRouteDistribution(const SUMOSAXAttributes &attrs)
virtual void myEndElement(int element)
Called when a closing tag occurs.
double departPos
(optional) The position the vehicle shall depart from
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:1553
void registerOneWaitingForContainer()
increases the count of vehicles waiting for a container to allow recogniztion of container related de...
static bool checkStopPos(double &startPos, double &endPos, const double laneLength, const double minLength, const bool friendlyPos)
check start and end position of a stop
std::vector< SUMOVehicleParameter::Stop > myActiveRouteStops
List of the stops on the parsed route.
Structure representing possible vehicle parameter.
const double DEFAULT_PEDESTRIAN_SPEED
virtual const MSRoute & getRoute() const =0
Returns the current route.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
bool myAmLoadingState
whether a state file is being loaded
static std::mt19937 myParsingRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:358
int setParameter
Information for the router which parameter were set, TraCI may modify this (whe changing color) ...
std::string myCurrentVTypeDistributionID
The id of the currently parsed vehicle type distribution.
Definition of vehicle stop (position and duration)
bool parseStop(SUMOVehicleParameter::Stop &stop, const SUMOSAXAttributes &attrs, std::string errorSuffix, MsgHandler *const errorOutput)
parses attributes common to all stops
MSStoppingPlace * getContainerStop(const std::string &id) const
Returns the named container stop.
Definition: MSNet.cpp:888
const std::string & getID() const
Returns the name of the vehicle type.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
double getBeginLanePosition() const
Returns the begin position of this stop.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle&#39;s parameter (including departure definition)
T get(const std::string &str) const
const RGBColor * myActiveRouteColor
The currently parsed route&#39;s color.
double myCurrentCosts
The currently parsed route costs.
long long int SUMOTime
Definition: TraCIDefs.h:52
#define NUMERICAL_EPS
Definition: config.h:152
virtual ~MSRouteHandler()
standard destructor
a single trip definition (used by router)
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.
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true)
Builds a vehicle, increases the number of built vehicles.
void release() const
deletes the route if there are no further references to it
Definition: MSRoute.cpp:105
void parseWalkPositions(const SUMOSAXAttributes &attrs, const std::string &personID, const MSEdge *fromEdge, const MSEdge *&toEdge, double &departPos, double &arrivalPos, MSStoppingPlace *&bs, bool &ok)
@ brief parse depart- and arrival positions of a walk
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
int getNumPredecessors() const
Returns the number of edges this edge is connected to.
Definition: MSEdge.h:336
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
static bool gUseMesoSim
Definition: MSGlobals.h:98
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.
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:802
void closeRoute(const bool mayBeDisconnected=false)
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:74
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:118