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 
61 // ===========================================================================
62 // static members
63 // ===========================================================================
65 
66 
67 // ===========================================================================
68 // method definitions
69 // ===========================================================================
70 MSRouteHandler::MSRouteHandler(const std::string& file,
71  bool addVehiclesDirectly) :
72  SUMORouteHandler(file),
73  myActivePlan(0),
74  myActiveContainerPlan(0),
75  myAddVehiclesDirectly(addVehiclesDirectly),
76  myCurrentVTypeDistribution(0),
77  myCurrentRouteDistribution(0),
78  myAmLoadingState(false) {
79  myActiveRoute.reserve(100);
80 }
81 
82 
84 }
85 
86 void
88  MSTransportable::MSTransportablePlan::iterator i;
89  if (myActivePlan != 0) {
90  for (i = myActivePlan->begin(); i != myActivePlan->end(); i++) {
91  delete *i;
92  }
93  delete myActivePlan;
94  myActivePlan = NULL;
95  }
96  if (myActiveContainerPlan != 0) {
97  for (i = myActiveContainerPlan->begin(); i != myActiveContainerPlan->end(); i++) {
98  delete *i;
99  }
100  delete myActiveContainerPlan;
101  myActivePlan = NULL;
102  }
103 }
104 
105 
106 void
107 MSRouteHandler::parseFromViaTo(std::string element,
108  const SUMOSAXAttributes& attrs) {
109  myActiveRoute.clear();
110  bool useTaz = OptionsCont::getOptions().getBool("with-taz");
112  WRITE_WARNING("Taz usage was requested but no taz present in " + element + " '" + myVehicleParameter->id + "'!");
113  useTaz = false;
114  }
115  bool ok = true;
117  const MSEdge* fromTaz = MSEdge::dictionary(myVehicleParameter->fromTaz + "-source");
118  if (fromTaz == 0) {
119  throw ProcessError("Source taz '" + myVehicleParameter->fromTaz + "' not known for " + element + " '" + myVehicleParameter->id + "'!");
120  } else if (fromTaz->getNumSuccessors() == 0) {
121  throw ProcessError("Source taz '" + myVehicleParameter->fromTaz + "' has no outgoing edges for " + element + " '" + myVehicleParameter->id + "'!");
122  } else {
123  myActiveRoute.push_back(fromTaz);
124  }
125  } else {
126  MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok, "", true),
127  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
128  }
129  if (!attrs.hasAttribute(SUMO_ATTR_VIA) && !attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
130  myInsertStopEdgesAt = (int)myActiveRoute.size();
131  }
132  MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok, "", true),
133  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
134  myVehicleParameter->via = StringTokenizer(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok, "", true)).getVector();
136  const MSEdge* toTaz = MSEdge::dictionary(myVehicleParameter->toTaz + "-sink");
137  if (toTaz == 0) {
138  throw ProcessError("Sink taz '" + myVehicleParameter->toTaz + "' not known for " + element + " '" + myVehicleParameter->id + "'!");
139  } else if (toTaz->getNumPredecessors() == 0) {
140  throw ProcessError("Sink taz '" + myVehicleParameter->toTaz + "' has no incoming edges for " + element + " '" + myVehicleParameter->id + "'!");
141  } else {
142  myActiveRoute.push_back(toTaz);
143  }
144  } else {
145  MSEdge::parseEdgesList(attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "", true),
146  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
147  }
149  if (myVehicleParameter->routeid == "") {
151  }
152 }
153 
154 
155 void
157  const SUMOSAXAttributes& attrs) {
158  SUMORouteHandler::myStartElement(element, attrs);
159  try {
160  switch (element) {
161  case SUMO_TAG_PERSON:
163  break;
164  case SUMO_TAG_CONTAINER:
166  break;
167  case SUMO_TAG_RIDE: {
168  const std::string pid = myVehicleParameter->id;
169  bool ok = true;
170  MSEdge* from = 0;
171  const std::string desc = attrs.get<std::string>(SUMO_ATTR_LINES, pid.c_str(), ok);
172  StringTokenizer st(desc);
173  std::string bsID = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, 0, ok, "");
174  MSStoppingPlace* bs = 0;
175  MSEdge* to = 0;
176  if (bsID != "") {
177  bs = MSNet::getInstance()->getBusStop(bsID);
178  if (bs == 0) {
179  throw ProcessError("Unknown bus stop '" + bsID + "' for person '" + myVehicleParameter->id + "'.");
180  }
181  to = &bs->getLane().getEdge();
182  }
183  if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
184  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, pid.c_str(), ok);
185  from = MSEdge::dictionary(fromID);
186  if (from == 0) {
187  throw ProcessError("The from edge '" + fromID + "' within a ride of person '" + pid + "' is not known.");
188  }
189  if (!myActivePlan->empty() && &myActivePlan->back()->getDestination() != from) {
190  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + fromID + "!=" + myActivePlan->back()->getDestination().getID() + ").");
191  }
192  if (myActivePlan->empty()) {
194  *from, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
195  }
196  } else if (myActivePlan->empty()) {
197  throw ProcessError("The start edge for person '" + pid + "' is not known.");
198  }
199  if (to == 0) {
200  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, pid.c_str(), ok);
201  to = MSEdge::dictionary(toID);
202  if (to == 0) {
203  throw ProcessError("The to edge '" + toID + "' within a ride of person '" + pid + "' is not known.");
204  }
205  }
206  myActivePlan->push_back(new MSPerson::MSPersonStage_Driving(*to, bs, -NUMERICAL_EPS, st.getVector()));
207  break;
208  }
209  case SUMO_TAG_WALK:
210  try {
211  myActiveRoute.clear();
212  bool ok = true;
213  const SUMOTime duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, 0, ok, -1);
214  if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
215  throw ProcessError("Non-positive walking duration for '" + myVehicleParameter->id + "'.");
216  }
217  double speed = DEFAULT_PEDESTRIAN_SPEED;
219  // need to check for explicitly set speed since we might have // DEFAULT_VEHTYPE
220  if (vtype != 0) {
221  speed = vtype->getMaxSpeed() * vtype->computeChosenSpeedDeviation(&myParsingRNG);
222  }
223  speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, 0, ok, speed);
224  if (speed <= 0) {
225  throw ProcessError("Non-positive walking speed for '" + myVehicleParameter->id + "'.");
226  }
227  double departPos = 0;
228  double arrivalPos = 0;
229  MSStoppingPlace* bs = 0;
230  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
232  parseWalkPositions(attrs, myVehicleParameter->id, myActiveRoute.front(), myActiveRoute.back(), departPos, arrivalPos, bs, ok);
233  } else {
234  const std::string fromID = attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok, "");
235  const MSEdge* from = fromID != "" || myActivePlan->empty() ? MSEdge::dictionary(fromID) : &myActivePlan->back()->getDestination();
236  if (from == 0) {
237  throw ProcessError("The from edge '" + fromID + "' within a walk of person '" + myVehicleParameter->id + "' is not known.");
238  }
239  const std::string toID = attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "");
240  const MSEdge* to = MSEdge::dictionary(toID);
241  if (toID != "" && to == 0) {
242  throw ProcessError("The to edge '" + toID + "' within a walk of person '" + myVehicleParameter->id + "' is not known.");
243  }
244  parseWalkPositions(attrs, myVehicleParameter->id, from, to, departPos, arrivalPos, bs, ok);
245  MSNet::getInstance()->getPedestrianRouter().compute(from, to, departPos, arrivalPos,
246  speed, 0, 0, myActiveRoute);
247  if (myActiveRoute.empty()) {
248  const std::string error = "No connection found between '" + from->getID() + "' and '" + to->getID() + "' for person '" + myVehicleParameter->id + "'.";
250  myActiveRoute.push_back(from);
251  myActiveRoute.push_back(to); // pedestrian will teleport
252  //WRITE_WARNING(error);
253  } else {
254  throw ProcessError(error);
255  }
256  }
257  //std::cout << myVehicleParameter->id << " edges=" << toString(myActiveRoute) << "\n";
258  }
259  if (myActiveRoute.empty()) {
260  throw ProcessError("No edges to walk for person '" + myVehicleParameter->id + "'.");
261  }
262  if (!myActivePlan->empty() && &myActivePlan->back()->getDestination() != myActiveRoute.front()) {
263  if (myActivePlan->back()->getDestinationStop() == 0 || !myActivePlan->back()->getDestinationStop()->hasAccess(myActiveRoute.front())) {
264  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + myActiveRoute.front()->getID() + " != " + myActivePlan->back()->getDestination().getID() + ").");
265  }
266  }
267  if (myActivePlan->empty()) {
269  *myActiveRoute.front(), -1, myVehicleParameter->depart, departPos, "start", true));
270  }
271  const double departPosLat = attrs.getOpt<double>(SUMO_ATTR_DEPARTPOS_LAT, 0, ok, 0);
272  myActivePlan->push_back(new MSPerson::MSPersonStage_Walking(myActiveRoute, bs, duration, speed, departPos, arrivalPos, departPosLat));
273  myActiveRoute.clear();
274  } catch (ProcessError&) {
276  throw;
277  }
278  break;
279  case SUMO_TAG_TRANSPORT:
280  try {
281  const std::string containerId = myVehicleParameter->id;
282  bool ok = true;
283  MSEdge* from = 0;
284  const std::string desc = attrs.get<std::string>(SUMO_ATTR_LINES, containerId.c_str(), ok);
285  StringTokenizer st(desc);
286  std::string csID = attrs.getOpt<std::string>(SUMO_ATTR_CONTAINER_STOP, 0, ok, "");
287  MSStoppingPlace* cs = 0;
288  if (csID != "") {
289  cs = MSNet::getInstance()->getContainerStop(csID);
290  if (cs == 0) {
291  throw ProcessError("Unknown container stop '" + csID + "' for container '" + myVehicleParameter->id + "'.");
292  }
293  }
294  if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
295  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, containerId.c_str(), ok);
296  from = MSEdge::dictionary(fromID);
297  if (from == 0) {
298  throw ProcessError("The from edge '" + fromID + "' within a transport of container '" + containerId + "' is not known.");
299  }
300  if (!myActiveContainerPlan->empty() && &myActiveContainerPlan->back()->getDestination() != from) {
301  throw ProcessError("Disconnected plan for container '" + myVehicleParameter->id + "' (" + fromID + "!=" + myActiveContainerPlan->back()->getDestination().getID() + ").");
302  }
303  if (myActiveContainerPlan->empty()) {
305  *from, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
306  }
307  } else if (myActiveContainerPlan->empty()) {
308  throw ProcessError("The start edge within a transport of container '" + containerId + "' is not known.");
309  }
310  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, containerId.c_str(), ok);
311  MSEdge* to = MSEdge::dictionary(toID);
312  if (to == 0) {
313  throw ProcessError("The to edge '" + toID + "' within a transport of container '" + containerId + "' is not known.");
314  }
315  myActiveContainerPlan->push_back(new MSContainer::MSContainerStage_Driving(*to, cs, -NUMERICAL_EPS, st.getVector()));
316 
317  } catch (ProcessError&) {
319  throw;
320  }
321  break;
322  case SUMO_TAG_TRANSHIP: {
323  myActiveRoute.clear();
324  bool ok = true;
325  double departPos = attrs.getOpt<double>(SUMO_ATTR_DEPARTPOS, myVehicleParameter->id.c_str(), ok, 0);
326  double arrivalPos = attrs.getOpt<double>(SUMO_ATTR_ARRIVALPOS, myVehicleParameter->id.c_str(), ok, -NUMERICAL_EPS);
327  double speed = DEFAULT_CONTAINER_TRANSHIP_SPEED;
329  // need to check for explicitly set speed since we might have // DEFAULT_VEHTYPE
330  if (vtype != 0 && vtype->wasSet(VTYPEPARS_MAXSPEED_SET)) {
331  speed = vtype->getMaxSpeed();
332  }
333  speed = attrs.getOpt<double>(SUMO_ATTR_SPEED, 0, ok, speed);
334  if (speed <= 0) {
335  throw ProcessError("Non-positive tranship speed for container '" + myVehicleParameter->id + "'.");
336  }
337  std::string csID = attrs.getOpt<std::string>(SUMO_ATTR_CONTAINER_STOP, 0, ok, "");
338  MSStoppingPlace* cs = 0;
339  if (csID != "") {
340  cs = MSNet::getInstance()->getContainerStop(csID);
341  if (cs == 0) {
342  throw ProcessError("Unknown container stop '" + csID + "' for container '" + myVehicleParameter->id + "'.");
343  }
344  arrivalPos = cs->getEndLanePosition();
345  }
346  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
348  } else {
349  if (attrs.hasAttribute(SUMO_ATTR_FROM) && attrs.hasAttribute(SUMO_ATTR_TO)) {
350  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok);
351  MSEdge* from = MSEdge::dictionary(fromID);
352  if (from == 0) {
353  throw ProcessError("The from edge '" + fromID + "' within a tranship of container '" + myVehicleParameter->id + "' is not known.");
354  }
355  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok);
356  MSEdge* to = MSEdge::dictionary(toID);
357  if (to == 0) {
358  throw ProcessError("The to edge '" + toID + "' within a tranship of container '" + myVehicleParameter->id + "' is not known.");
359  }
360  //the route of the container's tranship stage consists only of the 'from' and the 'to' edge
361  myActiveRoute.push_back(from);
362  myActiveRoute.push_back(to);
363  if (myActiveRoute.empty()) {
364  const std::string error = "No connection found between '" + from->getID() + "' and '" + to->getID() + "' for container '" + myVehicleParameter->id + "'.";
366  myActiveRoute.push_back(from);
367  } else {
368  WRITE_ERROR(error);
369  }
370  }
371  }
372  }
373  if (myActiveRoute.empty()) {
374  throw ProcessError("No edges to tranship container '" + myVehicleParameter->id + "'.");
375  }
376  if (!myActiveContainerPlan->empty() && &myActiveContainerPlan->back()->getDestination() != myActiveRoute.front()) {
377  throw ProcessError("Disconnected plan for container '" + myVehicleParameter->id + "' (" + myActiveRoute.front()->getID() + "!=" + myActiveContainerPlan->back()->getDestination().getID() + ").");
378  }
379  if (myActiveContainerPlan->empty()) {
381  *myActiveRoute.front(), -1, myVehicleParameter->depart, departPos, "start", true));
382  }
383  myActiveContainerPlan->push_back(new MSContainer::MSContainerStage_Tranship(myActiveRoute, cs, speed, departPos, arrivalPos));
384  myActiveRoute.clear();
385  break;
386  }
387  case SUMO_TAG_FLOW:
388  parseFromViaTo("flow", attrs);
389  break;
390  case SUMO_TAG_TRIP:
391  parseFromViaTo("trip", attrs);
392  break;
393  default:
394  break;
395  }
396  // parse embedded vtype information
397  if (myCurrentVType != 0 && element != SUMO_TAG_VTYPE && element != SUMO_TAG_PARAM) {
399  return;
400  }
401  } catch (ProcessError&) {
402  delete myVehicleParameter;
403  myVehicleParameter = 0;
404  throw;
405  }
406 }
407 
408 
409 void
411  bool ok = true;
412  myCurrentVTypeDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
413  if (ok) {
415  if (attrs.hasAttribute(SUMO_ATTR_VTYPES)) {
416  const std::string vTypes = attrs.get<std::string>(SUMO_ATTR_VTYPES, myCurrentVTypeDistributionID.c_str(), ok);
417  StringTokenizer st(vTypes);
418  while (st.hasNext()) {
419  std::string vtypeID = st.next();
421  if (type == 0) {
422  throw ProcessError("Unknown vtype '" + vtypeID + "' in distribution '" + myCurrentVTypeDistributionID + "'.");
423  }
425  }
426  }
427  }
428 }
429 
430 
431 void
433  if (myCurrentVTypeDistribution != 0) {
434  if (MSGlobals::gStateLoaded && MSNet::getInstance()->getVehicleControl().hasVTypeDistribution(myCurrentVTypeDistributionID)) {
436  return;
437  }
440  throw ProcessError("Vehicle type distribution '" + myCurrentVTypeDistributionID + "' is empty.");
441  }
442  if (!MSNet::getInstance()->getVehicleControl().addVTypeDistribution(myCurrentVTypeDistributionID, myCurrentVTypeDistribution)) {
444  throw ProcessError("Another vehicle type (or distribution) with the id '" + myCurrentVTypeDistributionID + "' exists.");
445  }
447  }
448 }
449 
450 
451 void
453  myActiveRoute.clear();
454  myInsertStopEdgesAt = -1;
455  // check whether the id is really necessary
456  std::string rid;
457  if (myCurrentRouteDistribution != 0) {
459  rid = "distribution '" + myCurrentRouteDistributionID + "'";
460  } else if (myVehicleParameter != 0) {
461  // ok, a vehicle is wrapping the route,
462  // we may use this vehicle's id as default
463  myActiveRouteID = "!" + myVehicleParameter->id; // !!! document this
464  if (attrs.hasAttribute(SUMO_ATTR_ID)) {
465  WRITE_WARNING("Ids of internal routes are ignored (vehicle '" + myVehicleParameter->id + "').");
466  }
467  } else {
468  bool ok = true;
469  myActiveRouteID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok, false);
470  if (!ok) {
471  return;
472  }
473  rid = "'" + myActiveRouteID + "'";
474  }
475  if (myVehicleParameter != 0) { // have to do this here for nested route distributions
476  rid = "for vehicle '" + myVehicleParameter->id + "'";
477  }
478  bool ok = true;
479  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
480  MSEdge::parseEdgesList(attrs.get<std::string>(SUMO_ATTR_EDGES, myActiveRouteID.c_str(), ok), myActiveRoute, rid);
481  }
482  myActiveRouteRefID = attrs.getOpt<std::string>(SUMO_ATTR_REFID, myActiveRouteID.c_str(), ok, "");
484  WRITE_ERROR("Invalid reference to route '" + myActiveRouteRefID + "' in route " + rid + ".");
485  }
488  myCurrentCosts = attrs.getOpt<double>(SUMO_ATTR_COST, myActiveRouteID.c_str(), ok, -1);
489  if (ok && myCurrentCosts != -1 && myCurrentCosts < 0) {
490  WRITE_ERROR("Invalid cost for route '" + myActiveRouteID + "'.");
491  }
492 }
493 
494 
495 void
498  switch (element) {
499  case SUMO_TAG_VTYPE: {
501  delete myCurrentVType;
502  myCurrentVType = 0;
503  if (!MSNet::getInstance()->getVehicleControl().addVType(vehType)) {
504  const std::string id = vehType->getID();
505  delete vehType;
507  throw ProcessError("Another vehicle type (or distribution) with the id '" + id + "' exists.");
508  }
509  } else {
510  if (myCurrentVTypeDistribution != 0) {
512  }
513  }
514  }
515  break;
516  case SUMO_TAG_TRIP:
518  closeRoute(true);
519  closeVehicle();
520  delete myVehicleParameter;
521  myVehicleParameter = 0;
522  myInsertStopEdgesAt = -1;
523  break;
524  default:
525  break;
526  }
527 }
528 
529 
530 void
531 MSRouteHandler::closeRoute(const bool mayBeDisconnected) {
532  std::string type = "vehicle";
533  if (mayBeDisconnected) {
535  type = "flow";
536  } else {
537  type = "trip";
538  }
539  }
540 
541  try {
542  if (myActiveRoute.size() == 0) {
543  delete myActiveRouteColor;
544  myActiveRouteColor = 0;
547  if (route != 0) {
549  route->addReference();
550  }
551  }
552  myActiveRouteID = "";
553  myActiveRouteRefID = "";
554  return;
555  }
556  if (myVehicleParameter != 0) {
557  throw ProcessError("The route for " + type + " '" + myVehicleParameter->id + "' has no edges.");
558  } else {
559  throw ProcessError("Route '" + myActiveRouteID + "' has no edges.");
560  }
561  }
562  if (myActiveRoute.size() == 1 && myActiveRoute.front()->getPurpose() == MSEdge::EDGEFUNCTION_DISTRICT) {
563  throw ProcessError("The routing information for " + type + " '" + myVehicleParameter->id + "' is insufficient.");
564  }
568  route->setCosts(myCurrentCosts);
569  myActiveRoute.clear();
570  if (!MSRoute::dictionary(myActiveRouteID, route)) {
571  delete route;
573  if (myVehicleParameter != 0) {
574  if (MSNet::getInstance()->getVehicleControl().getVehicle(myVehicleParameter->id) == 0) {
575  throw ProcessError("Another route for " + type + " '" + myVehicleParameter->id + "' exists.");
576  } else {
577  throw ProcessError("A vehicle with id '" + myVehicleParameter->id + "' already exists.");
578  }
579  } else {
580  throw ProcessError("Another route (or distribution) with the id '" + myActiveRouteID + "' exists.");
581  }
582  }
583  } else {
584  if (myCurrentRouteDistribution != 0) {
586  route->addReference();
587  }
588  }
589  }
590  myActiveRouteID = "";
591  myActiveRouteColor = 0;
592  myActiveRouteStops.clear();
593  } catch (ProcessError&) {
594  delete myVehicleParameter;
595  throw;
596  }
597 }
598 
599 
600 void
602  // check whether the id is really necessary
603  bool ok = true;
604  if (myVehicleParameter != 0) {
605  // ok, a vehicle is wrapping the route,
606  // we may use this vehicle's id as default
607  myCurrentRouteDistributionID = "!" + myVehicleParameter->id; // !!! document this
608  } else {
609  myCurrentRouteDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
610  if (!ok) {
611  return;
612  }
613  }
615  std::vector<double> probs;
616  if (attrs.hasAttribute(SUMO_ATTR_PROBS)) {
617  bool ok = true;
618  StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_PROBS, myCurrentRouteDistributionID.c_str(), ok));
619  while (st.hasNext()) {
620  probs.push_back(TplConvert::_2doubleSec(st.next().c_str(), 1.0));
621  }
622  }
623  if (attrs.hasAttribute(SUMO_ATTR_ROUTES)) {
624  bool ok = true;
625  StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_ROUTES, myCurrentRouteDistributionID.c_str(), ok));
626  int probIndex = 0;
627  while (st.hasNext()) {
628  std::string routeID = st.next();
629  const MSRoute* route = MSRoute::dictionary(routeID, &myParsingRNG);
630  if (route == 0) {
631  throw ProcessError("Unknown route '" + routeID + "' in distribution '" + myCurrentRouteDistributionID + "'.");
632  }
633  const double prob = ((int)probs.size() > probIndex ? probs[probIndex] : 1.0);
634  if (myCurrentRouteDistribution->add(route, prob, false)) {
635  route->addReference();
636  }
637  probIndex++;
638  }
639  if (probs.size() > 0 && probIndex != (int)probs.size()) {
640  WRITE_WARNING("Got " + toString(probs.size()) + " probabilities for " + toString(probIndex) +
641  " routes in routeDistribution '" + myCurrentRouteDistributionID + "'");
642  }
643  }
644 }
645 
646 
647 void
649  if (myCurrentRouteDistribution != 0) {
650  const bool haveSameID = MSRoute::dictionary(myCurrentRouteDistributionID, &myParsingRNG) != 0;
651  if (MSGlobals::gStateLoaded && haveSameID) {
653  return;
654  }
655  if (haveSameID) {
657  throw ProcessError("Another route (or distribution) with the id '" + myCurrentRouteDistributionID + "' exists.");
658  }
661  throw ProcessError("Route distribution '" + myCurrentRouteDistributionID + "' is empty.");
662  }
665  }
666 }
667 
668 
669 void
671  // get nested route
675  // let's check whether this vehicle had to depart before the simulation starts
677  if (route != 0) {
678  route->addReference();
679  route->release();
680  }
681  return;
682  }
683  }
684 
685  // get the vehicle's type
686  MSVehicleType* vtype = 0;
687 
688  try {
689  if (myVehicleParameter->vtypeid != "") {
690  vtype = vehControl.getVType(myVehicleParameter->vtypeid, &myParsingRNG);
691  if (vtype == 0) {
692  throw ProcessError("The vehicle type '" + myVehicleParameter->vtypeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
693  }
694  if (vtype->getVehicleClass() == SVC_PEDESTRIAN) {
695  WRITE_WARNING("Vehicle type '" + vtype->getID() + "' with vClass=pedestrian should only be used for persons and not for vehicle '" + myVehicleParameter->id + "'.");
696  }
697  } else {
698  // there should be one (at least the default one)
699  vtype = vehControl.getVType(DEFAULT_VTYPE_ID, &myParsingRNG);
700  }
701  if (route == 0) {
702  // if there is no nested route, try via the (hopefully) given route-id
704  }
705  if (route == 0) {
706  // nothing found? -> error
707  if (myVehicleParameter->routeid != "") {
708  throw ProcessError("The route '" + myVehicleParameter->routeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
709  } else {
710  throw ProcessError("Vehicle '" + myVehicleParameter->id + "' has no route.");
711  }
712  }
713  myActiveRouteID = "";
714 
715  } catch (ProcessError&) {
716  delete myVehicleParameter;
717  throw;
718  }
719 
720  // try to build the vehicle
721  SUMOVehicle* vehicle = 0;
722  if (vehControl.getVehicle(myVehicleParameter->id) == 0) {
723  try {
724  vehicle = vehControl.buildVehicle(myVehicleParameter, route, vtype, !MSGlobals::gCheckRoutes);
725  } catch (const ProcessError& e) {
727  WRITE_WARNING(e.what());
728  vehControl.deleteVehicle(0, true);
729  myVehicleParameter = 0;
730  vehicle = 0;
731  return;
732  } else {
733  throw e;
734  }
735  }
736  // maybe we do not want this vehicle to be inserted due to scaling
737  int quota = vehControl.getQuota();
738  if (quota > 0) {
739  vehControl.addVehicle(myVehicleParameter->id, vehicle);
741  const MSEdge* const firstEdge = vehicle->getRoute().getEdges()[0];
742  if (!MSGlobals::gUseMesoSim) {
743  // position will be checked against person position later
744  static_cast<MSVehicle*>(vehicle)->setTentativeLaneAndPosition(firstEdge->getLanes()[0], myVehicleParameter->departPos);
745  }
746  vehControl.addWaiting(*route->begin(), vehicle);
747  vehControl.registerOneWaitingForPerson();
749  const MSEdge* const firstEdge = vehicle->getRoute().getEdges()[0];
750  if (!MSGlobals::gUseMesoSim) {
751  // position will be checked against container position later
752  static_cast<MSVehicle*>(vehicle)->setTentativeLaneAndPosition(firstEdge->getLanes()[0], myVehicleParameter->departPos);
753  }
754  vehControl.addWaiting(*route->begin(), vehicle);
755  vehControl.registerOneWaitingForContainer();
756  } else {
757  // !!! no upscaling for triggered vehicles yet
758  for (int i = 1; i < quota; i++) {
761  newPars->id = myVehicleParameter->id + "." + toString(i);
762  vehicle = vehControl.buildVehicle(newPars, route, vtype, !MSGlobals::gCheckRoutes);
763  vehControl.addVehicle(newPars->id, vehicle);
764  }
765  }
767  myVehicleParameter = 0;
768  } else {
769  vehControl.deleteVehicle(vehicle, true);
770  myVehicleParameter = 0;
771  vehicle = 0;
772  }
773  } else {
774  // strange: another vehicle with the same id already exists
776  // and was not loaded while loading a simulation state
777  // -> error
778  std::string veh_id = myVehicleParameter->id;
779  delete myVehicleParameter;
780  myVehicleParameter = 0;
781  throw ProcessError("Another vehicle with the id '" + veh_id + "' exists.");
782  } else {
783  // ok, it seems to be loaded previously while loading a simulation state
784  vehicle = 0;
785  }
786  }
787  // check whether the vehicle shall be added directly to the network or
788  // shall stay in the internal buffer
789  if (vehicle != 0) {
790  if (vehicle->getParameter().departProcedure == DEPART_GIVEN) {
792  }
793  }
794 }
795 
796 
797 void
800  try {
801  if (myActivePlan->size() == 0) {
802  throw ProcessError("Person '" + myVehicleParameter->id + "' has no plan.");
803  }
804  if (type == 0) {
805  throw ProcessError("The type '" + myVehicleParameter->vtypeid + "' for person '" + myVehicleParameter->id + "' is not known.");
806  }
807  } catch (ProcessError&) {
808  delete myVehicleParameter;
809  myVehicleParameter = 0;
811  throw;
812  }
814  // @todo: consider myScale?
816  if (MSNet::getInstance()->getPersonControl().add(person)) {
818  } else {
819  ProcessError error("Another person with the id '" + myVehicleParameter->id + "' exists.");
820  delete person;
821  throw error;
822  }
823  } else {
824  // warning already given
825  delete person;
826  }
827  myVehicleParameter = 0;
828  myActivePlan = 0;
829 }
830 
831 void
833  if (myActiveContainerPlan->size() == 0) {
834  throw ProcessError("Container '" + myVehicleParameter->id + "' has no plan.");
835  }
837  if (type == 0) {
838  throw ProcessError("The type '" + myVehicleParameter->vtypeid + "' for container '" + myVehicleParameter->id + "' is not known.");
839  }
841  // @todo: consider myScale?
843  if (MSNet::getInstance()->getContainerControl().add(container)) {
845  } else {
846  ProcessError error("Another container with the id '" + myVehicleParameter->id + "' exists.");
847  delete container;
848  throw error;
849  }
850  } else {
851  // warning already given
852  delete container;
853  }
854  myVehicleParameter = 0;
856 }
857 
858 void
860  myInsertStopEdgesAt = -1;
862  delete myVehicleParameter;
863  myVehicleParameter = 0;
864  return;
865  }
866  // let's check whether vehicles had to depart before the simulation starts
869  const SUMOTime offsetToBegin = string2time(OptionsCont::getOptions().getString("begin")) - myVehicleParameter->depart;
873  delete myVehicleParameter;
874  myVehicleParameter = 0;
875  return;
876  }
877  }
878  }
879  if (MSNet::getInstance()->getVehicleControl().getVType(myVehicleParameter->vtypeid, &myParsingRNG) == 0) {
880  throw ProcessError("The vehicle type '" + myVehicleParameter->vtypeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
881  }
884  closeRoute(true);
885  }
887  throw ProcessError("The route '" + myVehicleParameter->routeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
888  }
889  myActiveRouteID = "";
890 
891  // check whether the vehicle shall be added directly to the network or
892  // shall stay in the internal buffer
894  if (MSNet::getInstance()->getInsertionControl().add(myVehicleParameter)) {
896  } else {
897  throw ProcessError("Another flow with the id '" + myVehicleParameter->id + "' exists.");
898  }
899  }
900  myVehicleParameter = 0;
901 }
902 
903 
904 void
906  std::string errorSuffix;
907  if (myActivePlan != 0) {
908  errorSuffix = " in person '" + myVehicleParameter->id + "'.";
909  } else if (myVehicleParameter != 0) {
910  errorSuffix = " in vehicle '" + myVehicleParameter->id + "'.";
911  } else if (myActiveContainerPlan != 0) {
912  errorSuffix = " in container '" + myVehicleParameter->id + "'.";
913  } else {
914  errorSuffix = " in route '" + myActiveRouteID + "'.";
915  }
917  bool ok = parseStop(stop, attrs, errorSuffix, MsgHandler::getErrorInstance());
918  if (!ok) {
919  return;
920  }
921  const MSEdge* edge = 0;
922  // try to parse the assigned bus stop
923  if (stop.busstop != "") {
924  // ok, we have a bus stop
926  if (bs == 0) {
927  WRITE_ERROR("The busStop '" + stop.busstop + "' is not known" + errorSuffix);
928  return;
929  }
930  const MSLane& l = bs->getLane();
931  stop.lane = l.getID();
932  stop.endPos = bs->getEndLanePosition();
933  stop.startPos = bs->getBeginLanePosition();
934  edge = &l.getEdge();
935  } //try to parse the assigned container stop
936  else if (stop.containerstop != "") {
937  // ok, we have obviously a container stop
939  if (cs == 0) {
940  WRITE_ERROR("The containerStop '" + stop.containerstop + "' is not known" + errorSuffix);
941  return;
942  }
943  const MSLane& l = cs->getLane();
944  stop.lane = l.getID();
945  stop.endPos = cs->getEndLanePosition();
946  stop.startPos = cs->getBeginLanePosition();
947  edge = &l.getEdge();
948  } //try to parse the assigned parking area
949  else if (stop.parkingarea != "") {
950  // ok, we have obviously a parking area
952  if (pa == 0) {
953  WRITE_ERROR("The parkingArea '" + stop.parkingarea + "' is not known" + errorSuffix);
954  return;
955  }
956  const MSLane& l = pa->getLane();
957  stop.lane = l.getID();
958  stop.endPos = pa->getEndLanePosition();
959  stop.startPos = pa->getBeginLanePosition();
960  edge = &l.getEdge();
961  } else if (stop.chargingStation != "") {
962  // ok, we have a charging station
964  if (cs != 0) {
965  const MSLane& l = cs->getLane();
966  stop.lane = l.getID();
967  stop.endPos = cs->getEndLanePosition();
968  stop.startPos = cs->getBeginLanePosition();
969  } else {
970  WRITE_ERROR("The chargingStation '" + stop.chargingStation + "' is not known" + errorSuffix);
971  return;
972  }
973  } else {
974  // no, the lane and the position should be given
975  // get the lane
976  stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, "");
977  if (ok && stop.lane != "") {
978  if (MSLane::dictionary(stop.lane) == 0) {
979  WRITE_ERROR("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix);
980  return;
981  }
982  } else {
983  if (myActivePlan && !myActivePlan->empty()) {
984  const MSStoppingPlace* bs = myActivePlan->back()->getDestinationStop();
985  if (bs != 0) {
986  edge = &bs->getLane().getEdge();
987  stop.lane = bs->getLane().getID();
988  stop.endPos = bs->getEndLanePosition();
989  stop.startPos = bs->getBeginLanePosition();
990  } else {
991  edge = &myActivePlan->back()->getDestination();
992  stop.lane = edge->getLanes()[0]->getID();
993  stop.endPos = myActivePlan->back()->getArrivalPos();
994  stop.startPos = stop.endPos - POSITION_EPS;
995  }
996  } else {
997  WRITE_ERROR("A stop must be placed on a busStop, a chargingStation, a containerStop a parkingArea or a lane" + errorSuffix);
998  return;
999  }
1000  }
1001  edge = &MSLane::dictionary(stop.lane)->getEdge();
1002  if (myActivePlan &&
1003  !myActivePlan->empty() &&
1004  &myActivePlan->back()->getDestination() != edge) {
1005  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + edge->getID() + "!=" + myActivePlan->back()->getDestination().getID() + ").");
1006  }
1007  if (myActivePlan && myActivePlan->empty()) {
1009  *edge, -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
1010  }
1011  if (myActiveContainerPlan &&
1012  !myActiveContainerPlan->empty() &&
1013  &myActiveContainerPlan->back()->getDestination() != &MSLane::dictionary(stop.lane)->getEdge()) {
1014  throw ProcessError("Disconnected plan for container '" + myVehicleParameter->id + "' (" + MSLane::dictionary(stop.lane)->getEdge().getID() + "!=" + myActiveContainerPlan->back()->getDestination().getID() + ").");
1015  }
1016  if (myActiveContainerPlan && myActiveContainerPlan->empty()) {
1018  MSLane::dictionary(stop.lane)->getEdge(), -1, myVehicleParameter->depart, myVehicleParameter->departPos, "start", true));
1019  }
1020  stop.endPos = attrs.getOpt<double>(SUMO_ATTR_ENDPOS, 0, ok, MSLane::dictionary(stop.lane)->getLength());
1021  if (attrs.hasAttribute(SUMO_ATTR_POSITION)) {
1022  WRITE_WARNING("Deprecated attribute 'pos' in description of stop" + errorSuffix);
1023  stop.endPos = attrs.getOpt<double>(SUMO_ATTR_POSITION, 0, ok, stop.endPos);
1024  }
1025  stop.startPos = attrs.getOpt<double>(SUMO_ATTR_STARTPOS, 0, ok, MAX2(0., stop.endPos - 2 * POSITION_EPS));
1026  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false);
1027  if (!ok || !checkStopPos(stop.startPos, stop.endPos, MSLane::dictionary(stop.lane)->getLength(), POSITION_EPS, friendlyPos)) {
1028  WRITE_ERROR("Invalid start or end position for stop on lane '" + stop.lane + "'" + errorSuffix);
1029  return;
1030  }
1031  }
1032  if (myActivePlan != 0) {
1033  std::string actType = attrs.getOpt<std::string>(SUMO_ATTR_ACTTYPE, 0, ok, "waiting");
1034  double pos = (stop.startPos + stop.endPos) / 2.;
1035  if (!myActivePlan->empty()) {
1036  pos = myActivePlan->back()->getArrivalPos();
1037  }
1039  MSLane::dictionary(stop.lane)->getEdge(), stop.duration, stop.until, pos, actType, false));
1040  } else if (myActiveContainerPlan != 0) {
1041  std::string actType = attrs.getOpt<std::string>(SUMO_ATTR_ACTTYPE, 0, ok, "waiting");
1043  MSLane::dictionary(stop.lane)->getEdge(), stop.duration, stop.until, stop.startPos, actType, false));
1044  } else if (myVehicleParameter != 0) {
1045  myVehicleParameter->stops.push_back(stop);
1046  } else {
1047  myActiveRouteStops.push_back(stop);
1048  }
1049  if (myInsertStopEdgesAt >= 0) {
1050  myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
1052  }
1053 }
1054 
1055 
1056 void
1057 MSRouteHandler::parseWalkPositions(const SUMOSAXAttributes& attrs, const std::string& personID,
1058  const MSEdge* fromEdge, const MSEdge*& toEdge,
1059  double& departPos, double& arrivalPos, MSStoppingPlace*& bs, bool& ok) {
1060  const std::string description = "person '" + personID + "' walking from " + fromEdge->getID();
1061 
1062  departPos = parseWalkPos(SUMO_ATTR_DEPARTPOS, description, fromEdge,
1063  attrs.getOpt<std::string>(SUMO_ATTR_DEPARTPOS, description.c_str(), ok, "0"));
1064 
1065  std::string bsID = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, 0, ok, "");
1066  if (bsID != "") {
1067  bs = MSNet::getInstance()->getBusStop(bsID);
1068  if (bs == 0) {
1069  throw ProcessError("Unknown bus stop '" + bsID + "' for " + description + ".");
1070  }
1071  arrivalPos = bs->getEndLanePosition();
1072  if (toEdge == 0) {
1073  toEdge = &bs->getLane().getEdge();
1074  }
1075  if (!bs->hasAccess(toEdge)) {
1076  throw ProcessError("Bus stop '" + bsID + "' is not connected to arrival edge '" + toEdge->getID() + "' for " + description + ".");
1077  }
1078  arrivalPos = (bs->getBeginLanePosition() + bs->getEndLanePosition()) / 2.;
1079  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
1080  const double arrPos = parseWalkPos(SUMO_ATTR_ARRIVALPOS, description, toEdge,
1081  attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok));
1082  if (arrPos >= bs->getBeginLanePosition() && arrPos < bs->getEndLanePosition()) {
1083  arrivalPos = arrPos;
1084  } else {
1085  WRITE_WARNING("Ignoring arrivalPos for " + description + " because it is outside the given stop '" + toString(SUMO_ATTR_BUS_STOP) + "'.");
1086  }
1087  }
1088  } else {
1089  if (toEdge == 0) {
1090  throw ProcessError("No destination edge for " + description + ".");
1091  }
1092  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
1093  arrivalPos = parseWalkPos(SUMO_ATTR_ARRIVALPOS, description, toEdge,
1094  attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, description.c_str(), ok));
1095  } else {
1096  arrivalPos = -NUMERICAL_EPS;
1097  }
1098  }
1099 }
1100 
1101 
1102 double
1103 MSRouteHandler::parseWalkPos(SumoXMLAttr attr, const std::string& id, const MSEdge* edge, const std::string& val) {
1104  double result;
1105  std::string error;
1106  ArrivalPosDefinition proc;
1107  // only supports 'random' and 'max'
1108  if (!SUMOVehicleParameter::parseArrivalPos(val, toString(SUMO_TAG_WALK), id, result, proc, error)) {
1109  throw ProcessError(error);
1110  }
1111  if (proc == ARRIVAL_POS_RANDOM) {
1112  result = myParsingRNG.rand(edge->getLength());
1113  } else if (proc == ARRIVAL_POS_MAX) {
1114  result = edge->getLength();
1115  }
1116  return SUMOVehicleParameter::interpretEdgePos(result, edge->getLength(), attr, id);
1117 }
1118 
1119 
1120 /****************************************************************************/
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
int getNumPredecessors() const
Returns the number of edges this edge is connected to.
Definition: MSEdge.h:355
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
double rand()
virtual void myEndElement(int element)
Called when a closing tag occurs.
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:582
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
double getBeginLanePosition() const
Returns the begin position of this stop.
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
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:128
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:355
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.
static MTRand myParsingRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
void release() const
deletes the route if there are no further references to it
Definition: MSRoute.cpp:105
static void parseVTypeEmbedded(SUMOVTypeParameter &into, int element, const SUMOSAXAttributes &attrs, bool fromVType=false)
Parses an element embedded in vtype definition.
virtual const MSRoute & getRoute() const =0
Returns the current route.
a flow definition (used by router)
A lane area vehicles can halt at.
Represents a generic random distribution.
bool myAddVehiclesDirectly
Information whether vehicles shall be directly added to the network or kept within the buffer...
SUMOTime duration
The stopping duration.
SUMOVehicleParameter * myVehicleParameter
Parameter of the current vehicle, trip, person, container or flow.
bool hasAccess(const MSEdge *edge) const
checks whether this stop provides access to the given edge
The departure is container triggered.
virtual MSTransportable * buildPerson(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan) const
Builds a new person.
double repetitionProbability
The probability for emitting a vehicle per second.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
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.
int getQuota(double frac=-1) const
Returns the number of instances of the current vehicle that shall be emitted considering that "frac" ...
void openRoute(const SUMOSAXAttributes &attrs)
double myActiveRouteProbability
The probability of the current route.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:158
T MAX2(T a, T b)
Definition: StdDefs.h:70
MSPedestrianRouterDijkstra & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:963
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:728
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)
const double DEFAULT_VEH_PROB
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getID() const
Returns the id.
Definition: Named.h:66
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)
MSChargingStation * getChargingStation(const std::string &id) const
Returns the named charging station.
Definition: MSNet.cpp:897
double getLength() const
return the length of the edge
Definition: MSEdge.h:586
const std::string DEFAULT_VTYPE_ID
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
static MSVehicleType * build(SUMOVTypeParameter &from)
Builds the microsim vehicle type described by the given parameter.
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:65
std::string toTaz
The vehicle&#39;s destination zone (district)
bool wasSet(int what) const
Returns whether the given parameter was set.
Definition: MSVehicleType.h:91
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:332
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:738
static double interpretEdgePos(double pos, double maximumValue, SumoXMLAttr attr, const std::string &id)
Interprets negative edge positions and fits them onto a given edge.
double getDefaultProbability() const
Get the default probability of this vehicle type.
std::string busstop
(Optional) bus stop if one is assigned to the stop
A road/street connecting two junctions.
Definition: MSEdge.h:80
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
double getEndLanePosition() const
Returns the end position of this stop.
RandomDistributor< MSVehicleType * > * myCurrentVTypeDistribution
The currently parsed distribution of vehicle types (probability->vehicle type)
The edge is a district edge.
Definition: MSEdge.h:99
the edges of a route
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.
const std::vector< double > & getProbs() const
Returns the probabilities assigned to the members of the distribution.
Representation of a vehicle.
Definition: SUMOVehicle.h:67
static bool gCheckRoutes
Definition: MSGlobals.h:86
double startPos
The stopping position start.
Encapsulated SAX-Attributes.
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:730
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
std::string chargingStation
(Optional) charging station if one is assigned to the stop
parameter associated to a certain key
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:310
void closeVehicleTypeDistribution()
const double DEFAULT_CONTAINER_TRANSHIP_SPEED
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.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:47
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
#define POSITION_EPS
Definition: config.h:175
std::string fromTaz
The vehicle&#39;s origin zone (district)
virtual MSTransportable * buildContainer(const SUMOVehicleParameter *pars, const 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;.
const int VEHPARS_FROM_TAZ_SET
void registerOneWaitingForPerson()
increases the count of vehicles waiting for a person to allow recogniztion of person related deadlock...
MSTransportable::MSTransportablePlan * myActivePlan
The plan of the current person.
std::string lane
The lane to stop at.
Parser for routes during their loading.
std::vector< std::string > via
List of the via-edges the vehicle must visit.
std::string myCurrentRouteDistributionID
The id of the currently parsed route distribution.
std::vector< std::string > getVector()
void openRouteDistribution(const SUMOSAXAttributes &attrs)
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
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:1371
MSStoppingPlace * getContainerStop(const std::string &id) const
Returns the named container stop.
Definition: MSNet.cpp:851
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.
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.
Structure representing possible vehicle parameter.
const double DEFAULT_PEDESTRIAN_SPEED
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:363
int setParameter
Information for the router which parameter were set, TraCI may modify this (whe changing color) ...
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle&#39;s parameter (including departure definition)
std::string myCurrentVTypeDistributionID
The id of the currently parsed vehicle type distribution.
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.
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
const std::string & getID() const
Returns the name of the vehicle type.
static bool parseArrivalPos(const std::string &val, const std::string &element, const std::string &id, double &pos, ArrivalPosDefinition &apd, std::string &error)
Validates a given arrivalPos value.
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:99
double parseWalkPos(SumoXMLAttr attr, const std::string &id, const MSEdge *edge, const std::string &val)
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
bool wasSet(int what) const
Returns whether the given parameter was set.
const RGBColor * myActiveRouteColor
The currently parsed route&#39;s color.
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...
double myCurrentCosts
The currently parsed route costs.
ArrivalPosDefinition
Possible ways to choose the arrival position.
long long int SUMOTime
Definition: TraCIDefs.h:52
#define NUMERICAL_EPS
Definition: config.h:151
virtual ~MSRouteHandler()
standard destructor
a single trip definition (used by router)
void openVehicleTypeDistribution(const SUMOSAXAttributes &attrs)
double computeChosenSpeedDeviation(MTRand *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:74
The class responsible for building and deletion of vehicles.
const MSLane & getLane() const
Returns the lane this stop is located at.
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
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, MTRand *rng=0)
Returns the named vehicle type or a sample from the named distribution.
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
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.
The maximum arrival position is used.
MSStoppingPlace * getBusStop(const std::string &id) const
Returns the named bus stop.
Definition: MSNet.cpp:827
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:784
void closeRoute(const bool mayBeDisconnected=false)
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
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
MSParkingArea * getParkingArea(const std::string &id) const
Returns the named parking area.
Definition: MSNet.cpp:874
The arrival position is chosen randomly.