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 
57 #include <microsim/MSGlobals.h>
59 
60 #ifdef CHECK_MEMORY_LEAKS
61 #include <foreign/nvwa/debug_new.h>
62 #endif // CHECK_MEMORY_LEAKS
63 
64 
65 // ===========================================================================
66 // static members
67 // ===========================================================================
69 
70 
71 // ===========================================================================
72 // method definitions
73 // ===========================================================================
74 MSRouteHandler::MSRouteHandler(const std::string& file,
75  bool addVehiclesDirectly) :
76  SUMORouteHandler(file),
77  myActivePlan(0),
78  myActiveContainerPlan(0),
79  myAddVehiclesDirectly(addVehiclesDirectly),
80  myCurrentVTypeDistribution(0),
81  myCurrentRouteDistribution(0),
82  myAmLoadingState(false) {
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 + "'");
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  if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
188  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, pid.c_str(), ok);
189  from = MSEdge::dictionary(fromID);
190  if (from == 0) {
191  throw ProcessError("The from edge '" + fromID + "' within a ride of person '" + pid + "' is not known.");
192  }
193  if (!myActivePlan->empty() && &myActivePlan->back()->getDestination() != from) {
194  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + fromID + "!=" + myActivePlan->back()->getDestination().getID() + ").");
195  }
196  if (myActivePlan->empty()) {
198  *from, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
199  }
200  } else if (myActivePlan->empty()) {
201  throw ProcessError("The start edge for person '" + pid + "' is not known.");
202  }
203  if (to == 0) {
204  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, pid.c_str(), ok);
205  to = MSEdge::dictionary(toID);
206  if (to == 0) {
207  throw ProcessError("The to edge '" + toID + "' within a ride of person '" + pid + "' is not known.");
208  }
209  }
210  myActivePlan->push_back(new MSPerson::MSPersonStage_Driving(*to, bs, -NUMERICAL_EPS, st.getVector()));
211  break;
212  }
213  case SUMO_TAG_WALK:
214  try {
215  myActiveRoute.clear();
216  bool ok = true;
217  const SUMOTime duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, 0, ok, -1);
218  if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
219  throw ProcessError("Non-positive walking duration for '" + myVehicleParameter->id + "'.");
220  }
223  // need to check for explicitly set speed since we might have // DEFAULT_VEHTYPE
224  if (vtype != 0) {
225  speed = vtype->getMaxSpeed() * vtype->computeChosenSpeedDeviation(&myParsingRNG);
226  }
227  speed = attrs.getOpt<SUMOReal>(SUMO_ATTR_SPEED, 0, ok, speed);
228  if (speed <= 0) {
229  throw ProcessError("Non-positive walking speed for '" + myVehicleParameter->id + "'.");
230  }
231  SUMOReal departPos = 0;
232  SUMOReal arrivalPos = 0;
233  MSStoppingPlace* bs = 0;
234  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
236  parseWalkPositions(attrs, myVehicleParameter->id, myActiveRoute.front(), myActiveRoute.back(), departPos, arrivalPos, bs, ok);
237  } else {
238  const std::string fromID = attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok, "");
239  const MSEdge* from = fromID != "" || myActivePlan->empty() ? MSEdge::dictionary(fromID) : &myActivePlan->back()->getDestination();
240  if (from == 0) {
241  throw ProcessError("The from edge '" + fromID + "' within a walk of person '" + myVehicleParameter->id + "' is not known.");
242  }
243  const std::string toID = attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "");
244  const MSEdge* to = MSEdge::dictionary(toID);
245  if (toID != "" && to == 0) {
246  throw ProcessError("The to edge '" + toID + "' within a walk of person '" + myVehicleParameter->id + "' is not known.");
247  }
248  parseWalkPositions(attrs, myVehicleParameter->id, from, to, departPos, arrivalPos, bs, ok);
249  MSNet::getInstance()->getPedestrianRouter().compute(from, to, departPos, arrivalPos,
250  speed, 0, 0, myActiveRoute);
251  if (myActiveRoute.empty()) {
252  const std::string error = "No connection found between '" + from->getID() + "' and '" + to->getID() + "' for person '" + myVehicleParameter->id + "'.";
254  myActiveRoute.push_back(from);
255  myActiveRoute.push_back(to); // pedestrian will teleport
256  //WRITE_WARNING(error);
257  } else {
258  throw ProcessError(error);
259  }
260  }
261  //std::cout << myVehicleParameter->id << " edges=" << toString(myActiveRoute) << "\n";
262  }
263  if (myActiveRoute.empty()) {
264  throw ProcessError("No edges to walk for person '" + myVehicleParameter->id + "'.");
265  }
266  if (!myActivePlan->empty() && &myActivePlan->back()->getDestination() != myActiveRoute.front()) {
267  if (myActivePlan->back()->getDestinationStop() == 0 || !myActivePlan->back()->getDestinationStop()->hasAccess(myActiveRoute.front())) {
268  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + myActiveRoute.front()->getID() + " != " + myActivePlan->back()->getDestination().getID() + ").");
269  }
270  }
271  if (myActivePlan->empty()) {
273  *myActiveRoute.front(), -1, myVehicleParameter->depart, departPos, "start", true));
274  }
275  const SUMOReal departPosLat = attrs.getOpt<SUMOReal>(SUMO_ATTR_DEPARTPOS_LAT, 0, ok, 0);
276  myActivePlan->push_back(new MSPerson::MSPersonStage_Walking(myActiveRoute, bs, duration, speed, departPos, arrivalPos, departPosLat));
277  myActiveRoute.clear();
278  } catch (ProcessError&) {
280  throw;
281  }
282  break;
283  case SUMO_TAG_TRANSPORT:
284  try {
285  const std::string containerId = myVehicleParameter->id;
286  bool ok = true;
287  MSEdge* from = 0;
288  const std::string desc = attrs.get<std::string>(SUMO_ATTR_LINES, containerId.c_str(), ok);
289  StringTokenizer st(desc);
290  std::string csID = attrs.getOpt<std::string>(SUMO_ATTR_CONTAINER_STOP, 0, ok, "");
291  MSStoppingPlace* cs = 0;
292  if (csID != "") {
293  cs = MSNet::getInstance()->getContainerStop(csID);
294  if (cs == 0) {
295  throw ProcessError("Unknown container stop '" + csID + "' for container '" + myVehicleParameter->id + "'.");
296  }
297  }
298  if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
299  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, containerId.c_str(), ok);
300  from = MSEdge::dictionary(fromID);
301  if (from == 0) {
302  throw ProcessError("The from edge '" + fromID + "' within a transport of container '" + containerId + "' is not known.");
303  }
304  if (!myActiveContainerPlan->empty() && &myActiveContainerPlan->back()->getDestination() != from) {
305  throw ProcessError("Disconnected plan for container '" + myVehicleParameter->id + "' (" + fromID + "!=" + myActiveContainerPlan->back()->getDestination().getID() + ").");
306  }
307  if (myActiveContainerPlan->empty()) {
309  *from, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
310  }
311  } else if (myActiveContainerPlan->empty()) {
312  throw ProcessError("The start edge within a transport of container '" + containerId + "' is not known.");
313  }
314  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, containerId.c_str(), ok);
315  MSEdge* to = MSEdge::dictionary(toID);
316  if (to == 0) {
317  throw ProcessError("The to edge '" + toID + "' within a transport of container '" + containerId + "' is not known.");
318  }
319  myActiveContainerPlan->push_back(new MSContainer::MSContainerStage_Driving(*to, cs, -NUMERICAL_EPS, st.getVector()));
320 
321  } catch (ProcessError&) {
323  throw;
324  }
325  break;
326  case SUMO_TAG_TRANSHIP: {
327  myActiveRoute.clear();
328  bool ok = true;
329  SUMOReal departPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_DEPARTPOS, myVehicleParameter->id.c_str(), ok, 0);
330  SUMOReal arrivalPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ARRIVALPOS, myVehicleParameter->id.c_str(), ok, -NUMERICAL_EPS);
333  // need to check for explicitly set speed since we might have // DEFAULT_VEHTYPE
334  if (vtype != 0 && vtype->wasSet(VTYPEPARS_MAXSPEED_SET)) {
335  speed = vtype->getMaxSpeed();
336  }
337  speed = attrs.getOpt<SUMOReal>(SUMO_ATTR_SPEED, 0, ok, speed);
338  if (speed <= 0) {
339  throw ProcessError("Non-positive tranship speed for container '" + myVehicleParameter->id + "'.");
340  }
341  std::string csID = attrs.getOpt<std::string>(SUMO_ATTR_CONTAINER_STOP, 0, ok, "");
342  MSStoppingPlace* cs = 0;
343  if (csID != "") {
344  cs = MSNet::getInstance()->getContainerStop(csID);
345  if (cs == 0) {
346  throw ProcessError("Unknown container stop '" + csID + "' for container '" + myVehicleParameter->id + "'.");
347  }
348  arrivalPos = cs->getEndLanePosition();
349  }
350  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
352  } else {
353  if (attrs.hasAttribute(SUMO_ATTR_FROM) && attrs.hasAttribute(SUMO_ATTR_TO)) {
354  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok);
355  MSEdge* from = MSEdge::dictionary(fromID);
356  if (from == 0) {
357  throw ProcessError("The from edge '" + fromID + "' within a tranship of container '" + myVehicleParameter->id + "' is not known.");
358  }
359  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok);
360  MSEdge* to = MSEdge::dictionary(toID);
361  if (to == 0) {
362  throw ProcessError("The to edge '" + toID + "' within a tranship of container '" + myVehicleParameter->id + "' is not known.");
363  }
364  //the route of the container's tranship stage consists only of the 'from' and the 'to' edge
365  myActiveRoute.push_back(from);
366  myActiveRoute.push_back(to);
367  if (myActiveRoute.empty()) {
368  const std::string error = "No connection found between '" + from->getID() + "' and '" + to->getID() + "' for container '" + myVehicleParameter->id + "'.";
370  myActiveRoute.push_back(from);
371  } else {
372  WRITE_ERROR(error);
373  }
374  }
375  }
376  }
377  if (myActiveRoute.empty()) {
378  throw ProcessError("No edges to tranship container '" + myVehicleParameter->id + "'.");
379  }
380  if (!myActiveContainerPlan->empty() && &myActiveContainerPlan->back()->getDestination() != myActiveRoute.front()) {
381  throw ProcessError("Disconnected plan for container '" + myVehicleParameter->id + "' (" + myActiveRoute.front()->getID() + "!=" + myActiveContainerPlan->back()->getDestination().getID() + ").");
382  }
383  if (myActiveContainerPlan->empty()) {
385  *myActiveRoute.front(), -1, myVehicleParameter->depart, departPos, "start", true));
386  }
387  myActiveContainerPlan->push_back(new MSContainer::MSContainerStage_Tranship(myActiveRoute, cs, speed, departPos, arrivalPos));
388  myActiveRoute.clear();
389  break;
390  }
391  case SUMO_TAG_FLOW:
392  parseFromViaTo("flow", attrs);
393  break;
394  case SUMO_TAG_TRIP:
395  parseFromViaTo("trip", attrs);
396  break;
397  default:
398  break;
399  }
400  // parse embedded vtype information
401  if (myCurrentVType != 0 && element != SUMO_TAG_VTYPE && element != SUMO_TAG_PARAM) {
403  return;
404  }
405  } catch (ProcessError&) {
406  delete myVehicleParameter;
407  myVehicleParameter = 0;
408  throw;
409  }
410 }
411 
412 
413 void
415  bool ok = true;
416  myCurrentVTypeDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
417  if (ok) {
419  if (attrs.hasAttribute(SUMO_ATTR_VTYPES)) {
420  const std::string vTypes = attrs.get<std::string>(SUMO_ATTR_VTYPES, myCurrentVTypeDistributionID.c_str(), ok);
421  StringTokenizer st(vTypes);
422  while (st.hasNext()) {
423  std::string vtypeID = st.next();
425  if (type == 0) {
426  throw ProcessError("Unknown vtype '" + vtypeID + "' in distribution '" + myCurrentVTypeDistributionID + "'.");
427  }
429  }
430  }
431  }
432 }
433 
434 
435 void
437  if (myCurrentVTypeDistribution != 0) {
438  if (MSGlobals::gStateLoaded && MSNet::getInstance()->getVehicleControl().hasVTypeDistribution(myCurrentVTypeDistributionID)) {
440  return;
441  }
444  throw ProcessError("Vehicle type distribution '" + myCurrentVTypeDistributionID + "' is empty.");
445  }
446  if (!MSNet::getInstance()->getVehicleControl().addVTypeDistribution(myCurrentVTypeDistributionID, myCurrentVTypeDistribution)) {
448  throw ProcessError("Another vehicle type (or distribution) with the id '" + myCurrentVTypeDistributionID + "' exists.");
449  }
451  }
452 }
453 
454 
455 void
457  myActiveRoute.clear();
458  myInsertStopEdgesAt = -1;
459  // check whether the id is really necessary
460  std::string rid;
461  if (myCurrentRouteDistribution != 0) {
463  rid = "distribution '" + myCurrentRouteDistributionID + "'";
464  } else if (myVehicleParameter != 0) {
465  // ok, a vehicle is wrapping the route,
466  // we may use this vehicle's id as default
467  myActiveRouteID = "!" + myVehicleParameter->id; // !!! document this
468  if (attrs.hasAttribute(SUMO_ATTR_ID)) {
469  WRITE_WARNING("Ids of internal routes are ignored (vehicle '" + myVehicleParameter->id + "').");
470  }
471  } else {
472  bool ok = true;
473  myActiveRouteID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok, false);
474  if (!ok) {
475  return;
476  }
477  rid = "'" + myActiveRouteID + "'";
478  }
479  if (myVehicleParameter != 0) { // have to do this here for nested route distributions
480  rid = "for vehicle '" + myVehicleParameter->id + "'";
481  }
482  bool ok = true;
483  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
484  MSEdge::parseEdgesList(attrs.get<std::string>(SUMO_ATTR_EDGES, myActiveRouteID.c_str(), ok), myActiveRoute, rid);
485  }
486  myActiveRouteRefID = attrs.getOpt<std::string>(SUMO_ATTR_REFID, myActiveRouteID.c_str(), ok, "");
488  WRITE_ERROR("Invalid reference to route '" + myActiveRouteRefID + "' in route " + rid + ".");
489  }
492  myCurrentCosts = attrs.getOpt<SUMOReal>(SUMO_ATTR_COST, myActiveRouteID.c_str(), ok, -1);
493  if (ok && myCurrentCosts != -1 && myCurrentCosts < 0) {
494  WRITE_ERROR("Invalid cost for route '" + myActiveRouteID + "'.");
495  }
496 }
497 
498 
499 void
502  switch (element) {
503  case SUMO_TAG_VTYPE: {
505  delete myCurrentVType;
506  myCurrentVType = 0;
507  if (!MSNet::getInstance()->getVehicleControl().addVType(vehType)) {
508  const std::string id = vehType->getID();
509  delete vehType;
511  throw ProcessError("Another vehicle type (or distribution) with the id '" + id + "' exists.");
512  }
513  } else {
514  if (myCurrentVTypeDistribution != 0) {
516  }
517  }
518  }
519  break;
520  case SUMO_TAG_TRIP:
522  closeRoute(true);
523  closeVehicle();
524  delete myVehicleParameter;
525  myVehicleParameter = 0;
526  myInsertStopEdgesAt = -1;
527  break;
528  default:
529  break;
530  }
531 }
532 
533 
534 void
535 MSRouteHandler::closeRoute(const bool mayBeDisconnected) {
536  std::string type = "vehicle";
537  if (mayBeDisconnected) {
539  type = "flow";
540  } else {
541  type = "trip";
542  }
543  }
544 
545  try {
546  if (myActiveRoute.size() == 0) {
547  delete myActiveRouteColor;
548  myActiveRouteColor = 0;
551  if (route != 0) {
553  route->addReference();
554  }
555  }
556  myActiveRouteID = "";
557  myActiveRouteRefID = "";
558  return;
559  }
560  if (myVehicleParameter != 0) {
561  throw ProcessError("The route for " + type + " '" + myVehicleParameter->id + "' has no edges.");
562  } else {
563  throw ProcessError("Route '" + myActiveRouteID + "' has no edges.");
564  }
565  }
566  if (myActiveRoute.size() == 1 && myActiveRoute.front()->getPurpose() == MSEdge::EDGEFUNCTION_DISTRICT) {
567  throw ProcessError("The routing information for " + type + " '" + myVehicleParameter->id + "' is insufficient.");
568  }
572  route->setCosts(myCurrentCosts);
573  myActiveRoute.clear();
574  if (!MSRoute::dictionary(myActiveRouteID, route)) {
575  delete route;
577  if (myVehicleParameter != 0) {
578  if (MSNet::getInstance()->getVehicleControl().getVehicle(myVehicleParameter->id) == 0) {
579  throw ProcessError("Another route for " + type + " '" + myVehicleParameter->id + "' exists.");
580  } else {
581  throw ProcessError("A vehicle with id '" + myVehicleParameter->id + "' already exists.");
582  }
583  } else {
584  throw ProcessError("Another route (or distribution) with the id '" + myActiveRouteID + "' exists.");
585  }
586  }
587  } else {
588  if (myCurrentRouteDistribution != 0) {
590  route->addReference();
591  }
592  }
593  }
594  myActiveRouteID = "";
595  myActiveRouteColor = 0;
596  myActiveRouteStops.clear();
597  } catch (ProcessError&) {
598  delete myVehicleParameter;
599  throw;
600  }
601 }
602 
603 
604 void
606  // check whether the id is really necessary
607  bool ok = true;
608  if (myVehicleParameter != 0) {
609  // ok, a vehicle is wrapping the route,
610  // we may use this vehicle's id as default
611  myCurrentRouteDistributionID = "!" + myVehicleParameter->id; // !!! document this
612  } else {
613  myCurrentRouteDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
614  if (!ok) {
615  return;
616  }
617  }
619  std::vector<SUMOReal> probs;
620  if (attrs.hasAttribute(SUMO_ATTR_PROBS)) {
621  bool ok = true;
622  StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_PROBS, myCurrentRouteDistributionID.c_str(), ok));
623  while (st.hasNext()) {
624  probs.push_back(TplConvert::_2SUMORealSec(st.next().c_str(), 1.0));
625  }
626  }
627  if (attrs.hasAttribute(SUMO_ATTR_ROUTES)) {
628  bool ok = true;
629  StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_ROUTES, myCurrentRouteDistributionID.c_str(), ok));
630  int probIndex = 0;
631  while (st.hasNext()) {
632  std::string routeID = st.next();
633  const MSRoute* route = MSRoute::dictionary(routeID, &myParsingRNG);
634  if (route == 0) {
635  throw ProcessError("Unknown route '" + routeID + "' in distribution '" + myCurrentRouteDistributionID + "'.");
636  }
637  const SUMOReal prob = ((int)probs.size() > probIndex ? probs[probIndex] : 1.0);
638  if (myCurrentRouteDistribution->add(prob, route, false)) {
639  route->addReference();
640  }
641  probIndex++;
642  }
643  if (probs.size() > 0 && probIndex != (int)probs.size()) {
644  WRITE_WARNING("Got " + toString(probs.size()) + " probabilities for " + toString(probIndex) +
645  " routes in routeDistribution '" + myCurrentRouteDistributionID + "'");
646  }
647  }
648 }
649 
650 
651 void
653  if (myCurrentRouteDistribution != 0) {
654  const bool haveSameID = MSRoute::dictionary(myCurrentRouteDistributionID, &myParsingRNG) != 0;
655  if (MSGlobals::gStateLoaded && haveSameID) {
657  return;
658  }
659  if (haveSameID) {
661  throw ProcessError("Another route (or distribution) with the id '" + myCurrentRouteDistributionID + "' exists.");
662  }
665  throw ProcessError("Route distribution '" + myCurrentRouteDistributionID + "' is empty.");
666  }
669  }
670 }
671 
672 
673 void
675  // get nested route
679  // let's check whether this vehicle had to depart before the simulation starts
681  if (route != 0) {
682  route->addReference();
683  route->release();
684  }
685  return;
686  }
687  }
688 
689  // get the vehicle's type
690  MSVehicleType* vtype = 0;
691 
692  try {
693  if (myVehicleParameter->vtypeid != "") {
694  vtype = vehControl.getVType(myVehicleParameter->vtypeid, &myParsingRNG);
695  if (vtype == 0) {
696  throw ProcessError("The vehicle type '" + myVehicleParameter->vtypeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
697  }
698  if (vtype->getVehicleClass() == SVC_PEDESTRIAN) {
699  WRITE_WARNING("Vehicle type '" + vtype->getID() + "' with vClass=pedestrian should only be used for persons and not for vehicle '" + myVehicleParameter->id + "'.");
700  }
701  } else {
702  // there should be one (at least the default one)
703  vtype = vehControl.getVType(DEFAULT_VTYPE_ID, &myParsingRNG);
704  }
705  if (route == 0) {
706  // if there is no nested route, try via the (hopefully) given route-id
708  }
709  if (route == 0) {
710  // nothing found? -> error
711  if (myVehicleParameter->routeid != "") {
712  throw ProcessError("The route '" + myVehicleParameter->routeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
713  } else {
714  throw ProcessError("Vehicle '" + myVehicleParameter->id + "' has no route.");
715  }
716  }
717  myActiveRouteID = "";
718 
719  } catch (ProcessError&) {
720  delete myVehicleParameter;
721  throw;
722  }
723 
724  // try to build the vehicle
725  SUMOVehicle* vehicle = 0;
726  if (vehControl.getVehicle(myVehicleParameter->id) == 0) {
727  try {
728  vehicle = vehControl.buildVehicle(myVehicleParameter, route, vtype, !MSGlobals::gCheckRoutes);
729  } catch (const ProcessError& e) {
731  WRITE_WARNING(e.what());
732  vehControl.deleteVehicle(0, true);
733  myVehicleParameter = 0;
734  vehicle = 0;
735  return;
736  } else {
737  throw e;
738  }
739  }
740  // maybe we do not want this vehicle to be inserted due to scaling
741  int quota = vehControl.getQuota();
742  if (quota > 0) {
743  vehControl.addVehicle(myVehicleParameter->id, vehicle);
745  const MSEdge* const firstEdge = vehicle->getRoute().getEdges()[0];
746  if (!MSGlobals::gUseMesoSim) {
747  // position will be checked against person position later
748  static_cast<MSVehicle*>(vehicle)->setTentativeLaneAndPosition(firstEdge->getLanes()[0], myVehicleParameter->departPos);
749  }
750  vehControl.addWaiting(*route->begin(), vehicle);
751  vehControl.registerOneWaitingForPerson();
753  const MSEdge* const firstEdge = vehicle->getRoute().getEdges()[0];
754  if (!MSGlobals::gUseMesoSim) {
755  // position will be checked against container position later
756  static_cast<MSVehicle*>(vehicle)->setTentativeLaneAndPosition(firstEdge->getLanes()[0], myVehicleParameter->departPos);
757  }
758  vehControl.addWaiting(*route->begin(), vehicle);
759  vehControl.registerOneWaitingForContainer();
760  } else {
761  // !!! no upscaling for triggered vehicles yet
762  for (int i = 1; i < quota; i++) {
765  newPars->id = myVehicleParameter->id + "." + toString(i);
766  vehicle = vehControl.buildVehicle(newPars, route, vtype, !MSGlobals::gCheckRoutes);
767  vehControl.addVehicle(newPars->id, vehicle);
768  }
769  }
771  myVehicleParameter = 0;
772  } else {
773  vehControl.deleteVehicle(vehicle, true);
774  myVehicleParameter = 0;
775  vehicle = 0;
776  }
777  } else {
778  // strange: another vehicle with the same id already exists
780  // and was not loaded while loading a simulation state
781  // -> error
782  std::string veh_id = myVehicleParameter->id;
783  delete myVehicleParameter;
784  myVehicleParameter = 0;
785  throw ProcessError("Another vehicle with the id '" + veh_id + "' exists.");
786  } else {
787  // ok, it seems to be loaded previously while loading a simulation state
788  vehicle = 0;
789  }
790  }
791  // check whether the vehicle shall be added directly to the network or
792  // shall stay in the internal buffer
793  if (vehicle != 0) {
794  if (vehicle->getParameter().departProcedure == DEPART_GIVEN) {
796  }
797  }
798 }
799 
800 
801 void
804  try {
805  if (myActivePlan->size() == 0) {
806  throw ProcessError("Person '" + myVehicleParameter->id + "' has no plan.");
807  }
808  if (type == 0) {
809  throw ProcessError("The type '" + myVehicleParameter->vtypeid + "' for person '" + myVehicleParameter->id + "' is not known.");
810  }
811  } catch (ProcessError&) {
812  delete myVehicleParameter;
813  myVehicleParameter = 0;
815  throw;
816  }
818  // @todo: consider myScale?
820  if (MSNet::getInstance()->getPersonControl().add(person)) {
822  } else {
823  ProcessError error("Another person with the id '" + myVehicleParameter->id + "' exists.");
824  delete person;
825  throw error;
826  }
827  } else {
828  // warning already given
829  delete person;
830  }
831  myVehicleParameter = 0;
832  myActivePlan = 0;
833 }
834 
835 void
837  if (myActiveContainerPlan->size() == 0) {
838  throw ProcessError("Container '" + myVehicleParameter->id + "' has no plan.");
839  }
841  if (type == 0) {
842  throw ProcessError("The type '" + myVehicleParameter->vtypeid + "' for container '" + myVehicleParameter->id + "' is not known.");
843  }
845  // @todo: consider myScale?
847  if (MSNet::getInstance()->getContainerControl().add(container)) {
849  } else {
850  ProcessError error("Another container with the id '" + myVehicleParameter->id + "' exists.");
851  delete container;
852  throw error;
853  }
854  } else {
855  // warning already given
856  delete container;
857  }
858  myVehicleParameter = 0;
860 }
861 
862 void
864  myInsertStopEdgesAt = -1;
866  delete myVehicleParameter;
867  myVehicleParameter = 0;
868  return;
869  }
870  // let's check whether vehicles had to depart before the simulation starts
873  const SUMOTime offsetToBegin = string2time(OptionsCont::getOptions().getString("begin")) - myVehicleParameter->depart;
877  delete myVehicleParameter;
878  myVehicleParameter = 0;
879  return;
880  }
881  }
882  }
883  if (MSNet::getInstance()->getVehicleControl().getVType(myVehicleParameter->vtypeid, &myParsingRNG) == 0) {
884  throw ProcessError("The vehicle type '" + myVehicleParameter->vtypeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
885  }
888  closeRoute(true);
889  }
891  throw ProcessError("The route '" + myVehicleParameter->routeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
892  }
893  myActiveRouteID = "";
894 
895  // check whether the vehicle shall be added directly to the network or
896  // shall stay in the internal buffer
898  if (MSNet::getInstance()->getInsertionControl().add(myVehicleParameter)) {
900  } else {
901  throw ProcessError("Another flow with the id '" + myVehicleParameter->id + "' exists.");
902  }
903  }
904  myVehicleParameter = 0;
905 }
906 
907 
908 void
910  std::string errorSuffix;
911  if (myActivePlan != 0) {
912  errorSuffix = " in person '" + myVehicleParameter->id + "'.";
913  } else if (myVehicleParameter != 0) {
914  errorSuffix = " in vehicle '" + myVehicleParameter->id + "'.";
915  } else if (myActiveContainerPlan != 0) {
916  errorSuffix = " in container '" + myVehicleParameter->id + "'.";
917  } else {
918  errorSuffix = " in route '" + myActiveRouteID + "'.";
919  }
921  bool ok = parseStop(stop, attrs, errorSuffix, MsgHandler::getErrorInstance());
922  if (!ok) {
923  return;
924  }
925  const MSEdge* edge = 0;
926  // try to parse the assigned bus stop
927  if (stop.busstop != "") {
928  // ok, we have a bus stop
930  if (bs == 0) {
931  WRITE_ERROR("The busStop '" + stop.busstop + "' is not known" + errorSuffix);
932  return;
933  }
934  const MSLane& l = bs->getLane();
935  stop.lane = l.getID();
936  stop.endPos = bs->getEndLanePosition();
937  stop.startPos = bs->getBeginLanePosition();
938  edge = &l.getEdge();
939  } //try to parse the assigned container stop
940  else if (stop.containerstop != "") {
941  // ok, we have obviously a container stop
943  if (cs == 0) {
944  WRITE_ERROR("The containerStop '" + stop.containerstop + "' is not known" + errorSuffix);
945  return;
946  }
947  const MSLane& l = cs->getLane();
948  stop.lane = l.getID();
949  stop.endPos = cs->getEndLanePosition();
950  stop.startPos = cs->getBeginLanePosition();
951  edge = &l.getEdge();
952  } //try to parse the assigned parking area
953  else if (stop.parkingarea != "") {
954  // ok, we have obviously a parking area
956  if (pa == 0) {
957  WRITE_ERROR("The parkingArea '" + stop.parkingarea + "' is not known" + errorSuffix);
958  return;
959  }
960  const MSLane& l = pa->getLane();
961  stop.lane = l.getID();
962  stop.endPos = pa->getEndLanePosition();
963  stop.startPos = pa->getBeginLanePosition();
964  edge = &l.getEdge();
965  } else if (stop.chargingStation != "") {
966  // ok, we have a charging station
968  if (cs != 0) {
969  const MSLane& l = cs->getLane();
970  stop.lane = l.getID();
971  stop.endPos = cs->getEndLanePosition();
972  stop.startPos = cs->getBeginLanePosition();
973  } else {
974  WRITE_ERROR("The chargingStation '" + stop.chargingStation + "' is not known" + errorSuffix);
975  return;
976  }
977  } else {
978  // no, the lane and the position should be given
979  // get the lane
980  stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, "");
981  if (ok && stop.lane != "") {
982  if (MSLane::dictionary(stop.lane) == 0) {
983  WRITE_ERROR("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix);
984  return;
985  }
986  } else {
987  if (myActivePlan && !myActivePlan->empty()) {
988  const MSStoppingPlace* bs = myActivePlan->back()->getDestinationStop();
989  if (bs != 0) {
990  edge = &bs->getLane().getEdge();
991  stop.lane = bs->getLane().getID();
992  stop.endPos = bs->getEndLanePosition();
993  stop.startPos = bs->getBeginLanePosition();
994  } else {
995  edge = &myActivePlan->back()->getDestination();
996  stop.lane = edge->getLanes()[0]->getID();
997  stop.endPos = myActivePlan->back()->getArrivalPos();
998  stop.startPos = stop.endPos - POSITION_EPS;
999  }
1000  } else {
1001  WRITE_ERROR("A stop must be placed on a busStop, a chargingStation, a containerStop a parkingArea or a lane" + errorSuffix);
1002  return;
1003  }
1004  }
1005  edge = &MSLane::dictionary(stop.lane)->getEdge();
1006  if (myActivePlan &&
1007  !myActivePlan->empty() &&
1008  &myActivePlan->back()->getDestination() != edge) {
1009  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + edge->getID() + "!=" + myActivePlan->back()->getDestination().getID() + ").");
1010  }
1011  if (myActivePlan && myActivePlan->empty()) {
1013  *edge, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
1014  }
1015  if (myActiveContainerPlan &&
1016  !myActiveContainerPlan->empty() &&
1017  &myActiveContainerPlan->back()->getDestination() != &MSLane::dictionary(stop.lane)->getEdge()) {
1018  throw ProcessError("Disconnected plan for container '" + myVehicleParameter->id + "' (" + MSLane::dictionary(stop.lane)->getEdge().getID() + "!=" + myActiveContainerPlan->back()->getDestination().getID() + ").");
1019  }
1020  if (myActiveContainerPlan && myActiveContainerPlan->empty()) {
1022  MSLane::dictionary(stop.lane)->getEdge(), -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
1023  }
1024  stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ENDPOS, 0, ok, MSLane::dictionary(stop.lane)->getLength());
1025  if (attrs.hasAttribute(SUMO_ATTR_POSITION)) {
1026  WRITE_WARNING("Deprecated attribute 'pos' in description of stop" + errorSuffix);
1027  stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_POSITION, 0, ok, stop.endPos);
1028  }
1029  stop.startPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_STARTPOS, 0, ok, MAX2((SUMOReal)0., stop.endPos - 2 * POSITION_EPS));
1030  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false);
1031  if (!ok || !checkStopPos(stop.startPos, stop.endPos, MSLane::dictionary(stop.lane)->getLength(), POSITION_EPS, friendlyPos)) {
1032  WRITE_ERROR("Invalid start or end position for stop on lane '" + stop.lane + "'" + errorSuffix);
1033  return;
1034  }
1035  }
1036  if (myActivePlan != 0) {
1037  std::string actType = attrs.getOpt<std::string>(SUMO_ATTR_ACTTYPE, 0, ok, "waiting");
1038  SUMOReal pos = (stop.startPos + stop.endPos) / 2.;
1039  if (!myActivePlan->empty()) {
1040  pos = myActivePlan->back()->getArrivalPos();
1041  }
1043  MSLane::dictionary(stop.lane)->getEdge(), stop.duration, stop.until, pos, actType, false));
1044  } else if (myActiveContainerPlan != 0) {
1045  std::string actType = attrs.getOpt<std::string>(SUMO_ATTR_ACTTYPE, 0, ok, "waiting");
1047  MSLane::dictionary(stop.lane)->getEdge(), stop.duration, stop.until, stop.startPos, actType, false));
1048  } else if (myVehicleParameter != 0) {
1049  myVehicleParameter->stops.push_back(stop);
1050  } else {
1051  myActiveRouteStops.push_back(stop);
1052  }
1053  if (myInsertStopEdgesAt >= 0) {
1054  myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
1056  }
1057 }
1058 
1059 
1060 void
1061 MSRouteHandler::parseWalkPositions(const SUMOSAXAttributes& attrs, const std::string& personID,
1062  const MSEdge* fromEdge, const MSEdge*& toEdge,
1063  SUMOReal& departPos, SUMOReal& arrivalPos, MSStoppingPlace*& bs, bool& ok) {
1064  const std::string description = "person '" + personID + "' walking from " + fromEdge->getID();
1065 
1066  departPos = parseWalkPos(SUMO_ATTR_DEPARTPOS, description, fromEdge,
1067  attrs.getOpt<std::string>(SUMO_ATTR_DEPARTPOS, description.c_str(), ok, "0"));
1068 
1069  std::string bsID = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, 0, ok, "");
1070  if (bsID != "") {
1071  bs = MSNet::getInstance()->getBusStop(bsID);
1072  if (bs == 0) {
1073  throw ProcessError("Unknown bus stop '" + bsID + "' for " + description + ".");
1074  }
1075  arrivalPos = bs->getEndLanePosition();
1076  if (toEdge == 0) {
1077  toEdge = &bs->getLane().getEdge();
1078  }
1079  if (!bs->hasAccess(toEdge)) {
1080  throw ProcessError("Bus stop '" + bsID + "' is not connected to arrival edge '" + toEdge->getID() + "' for " + description + ".");
1081  }
1082  arrivalPos = (bs->getBeginLanePosition() + bs->getEndLanePosition()) / 2.;
1083  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
1084  const SUMOReal arrPos = parseWalkPos(SUMO_ATTR_ARRIVALPOS, description, toEdge,
1085  attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok));
1086  if (arrPos >= bs->getBeginLanePosition() && arrPos < bs->getEndLanePosition()) {
1087  arrivalPos = arrPos;
1088  } else {
1089  WRITE_WARNING("Ignoring arrivalPos for " + description + " because it is outside the given stop '" + toString(SUMO_ATTR_BUS_STOP) + "'.");
1090  }
1091  }
1092  } else {
1093  if (toEdge == 0) {
1094  throw ProcessError("No destination edge for " + description + ".");
1095  }
1096  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
1097  arrivalPos = parseWalkPos(SUMO_ATTR_ARRIVALPOS, description, toEdge,
1098  attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok));
1099  } else {
1100  arrivalPos = -NUMERICAL_EPS;
1101  }
1102  }
1103 }
1104 
1105 
1106 SUMOReal
1107 MSRouteHandler::parseWalkPos(SumoXMLAttr attr, const std::string& id, const MSEdge* edge, const std::string& val) {
1108  SUMOReal result;
1109  std::string error;
1110  ArrivalPosDefinition proc;
1111  // only supports 'random' and 'max'
1112  if (!SUMOVehicleParameter::parseArrivalPos(val, toString(SUMO_TAG_WALK), id, result, proc, error)) {
1113  throw ProcessError(error);
1114  }
1115  if (proc == ARRIVAL_POS_RANDOM) {
1116  result = myParsingRNG.rand(edge->getLength());
1117  } else if (proc == ARRIVAL_POS_MAX) {
1118  result = edge->getLength();
1119  }
1120  return SUMOVehicleParameter::interpretEdgePos(result, edge->getLength(), attr, id);
1121 }
1122 
1123 
1124 /****************************************************************************/
The departure is person triggered.
void addStop(const SUMOSAXAttributes &attrs)
Processing of a stop.
const int VTYPEPARS_MAXSPEED_SET
const int VEHPARS_TO_TAZ_SET
MSRouteHandler(const std::string &file, bool addVehiclesDirectly)
standard constructor
bool wasSet(int what) const
Returns whether the given parameter was set.
Definition: MSVehicleType.h:91
SUMOReal repetitionProbability
The probability for emitting a vehicle per second.
virtual MSTransportable * buildPerson(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan) const
Builds a new person.
void addWaiting(const MSEdge *const edge, SUMOVehicle *vehicle)
Adds a vehicle to the list of waiting vehiclse to a given edge.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
SUMOReal myCurrentCosts
The currently parsed route costs.
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:571
double rand()
virtual void myEndElement(int element)
Called when a closing tag occurs.
ConstMSEdgeVector myActiveRoute
The current route.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
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
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)
const std::vector< SUMOReal > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
The time is given.
is a pedestrian
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.
int getQuota(SUMOReal frac=-1) const
Returns the number of instances of the current vehicle that shall be emitted considering that "frac" ...
virtual 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.
MSParkingArea * getParkingArea(const std::string &id) const
Returns the named parking area.
Definition: MSNet.cpp:854
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.
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 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:192
SUMOVehicleParameter * myVehicleParameter
Parameter of the current vehicle, trip, person, container or flow.
The departure is container triggered.
bool add(SUMOReal prob, T val, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static bool checkStopPos(SUMOReal &startPos, SUMOReal &endPos, const SUMOReal laneLength, const SUMOReal minLength, const bool friendlyPos)
check start and end position of a stop
static bool gStateLoaded
Information whether a state has been loaded.
Definition: MSGlobals.h:92
SUMOVTypeParameter * myCurrentVType
The currently parsed vehicle type.
void closePerson()
Ends the processing of a person.
int repetitionsDone
The number of times the vehicle was already inserted.
const SUMOReal DEFAULT_PEDESTRIAN_SPEED
void openRoute(const SUMOSAXAttributes &attrs)
MSPedestrianRouterDijkstra & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:934
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:877
static SUMOReal _2SUMORealSec(const E *const data, SUMOReal def)
converts a 0-terminated char-type array into the SUMOReal value described by it
Definition: TplConvert.h:355
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
T MAX2(T a, T b)
Definition: StdDefs.h:70
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.
SUMOReal computeChosenSpeedDeviation(MTRand *rng, const SUMOReal minDevFactor=0.2) const
Computes and returns the speed deviation.
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:693
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
static MSVehicleType * build(SUMOVTypeParameter &from)
Builds the microsim vehicle type described by the given parameter.
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: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, 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:718
static SUMOReal interpretEdgePos(SUMOReal pos, SUMOReal maximumValue, SumoXMLAttr attr, const std::string &id)
Interprets negative edge positions and fits them onto a given edge.
std::string busstop
(Optional) bus stop if one is assigned to the stop
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A road/street connecting two junctions.
Definition: MSEdge.h:80
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
SUMOReal getLength() const
return the length of the edge
Definition: MSEdge.h:580
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:807
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
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:83
Encapsulated SAX-Attributes.
bool wasSet(int what) const
Returns whether the given parameter was set.
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:710
std::string chargingStation
(Optional) charging station if one is assigned to the stop
parameter associated to a certain key
SUMOReal endPos
The stopping position end.
void deleteActivePlans()
delete already created MSTransportablePlans if error occurs before handing over responsibility to a M...
void closeContainer()
Ends the processing of a container.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h: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:47
int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:332
#define POSITION_EPS
Definition: config.h:182
std::string fromTaz
The vehicle&#39;s origin zone (district)
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...
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.
Parser for routes during their loading.
std::vector< std::string > via
List of the via-edges the vehicle must visit.
std::string myCurrentRouteDistributionID
The id of the currently parsed route distribution.
virtual MSTransportable * buildContainer(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan) const
Builds a new container.
std::vector< std::string > getVector()
void parseWalkPositions(const SUMOSAXAttributes &attrs, const std::string &personID, const MSEdge *fromEdge, const MSEdge *&toEdge, SUMOReal &departPos, SUMOReal &arrivalPos, MSStoppingPlace *&bs, bool &ok)
@ brief parse depart- and arrival positions of a walk
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
void openRouteDistribution(const SUMOSAXAttributes &attrs)
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:1317
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 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
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:361
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)
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:831
const std::string & getID() const
Returns the name of the vehicle type.
SUMOReal departPos
(optional) The position the vehicle shall depart from
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle&#39;s parameter (including departure definition)
const RGBColor * myActiveRouteColor
The currently parsed route&#39;s color.
#define SUMOReal
Definition: config.h:208
ArrivalPosDefinition
Possible ways to choose the arrival position.
#define NUMERICAL_EPS
Definition: config.h:158
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.
void release() const
deletes the route if there are no further references to it
Definition: MSRoute.cpp:109
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, MTRand *rng=0)
Returns the named vehicle type or a sample from the named distribution.
int getNumPredecessors() const
Returns the number of edges this edge is connected to.
Definition: MSEdge.h:355
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
static bool gUseMesoSim
Definition: MSGlobals.h:95
bool checkLastDepart()
Checks whether the route file is sorted by departure time if needed.
std::string myActiveRouteRefID
The id of the route the current route references to.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
A color information.
The maximum arrival position is used.
static void parseEdgesList(const std::string &desc, ConstMSEdgeVector &into, const std::string &rid)
Parses the given string assuming it contains a list of edge ids divided by spaces.
Definition: MSEdge.cpp:749
void closeRoute(const bool mayBeDisconnected=false)
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:78
void closeFlow()
Ends the processing of a flow.
MSTransportable::MSTransportablePlan * myActiveContainerPlan
The plan of the current container.
std::string id
The vehicle&#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.