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  ConstROEdgeVector viaEdges;
113  parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok, "", true),
114  viaEdges, "for " + element + " '" + myVehicleParameter->id + "'");
115  for (ConstROEdgeVector::const_iterator i = viaEdges.begin(); i != viaEdges.end(); ++i) {
116  myActiveRoute.push_back(*i);
117  myVehicleParameter->via.push_back((*i)->getID());
118  }
119 
121  const ROEdge* toTaz = myNet.getEdge(myVehicleParameter->toTaz + "-sink");
122  if (toTaz == 0) {
123  myErrorOutput->inform("Sink taz '" + myVehicleParameter->toTaz + "' not known for " + element + " '" + myVehicleParameter->id + "'!");
124  } else if (toTaz->getNumPredecessors() == 0) {
125  myErrorOutput->inform("Sink taz '" + myVehicleParameter->toTaz + "' has no incoming edges for " + element + " '" + myVehicleParameter->id + "'!");
126  } else {
127  myActiveRoute.push_back(toTaz);
128  }
129  } else {
130  parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "", true),
131  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
132  }
134  if (myVehicleParameter->routeid == "") {
136  }
137 }
138 
139 
140 void
142  const SUMOSAXAttributes& attrs) {
143  SUMORouteHandler::myStartElement(element, attrs);
144  switch (element) {
145  case SUMO_TAG_PERSON: {
147  if (type == 0) {
148  myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for person '" + myVehicleParameter->id + "' is not known.");
150  }
152  break;
153  }
154  case SUMO_TAG_RIDE: {
155  std::vector<ROPerson::PlanItem*>& plan = myActivePerson->getPlan();
156  const std::string pid = myVehicleParameter->id;
157  bool ok = true;
158  ROEdge* from = 0;
159  if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
160  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, pid.c_str(), ok);
161  from = myNet.getEdge(fromID);
162  if (from == 0) {
163  throw ProcessError("The from edge '" + fromID + "' within a ride of person '" + pid + "' is not known.");
164  }
165  if (!plan.empty() && plan.back()->getDestination() != from) {
166  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + fromID + "!=" + plan.back()->getDestination()->getID() + ").");
167  }
168  } else if (plan.empty()) {
169  throw ProcessError("The start edge for person '" + pid + "' is not known.");
170  }
171  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, pid.c_str(), ok);
172  ROEdge* to = myNet.getEdge(toID);
173  if (to == 0) {
174  throw ProcessError("The to edge '" + toID + "' within a ride of person '" + pid + "' is not known.");
175  }
176  const std::string desc = attrs.get<std::string>(SUMO_ATTR_LINES, pid.c_str(), ok);
177  const std::string busStop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, pid.c_str(), ok, "");
178  myActivePerson->addRide(from, to, desc, busStop);
179  break;
180  }
181  case SUMO_TAG_PERSONTRIP:
182  case SUMO_TAG_WALK: {
183  bool ok = true;
184  const char* const objId = myVehicleParameter->id.c_str();
185  const SUMOReal duration = attrs.getOpt<SUMOReal>(SUMO_ATTR_DURATION, objId, ok, -1);
186  if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
187  throw ProcessError("Non-positive walking duration for '" + myVehicleParameter->id + "'.");
188  }
189  const SUMOReal speed = attrs.getOpt<SUMOReal>(SUMO_ATTR_SPEED, objId, ok, -1.);
190  if (attrs.hasAttribute(SUMO_ATTR_SPEED) && speed <= 0) {
191  throw ProcessError("Non-positive walking speed for '" + myVehicleParameter->id + "'.");
192  }
193  const SUMOReal departPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_DEPARTPOS, objId, ok, std::numeric_limits<SUMOReal>::infinity());
194  const SUMOReal arrivalPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ARRIVALPOS, objId, ok, std::numeric_limits<SUMOReal>::infinity());
195  const std::string busStop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, objId, ok, "");
196  if (!ok) {
197  break;
198  }
199  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
200  // XXX allow --repair?
201  myActiveRoute.clear();
202  parseEdges(attrs.get<std::string>(SUMO_ATTR_EDGES, myVehicleParameter->id.c_str(), ok), myActiveRoute, " walk for person '" + myVehicleParameter->id + "'");
203  myActivePerson->addWalk(myActiveRoute, duration, speed, departPos, arrivalPos, busStop);
204  } else {
205  addPersonTrip(attrs);
206  }
207  break;
208  }
209  case SUMO_TAG_CONTAINER:
213  (*myActiveContainerPlan) << attrs;
214  break;
215  case SUMO_TAG_TRANSPORT: {
217  (*myActiveContainerPlan) << attrs;
220  break;
221  }
222  case SUMO_TAG_TRANSHIP: {
223  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
224  // copy walk as it is
225  // XXX allow --repair?
227  (*myActiveContainerPlan) << attrs;
230  } else {
231  //routePerson(attrs, *myActiveContainerPlan);
232  }
233  break;
234  }
235  case SUMO_TAG_FLOW:
237  parseFromViaTo("flow", attrs);
238  break;
239  case SUMO_TAG_TRIP: {
241  parseFromViaTo("trip", attrs);
242  }
243  break;
244  default:
245  break;
246  }
247  // parse embedded vtype information
248  if (myCurrentVType != 0 && element != SUMO_TAG_VTYPE && element != SUMO_TAG_PARAM) {
250  return;
251  }
252 }
253 
254 
255 void
257  bool ok = true;
258  myCurrentVTypeDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
259  if (ok) {
261  if (attrs.hasAttribute(SUMO_ATTR_VTYPES)) {
262  const std::string vTypes = attrs.get<std::string>(SUMO_ATTR_VTYPES, myCurrentVTypeDistributionID.c_str(), ok);
263  StringTokenizer st(vTypes);
264  while (st.hasNext()) {
265  SUMOVTypeParameter* type = myNet.getVehicleTypeSecure(st.next());
266  myCurrentVTypeDistribution->add(1., type);
267  }
268  }
269  }
270 }
271 
272 
273 void
275  if (myCurrentVTypeDistribution != 0) {
278  myErrorOutput->inform("Vehicle type distribution '" + myCurrentVTypeDistributionID + "' is empty.");
281  myErrorOutput->inform("Another vehicle type (or distribution) with the id '" + myCurrentVTypeDistributionID + "' exists.");
282  }
284  }
285 }
286 
287 
288 void
290  myActiveRoute.clear();
291  myInsertStopEdgesAt = -1;
292  // check whether the id is really necessary
293  std::string rid;
294  if (myCurrentAlternatives != 0) {
296  rid = "distribution '" + myCurrentAlternatives->getID() + "'";
297  } else if (myVehicleParameter != 0) {
298  // ok, a vehicle is wrapping the route,
299  // we may use this vehicle's id as default
300  myVehicleParameter->routeid = myActiveRouteID = "!" + myVehicleParameter->id; // !!! document this
301  if (attrs.hasAttribute(SUMO_ATTR_ID)) {
302  WRITE_WARNING("Ids of internal routes are ignored (vehicle '" + myVehicleParameter->id + "').");
303  }
304  } else {
305  bool ok = true;
306  myActiveRouteID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
307  if (!ok) {
308  return;
309  }
310  rid = "'" + myActiveRouteID + "'";
311  }
312  if (myVehicleParameter != 0) { // have to do this here for nested route distributions
313  rid = "for vehicle '" + myVehicleParameter->id + "'";
314  }
315  bool ok = true;
316  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
317  parseEdges(attrs.get<std::string>(SUMO_ATTR_EDGES, myActiveRouteID.c_str(), ok), myActiveRoute, rid);
318  }
319  myActiveRouteRefID = attrs.getOpt<std::string>(SUMO_ATTR_REFID, myActiveRouteID.c_str(), ok, "");
321  myErrorOutput->inform("Invalid reference to route '" + myActiveRouteRefID + "' in route " + rid + ".");
322  }
323  if (myCurrentAlternatives != 0 && !attrs.hasAttribute(SUMO_ATTR_PROB)) {
324  WRITE_WARNING("No probability for a route in '" + rid + "', using default.");
325  }
327  if (ok && myActiveRouteProbability < 0) {
328  myErrorOutput->inform("Invalid probability for route '" + myActiveRouteID + "'.");
329  }
331  ok = true;
332  myCurrentCosts = attrs.getOpt<SUMOReal>(SUMO_ATTR_COST, myActiveRouteID.c_str(), ok, -1);
333  if (ok && myCurrentCosts != -1 && myCurrentCosts < 0) {
334  myErrorOutput->inform("Invalid cost for route '" + myActiveRouteID + "'.");
335  }
336 }
337 
338 
339 void
342  switch (element) {
343  case SUMO_TAG_VTYPE:
345  if (myCurrentVTypeDistribution != 0) {
347  }
348  }
349  myCurrentVType = 0;
350  break;
351  case SUMO_TAG_TRIP:
352  closeRoute(true);
353  closeVehicle();
354  delete myVehicleParameter;
355  myVehicleParameter = 0;
356  myInsertStopEdgesAt = -1;
357  break;
358  default:
359  break;
360  }
361 }
362 
363 
364 void
365 RORouteHandler::closeRoute(const bool mayBeDisconnected) {
366  if (myActiveRoute.size() == 0) {
367  if (myActiveRouteRefID != "" && myCurrentAlternatives != 0) {
369  myActiveRouteID = "";
370  myActiveRouteRefID = "";
371  return;
372  }
373  if (myVehicleParameter != 0) {
374  myErrorOutput->inform("The route for vehicle '" + myVehicleParameter->id + "' has no edges.");
375  } else {
376  myErrorOutput->inform("Route '" + myActiveRouteID + "' has no edges.");
377  }
378  myActiveRouteID = "";
379  myActiveRouteStops.clear();
380  return;
381  }
382  if (myActiveRoute.size() == 1 && myActiveRoute.front()->getFunc() == ROEdge::ET_DISTRICT) {
383  myErrorOutput->inform("The routing information for vehicle '" + myVehicleParameter->id + "' is insufficient.");
384  myActiveRouteID = "";
385  myActiveRouteStops.clear();
386  return;
387  }
390  myActiveRoute.clear();
391  if (myCurrentAlternatives == 0) {
392  if (myNet.getRouteDef(myActiveRouteID) != 0) {
393  delete route;
394  if (myVehicleParameter != 0) {
395  myErrorOutput->inform("Another route for vehicle '" + myVehicleParameter->id + "' exists.");
396  } else {
397  myErrorOutput->inform("Another route (or distribution) with the id '" + myActiveRouteID + "' exists.");
398  }
399  myActiveRouteID = "";
400  myActiveRouteStops.clear();
401  return;
402  } else {
403  myCurrentAlternatives = new RORouteDef(myActiveRouteID, 0, mayBeDisconnected || myTryRepair, mayBeDisconnected);
407  }
408  } else {
410  }
411  myActiveRouteID = "";
412  myActiveRouteStops.clear();
413 }
414 
415 
416 void
418  // check whether the id is really necessary
419  bool ok = true;
420  std::string id;
421  if (myVehicleParameter != 0) {
422  // ok, a vehicle is wrapping the route,
423  // we may use this vehicle's id as default
424  myVehicleParameter->routeid = id = "!" + myVehicleParameter->id; // !!! document this
425  if (attrs.hasAttribute(SUMO_ATTR_ID)) {
426  WRITE_WARNING("Ids of internal route distributions are ignored (vehicle '" + myVehicleParameter->id + "').");
427  }
428  } else {
429  id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
430  if (!ok) {
431  return;
432  }
433  }
434  // try to get the index of the last element
435  int index = attrs.getOpt<int>(SUMO_ATTR_LAST, id.c_str(), ok, 0);
436  if (ok && index < 0) {
437  myErrorOutput->inform("Negative index of a route alternative (id='" + id + "').");
438  return;
439  }
440  // build the alternative cont
441  myCurrentAlternatives = new RORouteDef(id, index, myTryRepair, false);
442  if (attrs.hasAttribute(SUMO_ATTR_ROUTES)) {
443  ok = true;
444  StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_ROUTES, id.c_str(), ok));
445  while (st.hasNext()) {
446  const std::string routeID = st.next();
447  const RORouteDef* route = myNet.getRouteDef(routeID);
448  if (route == 0) {
449  myErrorOutput->inform("Unknown route '" + routeID + "' in distribution '" + id + "'.");
450  } else {
452  }
453  }
454  }
455 }
456 
457 
458 void
460  if (myCurrentAlternatives != 0) {
462  myErrorOutput->inform("Route distribution '" + myCurrentAlternatives->getID() + "' is empty.");
463  delete myCurrentAlternatives;
464  } else if (!myNet.addRouteDef(myCurrentAlternatives)) {
465  myErrorOutput->inform("Another route (or distribution) with the id '" + myCurrentAlternatives->getID() + "' exists.");
466  delete myCurrentAlternatives;
467  }
469  }
470 }
471 
472 
473 void
475  // get the vehicle id
477  return;
478  }
479  // get vehicle type
481  if (type == 0) {
482  myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
484  } else {
485  // fix the type id in case we used a distribution
486  myVehicleParameter->vtypeid = type->id;
487  }
488  // get the route
490  if (route == 0) {
491  myErrorOutput->inform("The route of the vehicle '" + myVehicleParameter->id + "' is not known.");
492  return;
493  }
494  if (route->getID()[0] != '!') {
495  route = route->copy("!" + myVehicleParameter->id, myVehicleParameter->depart);
496  }
497  // build the vehicle
498  if (!MsgHandler::getErrorInstance()->wasInformed()) {
499  ROVehicle* veh = new ROVehicle(*myVehicleParameter, route, type, &myNet, myErrorOutput);
500  if (myNet.addVehicle(myVehicleParameter->id, veh)) {
502  }
503  }
504 }
505 
506 
507 void
509  if (myActivePerson->getPlan().empty()) {
510  WRITE_WARNING("Discarding person '" + myVehicleParameter->id + "' because it's plan is empty");
511  } else {
514  }
515  }
516  delete myVehicleParameter;
517  myVehicleParameter = 0;
518  myActivePerson = 0;
519 }
520 
521 void
524  if (myActiveContainerPlanSize > 0) {
527  } else {
528  WRITE_WARNING("Discarding container '" + myVehicleParameter->id + "' because it's plan is empty");
529  }
530  delete myVehicleParameter;
531  myVehicleParameter = 0;
532  delete myActiveContainerPlan;
535 }
536 
537 
538 void
540  // @todo: consider myScale?
542  delete myVehicleParameter;
543  myVehicleParameter = 0;
544  return;
545  }
546  // let's check whether vehicles had to depart before the simulation starts
548  const SUMOTime offsetToBegin = string2time(OptionsCont::getOptions().getString("begin")) - myVehicleParameter->depart;
552  delete myVehicleParameter;
553  myVehicleParameter = 0;
554  return;
555  }
556  }
558  myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
559  }
561  closeRoute(true);
562  }
564  myErrorOutput->inform("The route '" + myVehicleParameter->routeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
565  delete myVehicleParameter;
566  myVehicleParameter = 0;
567  return;
568  }
569  myActiveRouteID = "";
570  if (!MsgHandler::getErrorInstance()->wasInformed()) {
571  if (myNet.addFlow(myVehicleParameter, OptionsCont::getOptions().getBool("randomize-flows"))) {
573  } else {
574  myErrorOutput->inform("Another flow with the id '" + myVehicleParameter->id + "' exists.");
575  }
576  } else {
577  delete myVehicleParameter;
578  }
579  myVehicleParameter = 0;
580  myInsertStopEdgesAt = -1;
581 }
582 
583 
584 void
586  if (myActiveContainerPlan != 0) {
588  (*myActiveContainerPlan) << attrs;
591  return;
592  }
593  std::string errorSuffix;
594  if (myVehicleParameter != 0) {
595  errorSuffix = " in vehicle '" + myVehicleParameter->id + "'.";
596  } else {
597  errorSuffix = " in route '" + myActiveRouteID + "'.";
598  }
600  bool ok = parseStop(stop, attrs, errorSuffix, myErrorOutput);
601  if (!ok) {
602  return;
603  }
604  // try to parse the assigned bus stop
605  ROEdge* edge = 0;
606  if (stop.busstop != "") {
607  const SUMOVehicleParameter::Stop* busstop = myNet.getBusStop(stop.busstop);
608  if (busstop == 0) {
609  myErrorOutput->inform("Unknown bus stop '" + stop.busstop + "'" + errorSuffix);
610  return;
611  }
612  stop.lane = busstop->lane;
613  stop.endPos = busstop->endPos;
614  stop.startPos = busstop->startPos;
615  edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
616  } // try to parse the assigned container stop
617  else if (stop.containerstop != "") {
618  const SUMOVehicleParameter::Stop* containerstop = myNet.getContainerStop(stop.containerstop);
619  if (containerstop == 0) {
620  myErrorOutput->inform("Unknown container stop '" + stop.containerstop + "'" + errorSuffix);
621  }
622  stop.lane = containerstop->lane;
623  stop.endPos = containerstop->endPos;
624  stop.startPos = containerstop->startPos;
625  edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
626  } else {
627  // no, the lane and the position should be given
628  stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, "");
629  if (!ok || stop.lane == "") {
630  myErrorOutput->inform("A stop must be placed on a bus stop, a container stop or a lane" + errorSuffix);
631  return;
632  }
633  edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
634  if (edge == 0) {
635  myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix);
636  return;
637  }
638  stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ENDPOS, 0, ok, edge->getLength());
639  stop.startPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS);
640  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false);
641  if (!ok || !checkStopPos(stop.startPos, stop.endPos, edge->getLength(), POSITION_EPS, friendlyPos)) {
642  myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix);
643  return;
644  }
645  }
646  if (myActivePerson != 0) {
647  myActivePerson->addStop(stop, edge);
648  } else if (myVehicleParameter != 0) {
649  myVehicleParameter->stops.push_back(stop);
650  } else {
651  myActiveRouteStops.push_back(stop);
652  }
653  if (myInsertStopEdgesAt >= 0) {
654  myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
656  }
657 }
658 
659 
660 void
661 RORouteHandler::parseEdges(const std::string& desc, ConstROEdgeVector& into,
662  const std::string& rid) {
663  if (desc[0] == BinaryFormatter::BF_ROUTE) {
664  std::istringstream in(desc, std::ios::binary);
665  char c;
666  in >> c;
667  FileHelpers::readEdgeVector(in, into, rid);
668  } else {
669  for (StringTokenizer st(desc); st.hasNext();) {
670  const std::string id = st.next();
671  const ROEdge* edge = myNet.getEdge(id);
672  if (edge == 0) {
673  myErrorOutput->inform("The edge '" + id + "' within the route " + rid + " is not known.");
674  } else {
675  into.push_back(edge);
676  }
677  }
678  }
679 }
680 
681 
682 bool
684  bool ok = true;
685  const char* id = myVehicleParameter->id.c_str();
686  assert(!attrs.hasAttribute(SUMO_ATTR_EDGES));
687  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, id, ok);
688  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, id, ok);
689  const std::string modes = attrs.getOpt<std::string>(SUMO_ATTR_MODES, id, ok, "");
690  const std::string types = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id, ok, "");
691  const std::string busStop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, id, ok, "");
692 
693  const ROEdge* from = myNet.getEdge(fromID);
694  if (from == 0) {
695  myErrorOutput->inform("The edge '" + fromID + "' within a walk of " + myVehicleParameter->id + " is not known."
696  + "\n The route can not be build.");
697  ok = false;
698  }
699  const ROEdge* to = myNet.getEdge(toID);
700  if (to == 0) {
701  myErrorOutput->inform("The edge '" + toID + "' within a walk of " + myVehicleParameter->id + " is not known."
702  + "\n The route can not be build.");
703  ok = false;
704  }
705  const SUMOReal departPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_DEPARTPOS, id, ok, 0);
706  const SUMOReal arrivalPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ARRIVALPOS, id, ok, -NUMERICAL_EPS);
707  SVCPermissions modeSet = 0;
708  for (StringTokenizer st(modes); st.hasNext();) {
709  const std::string mode = st.next();
710  if (mode == "car") {
711  modeSet |= SVC_PASSENGER;
712  } else if (mode == "bicycle") {
713  modeSet |= SVC_BICYCLE;
714  } else if (mode == "public") {
715  modeSet |= SVC_BUS;
716  } else {
717  throw InvalidArgument("Unknown person mode '" + mode + "'.");
718  }
719  }
720  if (ok) {
721  myActivePerson->addTrip(from, to, modeSet, types, departPos, arrivalPos, busStop);
722  }
723  return ok;
724 }
725 
726 
727 /****************************************************************************/
SUMOReal getLength() const
Returns the length of the edge.
Definition: ROEdge.h:198
RORouteDef * copy(const std::string &id, const SUMOTime stopOffset) const
Returns a deep copy of the route definition.
Definition: RORouteDef.cpp:406
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:98
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.
int getNumSuccessors() const
Returns the number of edges this edge is connected to.
Definition: ROEdge.cpp:219
void openRouteDistribution(const SUMOSAXAttributes &attrs)
static void parseVTypeEmbedded(SUMOVTypeParameter &into, int element, const SUMOSAXAttributes &attrs, bool fromVType=false)
Parses an element embedded in vtype definition.
Represents a generic random distribution.
SUMOVehicleParameter * myVehicleParameter
Parameter of the current vehicle, trip, person, container or flow.
SUMOReal getOverallProb() const
Returns the sum of the probablities of the contained routes.
Definition: RORouteDef.cpp:420
static void readEdgeVector(std::istream &in, std::vector< const E *> &edges, const std::string &rid)
Reads an edge vector binary.
Definition: FileHelpers.h:283
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
std::string getString() const
Returns the current content as a string.
int SVCPermissions
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:107
MsgHandler *const myErrorOutput
Depending on the "ignore-errors" option different outputs are used.
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
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
void openVehicleTypeDistribution(const SUMOSAXAttributes &attrs)
const std::string & getID() const
Returns the id.
Definition: Named.h:66
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...
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition: RONet.h:327
#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:324
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:347
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
RONet & myNet
The current route.
int getNumPredecessors() const
Returns the number of edges connected to this edge.
Definition: ROEdge.cpp:228
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter *> *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:337
std::string busstop
(Optional) bus stop if one is assigned to the stop
A vehicle as used by router.
Definition: ROVehicle.h:60
bool addRouteDef(RORouteDef *def)
Definition: RONet.cpp:224
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.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
SUMOReal endPos
The stopping position end.
std::vector< PlanItem * > & getPlan()
Definition: ROPerson.h:310
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:386
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:116
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:58
void addStop(const SUMOSAXAttributes &attrs)
Processing of a stop.
#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.
std::vector< std::string > via
List of the via-edges the vehicle must visit.
void closeContainer()
Ends the processing of a container.
vehicle is a bus
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.
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;.
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
const SUMOVehicleParameter::Stop * getContainerStop(const std::string &id) const
Retrieves a container stop from the network.
Definition: RONet.h:243
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
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)
bool wasSet(int what) const
Returns whether the given parameter was set.
const RGBColor * myActiveRouteColor
The currently parsed route&#39;s color.
virtual ~RORouteHandler()
standard destructor
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:272
#define NUMERICAL_EPS
Definition: config.h:160
void closeFlow()
Ends the processing of a flow.
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:165
const SUMOVehicleParameter::Stop * getBusStop(const std::string &id) const
Retrieves a bus stop from the network.
Definition: RONet.h:229
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:360
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:374
void parseFromViaTo(std::string element, const SUMOSAXAttributes &attrs)
Called for parsing from and to and the corresponding taz attributes.
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.
SUMOReal getOverallProb() const
Return the sum of the probabilites assigned to the members.