SUMO - Simulation of Urban MObility
RORouteHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Parser and container for routes during their loading
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <map>
36 #include <vector>
37 #include <iostream>
47 #include <utils/xml/XMLSubSys.h>
49 #include "ROPerson.h"
50 #include "RONet.h"
51 #include "ROEdge.h"
52 #include "ROLane.h"
53 #include "RORouteDef.h"
54 #include "RORouteHandler.h"
55 
56 #ifdef CHECK_MEMORY_LEAKS
57 #include <foreign/nvwa/debug_new.h>
58 #endif // CHECK_MEMORY_LEAKS
59 
60 
61 // ===========================================================================
62 // method definitions
63 // ===========================================================================
64 RORouteHandler::RORouteHandler(RONet& net, const std::string& file,
65  const bool tryRepair,
66  const bool emptyDestinationsAllowed,
67  const bool ignoreErrors) :
68  SUMORouteHandler(file),
69  myNet(net),
70  myActivePerson(0),
71  myActiveContainerPlan(0),
72  myActiveContainerPlanSize(0),
73  myTryRepair(tryRepair),
74  myEmptyDestinationsAllowed(emptyDestinationsAllowed),
75  myErrorOutput(ignoreErrors ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance()),
76  myCurrentVTypeDistribution(0),
77  myCurrentAlternatives(0) {
78  myActiveRoute.reserve(100);
79 }
80 
81 
83 }
84 
85 
86 void
87 RORouteHandler::parseFromViaTo(std::string element,
88  const SUMOSAXAttributes& attrs) {
89  myActiveRoute.clear();
90  bool useTaz = OptionsCont::getOptions().getBool("with-taz");
92  WRITE_WARNING("Taz usage was requested but no taz present in " + element + " '" + myVehicleParameter->id + "'!");
93  useTaz = false;
94  }
95  bool ok = true;
97  const ROEdge* fromTaz = myNet.getEdge(myVehicleParameter->fromTaz + "-source");
98  if (fromTaz == 0) {
99  myErrorOutput->inform("Source taz '" + myVehicleParameter->fromTaz + "' not known for " + element + " '" + myVehicleParameter->id + "'!");
100  } else if (fromTaz->getNumSuccessors() == 0) {
101  myErrorOutput->inform("Source taz '" + myVehicleParameter->fromTaz + "' has no outgoing edges for " + element + " '" + myVehicleParameter->id + "'!");
102  } else {
103  myActiveRoute.push_back(fromTaz);
104  }
105  } else {
106  parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok, "", true),
107  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
108  }
109  if (!attrs.hasAttribute(SUMO_ATTR_VIA)) {
110  myInsertStopEdgesAt = (int)myActiveRoute.size();
111  }
112  parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok, "", true),
113  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
115  const ROEdge* toTaz = myNet.getEdge(myVehicleParameter->toTaz + "-sink");
116  if (toTaz == 0) {
117  myErrorOutput->inform("Sink taz '" + myVehicleParameter->toTaz + "' not known for " + element + " '" + myVehicleParameter->id + "'!");
118  } else if (toTaz->getNumPredecessors() == 0) {
119  myErrorOutput->inform("Sink taz '" + myVehicleParameter->toTaz + "' has no incoming edges for " + element + " '" + myVehicleParameter->id + "'!");
120  } else {
121  myActiveRoute.push_back(toTaz);
122  }
123  } else {
124  parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "", true),
125  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
126  }
128  if (myVehicleParameter->routeid == "") {
130  }
131 }
132 
133 
134 void
136  const SUMOSAXAttributes& attrs) {
137  SUMORouteHandler::myStartElement(element, attrs);
138  switch (element) {
139  case SUMO_TAG_PERSON: {
141  if (type == 0) {
142  myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for person '" + myVehicleParameter->id + "' is not known.");
144  }
146  break;
147  }
148  case SUMO_TAG_RIDE: {
149  std::vector<ROPerson::PlanItem*>& plan = myActivePerson->getPlan();
150  const std::string pid = myVehicleParameter->id;
151  bool ok = true;
152  ROEdge* from = 0;
153  if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
154  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, pid.c_str(), ok);
155  from = myNet.getEdge(fromID);
156  if (from == 0) {
157  throw ProcessError("The from edge '" + fromID + "' within a ride of person '" + pid + "' is not known.");
158  }
159  if (!plan.empty() && plan.back()->getDestination() != from) {
160  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + fromID + "!=" + plan.back()->getDestination()->getID() + ").");
161  }
162  } else if (plan.empty()) {
163  throw ProcessError("The start edge for person '" + pid + "' is not known.");
164  }
165  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, pid.c_str(), ok);
166  ROEdge* to = myNet.getEdge(toID);
167  if (to == 0) {
168  throw ProcessError("The to edge '" + toID + "' within a ride of person '" + pid + "' is not known.");
169  }
170  const std::string desc = attrs.get<std::string>(SUMO_ATTR_LINES, pid.c_str(), ok);
171  const std::string busStop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, pid.c_str(), ok, "");
172  myActivePerson->addRide(from, to, desc, busStop);
173  break;
174  }
175  case SUMO_TAG_PERSONTRIP:
176  case SUMO_TAG_WALK: {
177  bool ok = true;
178  const char* const objId = myVehicleParameter->id.c_str();
179  const SUMOTime duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, objId, ok, -1);
180  if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
181  throw ProcessError("Non-positive walking duration for '" + myVehicleParameter->id + "'.");
182  }
183  const SUMOReal speed = attrs.getOpt<SUMOReal>(SUMO_ATTR_SPEED, objId, ok, -1.);
184  if (attrs.hasAttribute(SUMO_ATTR_SPEED) && speed <= 0) {
185  throw ProcessError("Non-positive walking speed for '" + myVehicleParameter->id + "'.");
186  }
187  const SUMOReal departPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_DEPARTPOS, objId, ok, std::numeric_limits<SUMOReal>::infinity());
188  const SUMOReal arrivalPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ARRIVALPOS, objId, ok, std::numeric_limits<SUMOReal>::infinity());
189  const std::string busStop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, objId, ok, "");
190  if (!ok) {
191  break;
192  }
193  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
194  // XXX allow --repair?
195  myActiveRoute.clear();
196  parseEdges(attrs.get<std::string>(SUMO_ATTR_EDGES, myVehicleParameter->id.c_str(), ok), myActiveRoute, " walk for person '" + myVehicleParameter->id + "'");
197  myActivePerson->addWalk(myActiveRoute, duration, speed, departPos, arrivalPos, busStop);
198  } else {
199  addPersonTrip(attrs);
200  }
201  break;
202  }
203  case SUMO_TAG_CONTAINER:
207  (*myActiveContainerPlan) << attrs;
208  break;
209  case SUMO_TAG_TRANSPORT: {
211  (*myActiveContainerPlan) << attrs;
214  break;
215  }
216  case SUMO_TAG_TRANSHIP: {
217  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
218  // copy walk as it is
219  // XXX allow --repair?
221  (*myActiveContainerPlan) << attrs;
224  } else {
225  //routePerson(attrs, *myActiveContainerPlan);
226  }
227  break;
228  }
229  case SUMO_TAG_FLOW:
231  parseFromViaTo("flow", attrs);
232  break;
233  case SUMO_TAG_TRIP: {
235  parseFromViaTo("trip", attrs);
236  }
237  break;
238  default:
239  break;
240  }
241  // parse embedded vtype information
242  if (myCurrentVType != 0 && element != SUMO_TAG_VTYPE && element != SUMO_TAG_PARAM) {
244  return;
245  }
246 }
247 
248 
249 void
251  bool ok = true;
252  myCurrentVTypeDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
253  if (ok) {
255  if (attrs.hasAttribute(SUMO_ATTR_VTYPES)) {
256  const std::string vTypes = attrs.get<std::string>(SUMO_ATTR_VTYPES, myCurrentVTypeDistributionID.c_str(), ok);
257  StringTokenizer st(vTypes);
258  while (st.hasNext()) {
259  SUMOVTypeParameter* type = myNet.getVehicleTypeSecure(st.next());
260  myCurrentVTypeDistribution->add(1., type);
261  }
262  }
263  }
264 }
265 
266 
267 void
269  if (myCurrentVTypeDistribution != 0) {
272  myErrorOutput->inform("Vehicle type distribution '" + myCurrentVTypeDistributionID + "' is empty.");
275  myErrorOutput->inform("Another vehicle type (or distribution) with the id '" + myCurrentVTypeDistributionID + "' exists.");
276  }
278  }
279 }
280 
281 
282 void
284  myActiveRoute.clear();
285  myInsertStopEdgesAt = -1;
286  // check whether the id is really necessary
287  std::string rid;
288  if (myCurrentAlternatives != 0) {
290  rid = "distribution '" + myCurrentAlternatives->getID() + "'";
291  } else if (myVehicleParameter != 0) {
292  // ok, a vehicle is wrapping the route,
293  // we may use this vehicle's id as default
294  myVehicleParameter->routeid = myActiveRouteID = "!" + myVehicleParameter->id; // !!! document this
295  if (attrs.hasAttribute(SUMO_ATTR_ID)) {
296  WRITE_WARNING("Ids of internal routes are ignored (vehicle '" + myVehicleParameter->id + "').");
297  }
298  } else {
299  bool ok = true;
300  myActiveRouteID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
301  if (!ok) {
302  return;
303  }
304  rid = "'" + myActiveRouteID + "'";
305  }
306  if (myVehicleParameter != 0) { // have to do this here for nested route distributions
307  rid = "for vehicle '" + myVehicleParameter->id + "'";
308  }
309  bool ok = true;
310  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
311  parseEdges(attrs.get<std::string>(SUMO_ATTR_EDGES, myActiveRouteID.c_str(), ok), myActiveRoute, rid);
312  }
313  myActiveRouteRefID = attrs.getOpt<std::string>(SUMO_ATTR_REFID, myActiveRouteID.c_str(), ok, "");
315  myErrorOutput->inform("Invalid reference to route '" + myActiveRouteRefID + "' in route " + rid + ".");
316  }
317  if (myCurrentAlternatives != 0 && !attrs.hasAttribute(SUMO_ATTR_PROB)) {
318  WRITE_WARNING("No probability for a route in '" + rid + "', using default.");
319  }
321  if (ok && myActiveRouteProbability < 0) {
322  myErrorOutput->inform("Invalid probability for route '" + myActiveRouteID + "'.");
323  }
325  ok = true;
326  myCurrentCosts = attrs.getOpt<SUMOReal>(SUMO_ATTR_COST, myActiveRouteID.c_str(), ok, -1);
327  if (ok && myCurrentCosts != -1 && myCurrentCosts < 0) {
328  myErrorOutput->inform("Invalid cost for route '" + myActiveRouteID + "'.");
329  }
330 }
331 
332 
333 void
336  switch (element) {
337  case SUMO_TAG_VTYPE:
339  if (myCurrentVTypeDistribution != 0) {
341  }
342  }
343  myCurrentVType = 0;
344  break;
345  case SUMO_TAG_TRIP:
346  closeRoute(true);
347  closeVehicle();
348  delete myVehicleParameter;
349  myVehicleParameter = 0;
350  myInsertStopEdgesAt = -1;
351  break;
352  default:
353  break;
354  }
355 }
356 
357 
358 void
359 RORouteHandler::closeRoute(const bool mayBeDisconnected) {
360  if (myActiveRoute.size() == 0) {
361  if (myActiveRouteRefID != "" && myCurrentAlternatives != 0) {
363  myActiveRouteID = "";
364  myActiveRouteRefID = "";
365  return;
366  }
367  if (myVehicleParameter != 0) {
368  myErrorOutput->inform("The route for vehicle '" + myVehicleParameter->id + "' has no edges.");
369  } else {
370  myErrorOutput->inform("Route '" + myActiveRouteID + "' has no edges.");
371  }
372  myActiveRouteID = "";
373  myActiveRouteStops.clear();
374  return;
375  }
376  if (myActiveRoute.size() == 1 && myActiveRoute.front()->getFunc() == ROEdge::ET_DISTRICT) {
377  myErrorOutput->inform("The routing information for vehicle '" + myVehicleParameter->id + "' is insufficient.");
378  myActiveRouteID = "";
379  myActiveRouteStops.clear();
380  return;
381  }
384  myActiveRoute.clear();
385  if (myCurrentAlternatives == 0) {
386  if (myNet.getRouteDef(myActiveRouteID) != 0) {
387  delete route;
388  if (myVehicleParameter != 0) {
389  myErrorOutput->inform("Another route for vehicle '" + myVehicleParameter->id + "' exists.");
390  } else {
391  myErrorOutput->inform("Another route (or distribution) with the id '" + myActiveRouteID + "' exists.");
392  }
393  myActiveRouteID = "";
394  myActiveRouteStops.clear();
395  return;
396  } else {
397  myCurrentAlternatives = new RORouteDef(myActiveRouteID, 0, mayBeDisconnected || myTryRepair, mayBeDisconnected);
401  }
402  } else {
404  }
405  myActiveRouteID = "";
406  myActiveRouteStops.clear();
407 }
408 
409 
410 void
412  // check whether the id is really necessary
413  bool ok = true;
414  std::string id;
415  if (myVehicleParameter != 0) {
416  // ok, a vehicle is wrapping the route,
417  // we may use this vehicle's id as default
418  myVehicleParameter->routeid = id = "!" + myVehicleParameter->id; // !!! document this
419  if (attrs.hasAttribute(SUMO_ATTR_ID)) {
420  WRITE_WARNING("Ids of internal route distributions are ignored (vehicle '" + myVehicleParameter->id + "').");
421  }
422  } else {
423  id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
424  if (!ok) {
425  return;
426  }
427  }
428  // try to get the index of the last element
429  int index = attrs.getOpt<int>(SUMO_ATTR_LAST, id.c_str(), ok, 0);
430  if (ok && index < 0) {
431  myErrorOutput->inform("Negative index of a route alternative (id='" + id + "').");
432  return;
433  }
434  // build the alternative cont
435  myCurrentAlternatives = new RORouteDef(id, index, myTryRepair, false);
436  if (attrs.hasAttribute(SUMO_ATTR_ROUTES)) {
437  ok = true;
438  StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_ROUTES, id.c_str(), ok));
439  while (st.hasNext()) {
440  const std::string routeID = st.next();
441  const RORouteDef* route = myNet.getRouteDef(routeID);
442  if (route == 0) {
443  myErrorOutput->inform("Unknown route '" + routeID + "' in distribution '" + id + "'.");
444  } else {
446  }
447  }
448  }
449 }
450 
451 
452 void
454  if (myCurrentAlternatives != 0) {
456  myErrorOutput->inform("Route distribution '" + myCurrentAlternatives->getID() + "' is empty.");
457  delete myCurrentAlternatives;
458  } else if (!myNet.addRouteDef(myCurrentAlternatives)) {
459  myErrorOutput->inform("Another route (or distribution) with the id '" + myCurrentAlternatives->getID() + "' exists.");
460  delete myCurrentAlternatives;
461  }
463  }
464 }
465 
466 
467 void
469  // get the vehicle id
471  return;
472  }
473  // get vehicle type
475  if (type == 0) {
476  myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
478  } else {
479  // fix the type id in case we used a distribution
480  myVehicleParameter->vtypeid = type->id;
481  }
482  // get the route
484  if (route == 0) {
485  myErrorOutput->inform("The route of the vehicle '" + myVehicleParameter->id + "' is not known.");
486  return;
487  }
488  if (route->getID()[0] != '!') {
489  route = route->copy("!" + myVehicleParameter->id, myVehicleParameter->depart);
490  }
491  // build the vehicle
492  if (!MsgHandler::getErrorInstance()->wasInformed()) {
493  ROVehicle* veh = new ROVehicle(*myVehicleParameter, route, type, &myNet, myErrorOutput);
494  if (myNet.addVehicle(myVehicleParameter->id, veh)) {
496  }
497  }
498 }
499 
500 
501 void
503  if (myActivePerson->getPlan().empty()) {
504  WRITE_WARNING("Discarding person '" + myVehicleParameter->id + "' because it's plan is empty");
505  } else {
508  }
509  }
510  delete myVehicleParameter;
511  myVehicleParameter = 0;
512  myActivePerson = 0;
513 }
514 
515 void
518  if (myActiveContainerPlanSize > 0) {
521  } else {
522  WRITE_WARNING("Discarding container '" + myVehicleParameter->id + "' because it's plan is empty");
523  }
524  delete myVehicleParameter;
525  myVehicleParameter = 0;
526  delete myActiveContainerPlan;
529 }
530 
531 
532 void
534  // @todo: consider myScale?
536  delete myVehicleParameter;
537  myVehicleParameter = 0;
538  return;
539  }
540  // let's check whether vehicles had to depart before the simulation starts
542  const SUMOTime offsetToBegin = string2time(OptionsCont::getOptions().getString("begin")) - myVehicleParameter->depart;
546  delete myVehicleParameter;
547  myVehicleParameter = 0;
548  return;
549  }
550  }
552  myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
554  }
556  closeRoute(true);
557  }
559  myErrorOutput->inform("The route '" + myVehicleParameter->routeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
560  delete myVehicleParameter;
561  myVehicleParameter = 0;
562  return;
563  }
564  myActiveRouteID = "";
565  if (!MsgHandler::getErrorInstance()->wasInformed()) {
566  if (myNet.addFlow(myVehicleParameter, OptionsCont::getOptions().getBool("randomize-flows"))) {
568  } else {
569  myErrorOutput->inform("Another flow with the id '" + myVehicleParameter->id + "' exists.");
570  }
571  } else {
572  delete myVehicleParameter;
573  }
574  myVehicleParameter = 0;
575  myInsertStopEdgesAt = -1;
576 }
577 
578 
579 void
581  if (myActiveContainerPlan != 0) {
583  (*myActiveContainerPlan) << attrs;
586  return;
587  }
588  std::string errorSuffix;
589  if (myVehicleParameter != 0) {
590  errorSuffix = " in vehicle '" + myVehicleParameter->id + "'.";
591  } else {
592  errorSuffix = " in route '" + myActiveRouteID + "'.";
593  }
595  bool ok = parseStop(stop, attrs, errorSuffix, myErrorOutput);
596  if (!ok) {
597  return;
598  }
599  // try to parse the assigned bus stop
600  ROEdge* edge = 0;
601  if (stop.busstop != "") {
602  const SUMOVehicleParameter::Stop* busstop = myNet.getBusStop(stop.busstop);
603  if (busstop == 0) {
604  myErrorOutput->inform("Unknown bus stop '" + stop.busstop + "'" + errorSuffix);
605  return;
606  }
607  stop.lane = busstop->lane;
608  stop.endPos = busstop->endPos;
609  stop.startPos = busstop->startPos;
610  edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
611  } // try to parse the assigned container stop
612  else if (stop.containerstop != "") {
613  const SUMOVehicleParameter::Stop* containerstop = myNet.getContainerStop(stop.containerstop);
614  if (containerstop == 0) {
615  myErrorOutput->inform("Unknown container stop '" + stop.containerstop + "'" + errorSuffix);
616  }
617  stop.lane = containerstop->lane;
618  stop.endPos = containerstop->endPos;
619  stop.startPos = containerstop->startPos;
620  edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
621  } else {
622  // no, the lane and the position should be given
623  stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, "");
624  if (!ok || stop.lane == "") {
625  myErrorOutput->inform("A stop must be placed on a bus stop, a container stop or a lane" + errorSuffix);
626  return;
627  }
628  edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
629  if (edge == 0) {
630  myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix);
631  return;
632  }
633  stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ENDPOS, 0, ok, edge->getLength());
634  stop.startPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS);
635  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false);
636  if (!ok || !checkStopPos(stop.startPos, stop.endPos, edge->getLength(), POSITION_EPS, friendlyPos)) {
637  myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix);
638  return;
639  }
640  }
641  if (myActivePerson != 0) {
642  myActivePerson->addStop(stop, edge);
643  } else if (myVehicleParameter != 0) {
644  myVehicleParameter->stops.push_back(stop);
645  } else {
646  myActiveRouteStops.push_back(stop);
647  }
648  if (myInsertStopEdgesAt >= 0) {
649  myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
651  }
652 }
653 
654 
655 void
656 RORouteHandler::parseEdges(const std::string& desc, ConstROEdgeVector& into,
657  const std::string& rid) {
658  if (desc[0] == BinaryFormatter::BF_ROUTE) {
659  std::istringstream in(desc, std::ios::binary);
660  char c;
661  in >> c;
662  FileHelpers::readEdgeVector(in, into, rid);
663  } else {
664  for (StringTokenizer st(desc); st.hasNext();) {
665  const std::string id = st.next();
666  const ROEdge* edge = myNet.getEdge(id);
667  if (edge == 0) {
668  myErrorOutput->inform("The edge '" + id + "' within the route " + rid + " is not known.");
669  } else {
670  into.push_back(edge);
671  }
672  }
673  }
674 }
675 
676 
677 bool
679  bool ok = true;
680  const char* id = myVehicleParameter->id.c_str();
681  assert(!attrs.hasAttribute(SUMO_ATTR_EDGES));
682  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, id, ok);
683  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, id, ok);
684  const std::string modes = attrs.getOpt<std::string>(SUMO_ATTR_MODES, id, ok, "");
685  const std::string types = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id, ok, "");
686  const std::string busStop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, id, ok, "");
687 
688  const ROEdge* from = myNet.getEdge(fromID);
689  if (from == 0) {
690  myErrorOutput->inform("The edge '" + fromID + "' within a walk of " + myVehicleParameter->id + " is not known."
691  + "\n The route can not be build.");
692  ok = false;
693  }
694  const ROEdge* to = myNet.getEdge(toID);
695  if (to == 0) {
696  myErrorOutput->inform("The edge '" + toID + "' within a walk of " + myVehicleParameter->id + " is not known."
697  + "\n The route can not be build.");
698  ok = false;
699  }
700  const SUMOReal departPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_DEPARTPOS, id, ok, 0);
701  const SUMOReal arrivalPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ARRIVALPOS, id, ok, -NUMERICAL_EPS);
702  SVCPermissions modeSet = 0;
703  for (StringTokenizer st(modes); st.hasNext();) {
704  const std::string mode = st.next();
705  if (mode == "car") {
706  modeSet |= SVC_PASSENGER;
707  } else if (mode == "bicycle") {
708  modeSet |= SVC_BICYCLE;
709  } else if (mode == "public") {
710  modeSet |= SVC_BUS;
711  } else {
712  throw InvalidArgument("Unknown person mode '" + mode + "'.");
713  }
714  }
715  if (ok) {
716  myActivePerson->addTrip(from, to, modeSet, types, departPos, arrivalPos, busStop);
717  }
718  return ok;
719 }
720 
721 
722 /****************************************************************************/
const int VEHPARS_TO_TAZ_SET
RORouteDef * myCurrentAlternatives
The currently parsed route alternatives.
void addRide(const ROEdge *const from, const ROEdge *const to, const std::string &lines, const std::string &destStop)
Definition: ROPerson.cpp:97
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
SUMOReal myCurrentCosts
The currently parsed route costs.
virtual void myEndElement(int element)
Called when a closing tag occurs.
long long int SUMOTime
Definition: SUMOTime.h:43
void closeVehicleTypeDistribution()
The time is given.
std::string next()
std::string containerstop
(Optional) container stop if one is assigned to the stop
int repetitionNumber
The number of times the vehicle shall be repeatedly inserted.
void closePerson()
Ends the processing of a person.
std::string vtypeid
The vehicle&#39;s type id.
void openRouteDistribution(const SUMOSAXAttributes &attrs)
unsigned int getNumSuccessors() const
Returns the number of edges this edge is connected to.
Definition: ROEdge.cpp:219
static void parseVTypeEmbedded(SUMOVTypeParameter &into, int element, const SUMOSAXAttributes &attrs, bool fromVType=false)
Parses an element embedded in vtype definition.
SUMOVehicleParameter * myVehicleParameter
Parameter of the current vehicle, trip, person, container or flow.
Structure representing possible vehicle parameter.
bool add(SUMOReal prob, T val, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
ConstROEdgeVector myActiveRoute
The current route.
void addAlternativeDef(const RORouteDef *alternative)
Adds an alternative loaded from the file.
Definition: RORouteDef.cpp:86
vehicle is a bicycle
int SVCPermissions
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:165
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
SUMOVTypeParameter * myCurrentVType
The currently parsed vehicle type.
int repetitionsDone
The number of times the vehicle was already inserted.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
void addWalk(const ConstROEdgeVector &edges, const SUMOReal duration, const SUMOReal speed, const SUMOReal departPos, const SUMOReal arrivalPos, const std::string &busStop)
Definition: ROPerson.cpp:106
MsgHandler *const myErrorOutput
Depending on the "ignore-errors" option different outputs are used.
const SUMOVehicleParameter::Stop * getContainerStop(const std::string &id) const
Retrieves a container stop from the network.
Definition: RONet.h:243
const SUMOReal DEFAULT_VEH_PROB
SUMOReal myActiveRouteProbability
The probability of the current route.
virtual void myEndElement(int element)
Called when a closing tag occurs.
void registerLastDepart()
save last depart (only to be used if vehicle is not discarded)
int myActiveContainerPlanSize
The number of stages in myActiveContainerPlan.
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:62
void openVehicleTypeDistribution(const SUMOSAXAttributes &attrs)
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
void closeVehicle()
Ends the processing of a vehicle.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition: RONet.cpp:307
RandomDistributor< SUMOVTypeParameter * > * myCurrentVTypeDistribution
The currently parsed distribution of vehicle types (probability->vehicle type)
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition: RONet.cpp:330
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.
RORouteHandler(RONet &net, const std::string &file, const bool tryRepair, const bool emptyDestinationsAllowed, const bool ignoreErrors)
standard constructor
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.
RONet & myNet
The current route.
const SUMOVehicleParameter::Stop * getBusStop(const std::string &id) const
Retrieves a bus stop from the network.
Definition: RONet.h:229
std::string busstop
(Optional) bus stop if one is assigned to the stop
const std::string & getID() const
Returns the id.
Definition: Named.h:65
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:320
A vehicle as used by router.
Definition: ROVehicle.h:60
bool addRouteDef(RORouteDef *def)
Definition: RONet.cpp:206
SUMOReal startPos
The stopping position start.
ROPerson * myActivePerson
The plan of the current person.
the edges of a route
std::string routeid
The vehicle&#39;s route id.
Encapsulated SAX-Attributes.
bool wasSet(int what) const
Returns whether the given parameter was set.
SUMOReal endPos
The stopping position end.
std::vector< PlanItem * > & getPlan()
Definition: ROPerson.h:305
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:369
void parseEdges(const std::string &desc, ConstROEdgeVector &into, const std::string &rid)
Parse edges from strings.
void addStop(const SUMOVehicleParameter::Stop &stopPar, const ROEdge *const stopEdge)
Definition: ROPerson.cpp:115
void addTrip(const ROEdge *const from, const ROEdge *const to, const SVCPermissions modeSet, const std::string &vTypes, const SUMOReal departPos, const SUMOReal arrivalPos, const std::string &busStop)
Definition: ROPerson.cpp:71
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:46
A person as used by router.
Definition: ROPerson.h:57
void addStop(const SUMOSAXAttributes &attrs)
Processing of a stop.
std::string getString()
Returns the current content as a string.
#define POSITION_EPS
Definition: config.h:187
std::string fromTaz
The vehicle&#39;s origin zone (district)
vehicle is a passenger car (a "normal" car)
A basic edge for routing applications.
Definition: ROEdge.h:77
const int VEHPARS_FROM_TAZ_SET
std::string lane
The lane to stop at.
Parser for routes during their loading.
void closeContainer()
Ends the processing of a container.
vehicle is a bus
SUMOReal getOverallProb() const
Return the sum of the probabilites assigned to the members.
std::vector< SUMOVehicleParameter::Stop > myActiveRouteStops
List of the stops on the parsed route.
The router&#39;s network representation.
Definition: RONet.h:76
void openRoute(const SUMOSAXAttributes &attrs)
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
RORouteDef * copy(const std::string &id, const SUMOTime stopOffset) const
Returns a deep copy of the route definition.
Definition: RORouteDef.cpp:410
SUMOReal getLength() const
Returns the length of the edge.
Definition: ROEdge.h:198
const std::string DEFAULT_PEDTYPE_ID
SUMOReal defaultProbability
The probability when being added to a distribution without an explicit probability.
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
bool addPersonTrip(const SUMOSAXAttributes &attrs)
add a routing request for a walking person
const bool myTryRepair
Information whether routes shall be repaired.
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:89
OutputDevice_String * myActiveContainerPlan
The plan of the current container.
Base class for a vehicle&#39;s route definition.
Definition: RORouteDef.h:63
unsigned int getNumPredecessors() const
Returns the number of edges connected to this edge.
Definition: ROEdge.cpp:228
std::string id
The vehicle type&#39;s id.
void addLoadedAlternative(RORoute *alternative)
Adds a single alternative loaded from the file An alternative may also be generated during DUA...
Definition: RORouteDef.cpp:80
void closeRoute(const bool mayBeDisconnected=false)
const RGBColor * myActiveRouteColor
The currently parsed route&#39;s color.
virtual ~RORouteHandler()
standard destructor
static void readEdgeVector(std::istream &in, std::vector< const E * > &edges, const std::string &rid)
Reads an edge vector binary.
Definition: FileHelpers.h:283
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:213
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:255
#define NUMERICAL_EPS
Definition: config.h:160
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.
void closeFlow()
Ends the processing of a flow.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:343
An edge representing a whole district.
Definition: ROEdge.h:87
std::string myActiveRouteRefID
The id of the route the current route references to.
A color information.
bool addPerson(ROPerson *person)
Definition: RONet.cpp:357
void parseFromViaTo(std::string element, const SUMOSAXAttributes &attrs)
Called for parsing from and to and the corresponding taz attributes.
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition: RONet.h:327
SUMOReal getOverallProb() const
Returns the sum of the probablities of the contained routes.
Definition: RORouteDef.cpp:424
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
A complete router&#39;s route.
Definition: RORoute.h:62
An output device that encapsulates an ofstream.
void closeRouteDistribution()
std::string myCurrentVTypeDistributionID
The id of the currently parsed vehicle type distribution.
std::string id
The vehicle&#39;s id.