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 + "'");
114  myVehicleParameter->via = StringTokenizer(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok, "", true)).getVector();
115 
117  const ROEdge* toTaz = myNet.getEdge(myVehicleParameter->toTaz + "-sink");
118  if (toTaz == 0) {
119  myErrorOutput->inform("Sink taz '" + myVehicleParameter->toTaz + "' not known for " + element + " '" + myVehicleParameter->id + "'!");
120  } else if (toTaz->getNumPredecessors() == 0) {
121  myErrorOutput->inform("Sink taz '" + myVehicleParameter->toTaz + "' has no incoming edges for " + element + " '" + myVehicleParameter->id + "'!");
122  } else {
123  myActiveRoute.push_back(toTaz);
124  }
125  } else {
126  parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_TO, myVehicleParameter->id.c_str(), ok, "", true),
127  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
128  }
130  if (myVehicleParameter->routeid == "") {
132  }
133 }
134 
135 
136 void
138  const SUMOSAXAttributes& attrs) {
139  SUMORouteHandler::myStartElement(element, attrs);
140  switch (element) {
141  case SUMO_TAG_PERSON: {
143  if (type == 0) {
144  myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for person '" + myVehicleParameter->id + "' is not known.");
146  }
148  break;
149  }
150  case SUMO_TAG_RIDE: {
151  std::vector<ROPerson::PlanItem*>& plan = myActivePerson->getPlan();
152  const std::string pid = myVehicleParameter->id;
153  bool ok = true;
154  ROEdge* from = 0;
155  if (attrs.hasAttribute(SUMO_ATTR_FROM)) {
156  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, pid.c_str(), ok);
157  from = myNet.getEdge(fromID);
158  if (from == 0) {
159  throw ProcessError("The from edge '" + fromID + "' within a ride of person '" + pid + "' is not known.");
160  }
161  if (!plan.empty() && plan.back()->getDestination() != from) {
162  throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + fromID + "!=" + plan.back()->getDestination()->getID() + ").");
163  }
164  } else if (plan.empty()) {
165  throw ProcessError("The start edge for person '" + pid + "' is not known.");
166  }
167  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, pid.c_str(), ok);
168  ROEdge* to = myNet.getEdge(toID);
169  if (to == 0) {
170  throw ProcessError("The to edge '" + toID + "' within a ride of person '" + pid + "' is not known.");
171  }
172  const std::string desc = attrs.get<std::string>(SUMO_ATTR_LINES, pid.c_str(), ok);
173  const std::string busStop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, pid.c_str(), ok, "");
174  myActivePerson->addRide(from, to, desc, busStop);
175  break;
176  }
177  case SUMO_TAG_PERSONTRIP:
178  case SUMO_TAG_WALK: {
179  bool ok = true;
180  const char* const objId = myVehicleParameter->id.c_str();
181  const SUMOTime duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, objId, ok, -1);
182  if (attrs.hasAttribute(SUMO_ATTR_DURATION) && duration <= 0) {
183  throw ProcessError("Non-positive walking duration for '" + myVehicleParameter->id + "'.");
184  }
185  const SUMOReal speed = attrs.getOpt<SUMOReal>(SUMO_ATTR_SPEED, objId, ok, -1.);
186  if (attrs.hasAttribute(SUMO_ATTR_SPEED) && speed <= 0) {
187  throw ProcessError("Non-positive walking speed for '" + myVehicleParameter->id + "'.");
188  }
189  const SUMOReal departPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_DEPARTPOS, objId, ok, std::numeric_limits<SUMOReal>::infinity());
190  const SUMOReal arrivalPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ARRIVALPOS, objId, ok, std::numeric_limits<SUMOReal>::infinity());
191  const std::string busStop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, objId, ok, "");
192  if (!ok) {
193  break;
194  }
195  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
196  // XXX allow --repair?
197  myActiveRoute.clear();
198  parseEdges(attrs.get<std::string>(SUMO_ATTR_EDGES, myVehicleParameter->id.c_str(), ok), myActiveRoute, " walk for person '" + myVehicleParameter->id + "'");
199  myActivePerson->addWalk(myActiveRoute, duration, speed, departPos, arrivalPos, busStop);
200  } else {
201  addPersonTrip(attrs);
202  }
203  break;
204  }
205  case SUMO_TAG_CONTAINER:
209  (*myActiveContainerPlan) << attrs;
210  break;
211  case SUMO_TAG_TRANSPORT: {
213  (*myActiveContainerPlan) << attrs;
216  break;
217  }
218  case SUMO_TAG_TRANSHIP: {
219  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
220  // copy walk as it is
221  // XXX allow --repair?
223  (*myActiveContainerPlan) << attrs;
226  } else {
227  //routePerson(attrs, *myActiveContainerPlan);
228  }
229  break;
230  }
231  case SUMO_TAG_FLOW:
233  parseFromViaTo("flow", attrs);
234  break;
235  case SUMO_TAG_TRIP: {
237  parseFromViaTo("trip", attrs);
238  }
239  break;
240  default:
241  break;
242  }
243  // parse embedded vtype information
244  if (myCurrentVType != 0 && element != SUMO_TAG_VTYPE && element != SUMO_TAG_PARAM) {
246  return;
247  }
248 }
249 
250 
251 void
253  bool ok = true;
254  myCurrentVTypeDistributionID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
255  if (ok) {
257  if (attrs.hasAttribute(SUMO_ATTR_VTYPES)) {
258  const std::string vTypes = attrs.get<std::string>(SUMO_ATTR_VTYPES, myCurrentVTypeDistributionID.c_str(), ok);
259  StringTokenizer st(vTypes);
260  while (st.hasNext()) {
261  SUMOVTypeParameter* type = myNet.getVehicleTypeSecure(st.next());
262  myCurrentVTypeDistribution->add(1., type);
263  }
264  }
265  }
266 }
267 
268 
269 void
271  if (myCurrentVTypeDistribution != 0) {
274  myErrorOutput->inform("Vehicle type distribution '" + myCurrentVTypeDistributionID + "' is empty.");
277  myErrorOutput->inform("Another vehicle type (or distribution) with the id '" + myCurrentVTypeDistributionID + "' exists.");
278  }
280  }
281 }
282 
283 
284 void
286  myActiveRoute.clear();
287  myInsertStopEdgesAt = -1;
288  // check whether the id is really necessary
289  std::string rid;
290  if (myCurrentAlternatives != 0) {
292  rid = "distribution '" + myCurrentAlternatives->getID() + "'";
293  } else if (myVehicleParameter != 0) {
294  // ok, a vehicle is wrapping the route,
295  // we may use this vehicle's id as default
296  myVehicleParameter->routeid = myActiveRouteID = "!" + myVehicleParameter->id; // !!! document this
297  if (attrs.hasAttribute(SUMO_ATTR_ID)) {
298  WRITE_WARNING("Ids of internal routes are ignored (vehicle '" + myVehicleParameter->id + "').");
299  }
300  } else {
301  bool ok = true;
302  myActiveRouteID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
303  if (!ok) {
304  return;
305  }
306  rid = "'" + myActiveRouteID + "'";
307  }
308  if (myVehicleParameter != 0) { // have to do this here for nested route distributions
309  rid = "for vehicle '" + myVehicleParameter->id + "'";
310  }
311  bool ok = true;
312  if (attrs.hasAttribute(SUMO_ATTR_EDGES)) {
313  parseEdges(attrs.get<std::string>(SUMO_ATTR_EDGES, myActiveRouteID.c_str(), ok), myActiveRoute, rid);
314  }
315  myActiveRouteRefID = attrs.getOpt<std::string>(SUMO_ATTR_REFID, myActiveRouteID.c_str(), ok, "");
317  myErrorOutput->inform("Invalid reference to route '" + myActiveRouteRefID + "' in route " + rid + ".");
318  }
319  if (myCurrentAlternatives != 0 && !attrs.hasAttribute(SUMO_ATTR_PROB)) {
320  WRITE_WARNING("No probability for a route in '" + rid + "', using default.");
321  }
323  if (ok && myActiveRouteProbability < 0) {
324  myErrorOutput->inform("Invalid probability for route '" + myActiveRouteID + "'.");
325  }
327  ok = true;
328  myCurrentCosts = attrs.getOpt<SUMOReal>(SUMO_ATTR_COST, myActiveRouteID.c_str(), ok, -1);
329  if (ok && myCurrentCosts != -1 && myCurrentCosts < 0) {
330  myErrorOutput->inform("Invalid cost for route '" + myActiveRouteID + "'.");
331  }
332 }
333 
334 
335 void
338  switch (element) {
339  case SUMO_TAG_VTYPE:
341  if (myCurrentVTypeDistribution != 0) {
343  }
344  }
345  myCurrentVType = 0;
346  break;
347  case SUMO_TAG_TRIP:
348  closeRoute(true);
349  closeVehicle();
350  delete myVehicleParameter;
351  myVehicleParameter = 0;
352  myInsertStopEdgesAt = -1;
353  break;
354  default:
355  break;
356  }
357 }
358 
359 
360 void
361 RORouteHandler::closeRoute(const bool mayBeDisconnected) {
362  if (myActiveRoute.size() == 0) {
363  if (myActiveRouteRefID != "" && myCurrentAlternatives != 0) {
365  myActiveRouteID = "";
366  myActiveRouteRefID = "";
367  return;
368  }
369  if (myVehicleParameter != 0) {
370  myErrorOutput->inform("The route for vehicle '" + myVehicleParameter->id + "' has no edges.");
371  } else {
372  myErrorOutput->inform("Route '" + myActiveRouteID + "' has no edges.");
373  }
374  myActiveRouteID = "";
375  myActiveRouteStops.clear();
376  return;
377  }
378  if (myActiveRoute.size() == 1 && myActiveRoute.front()->getFunc() == ROEdge::ET_DISTRICT) {
379  myErrorOutput->inform("The routing information for vehicle '" + myVehicleParameter->id + "' is insufficient.");
380  myActiveRouteID = "";
381  myActiveRouteStops.clear();
382  return;
383  }
386  myActiveRoute.clear();
387  if (myCurrentAlternatives == 0) {
388  if (myNet.getRouteDef(myActiveRouteID) != 0) {
389  delete route;
390  if (myVehicleParameter != 0) {
391  myErrorOutput->inform("Another route for vehicle '" + myVehicleParameter->id + "' exists.");
392  } else {
393  myErrorOutput->inform("Another route (or distribution) with the id '" + myActiveRouteID + "' exists.");
394  }
395  myActiveRouteID = "";
396  myActiveRouteStops.clear();
397  return;
398  } else {
399  myCurrentAlternatives = new RORouteDef(myActiveRouteID, 0, mayBeDisconnected || myTryRepair, mayBeDisconnected);
403  }
404  } else {
406  }
407  myActiveRouteID = "";
408  myActiveRouteStops.clear();
409 }
410 
411 
412 void
414  // check whether the id is really necessary
415  bool ok = true;
416  std::string id;
417  if (myVehicleParameter != 0) {
418  // ok, a vehicle is wrapping the route,
419  // we may use this vehicle's id as default
420  myVehicleParameter->routeid = id = "!" + myVehicleParameter->id; // !!! document this
421  if (attrs.hasAttribute(SUMO_ATTR_ID)) {
422  WRITE_WARNING("Ids of internal route distributions are ignored (vehicle '" + myVehicleParameter->id + "').");
423  }
424  } else {
425  id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
426  if (!ok) {
427  return;
428  }
429  }
430  // try to get the index of the last element
431  int index = attrs.getOpt<int>(SUMO_ATTR_LAST, id.c_str(), ok, 0);
432  if (ok && index < 0) {
433  myErrorOutput->inform("Negative index of a route alternative (id='" + id + "').");
434  return;
435  }
436  // build the alternative cont
437  myCurrentAlternatives = new RORouteDef(id, index, myTryRepair, false);
438  if (attrs.hasAttribute(SUMO_ATTR_ROUTES)) {
439  ok = true;
440  StringTokenizer st(attrs.get<std::string>(SUMO_ATTR_ROUTES, id.c_str(), ok));
441  while (st.hasNext()) {
442  const std::string routeID = st.next();
443  const RORouteDef* route = myNet.getRouteDef(routeID);
444  if (route == 0) {
445  myErrorOutput->inform("Unknown route '" + routeID + "' in distribution '" + id + "'.");
446  } else {
448  }
449  }
450  }
451 }
452 
453 
454 void
456  if (myCurrentAlternatives != 0) {
458  myErrorOutput->inform("Route distribution '" + myCurrentAlternatives->getID() + "' is empty.");
459  delete myCurrentAlternatives;
460  } else if (!myNet.addRouteDef(myCurrentAlternatives)) {
461  myErrorOutput->inform("Another route (or distribution) with the id '" + myCurrentAlternatives->getID() + "' exists.");
462  delete myCurrentAlternatives;
463  }
465  }
466 }
467 
468 
469 void
471  // get the vehicle id
473  return;
474  }
475  // get vehicle type
477  if (type == 0) {
478  myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for vehicle '" + myVehicleParameter->id + "' is not known.");
480  } else {
481  // fix the type id in case we used a distribution
482  myVehicleParameter->vtypeid = type->id;
483  }
484  // get the route
486  if (route == 0) {
487  myErrorOutput->inform("The route of the vehicle '" + myVehicleParameter->id + "' is not known.");
488  return;
489  }
490  if (route->getID()[0] != '!') {
491  route = route->copy("!" + myVehicleParameter->id, myVehicleParameter->depart);
492  }
493  // build the vehicle
494  if (!MsgHandler::getErrorInstance()->wasInformed()) {
495  ROVehicle* veh = new ROVehicle(*myVehicleParameter, route, type, &myNet, myErrorOutput);
496  if (myNet.addVehicle(myVehicleParameter->id, veh)) {
498  }
499  }
500 }
501 
502 
503 void
505  if (myActivePerson->getPlan().empty()) {
506  WRITE_WARNING("Discarding person '" + myVehicleParameter->id + "' because it's plan is empty");
507  } else {
510  }
511  }
512  delete myVehicleParameter;
513  myVehicleParameter = 0;
514  myActivePerson = 0;
515 }
516 
517 void
520  if (myActiveContainerPlanSize > 0) {
523  } else {
524  WRITE_WARNING("Discarding container '" + myVehicleParameter->id + "' because it's plan is empty");
525  }
526  delete myVehicleParameter;
527  myVehicleParameter = 0;
528  delete myActiveContainerPlan;
531 }
532 
533 
534 void
536  // @todo: consider myScale?
538  delete myVehicleParameter;
539  myVehicleParameter = 0;
540  return;
541  }
542  // let's check whether vehicles had to depart before the simulation starts
544  const SUMOTime offsetToBegin = string2time(OptionsCont::getOptions().getString("begin")) - myVehicleParameter->depart;
548  delete myVehicleParameter;
549  myVehicleParameter = 0;
550  return;
551  }
552  }
554  myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
555  }
557  closeRoute(true);
558  }
560  myErrorOutput->inform("The route '" + myVehicleParameter->routeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
561  delete myVehicleParameter;
562  myVehicleParameter = 0;
563  return;
564  }
565  myActiveRouteID = "";
566  if (!MsgHandler::getErrorInstance()->wasInformed()) {
567  if (myNet.addFlow(myVehicleParameter, OptionsCont::getOptions().getBool("randomize-flows"))) {
569  } else {
570  myErrorOutput->inform("Another flow with the id '" + myVehicleParameter->id + "' exists.");
571  }
572  } else {
573  delete myVehicleParameter;
574  }
575  myVehicleParameter = 0;
576  myInsertStopEdgesAt = -1;
577 }
578 
579 
580 void
582  if (myActiveContainerPlan != 0) {
584  (*myActiveContainerPlan) << attrs;
587  return;
588  }
589  std::string errorSuffix;
590  if (myVehicleParameter != 0) {
591  errorSuffix = " in vehicle '" + myVehicleParameter->id + "'.";
592  } else {
593  errorSuffix = " in route '" + myActiveRouteID + "'.";
594  }
596  bool ok = parseStop(stop, attrs, errorSuffix, myErrorOutput);
597  if (!ok) {
598  return;
599  }
600  // try to parse the assigned bus stop
601  ROEdge* edge = 0;
602  if (stop.busstop != "") {
603  const SUMOVehicleParameter::Stop* busstop = myNet.getBusStop(stop.busstop);
604  if (busstop == 0) {
605  myErrorOutput->inform("Unknown bus stop '" + stop.busstop + "'" + errorSuffix);
606  return;
607  }
608  stop.lane = busstop->lane;
609  stop.endPos = busstop->endPos;
610  stop.startPos = busstop->startPos;
611  edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
612  } // try to parse the assigned container stop
613  else if (stop.containerstop != "") {
614  const SUMOVehicleParameter::Stop* containerstop = myNet.getContainerStop(stop.containerstop);
615  if (containerstop == 0) {
616  myErrorOutput->inform("Unknown container stop '" + stop.containerstop + "'" + errorSuffix);
617  }
618  stop.lane = containerstop->lane;
619  stop.endPos = containerstop->endPos;
620  stop.startPos = containerstop->startPos;
621  edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
622  } else {
623  // no, the lane and the position should be given
624  stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, "");
625  if (!ok || stop.lane == "") {
626  myErrorOutput->inform("A stop must be placed on a bus stop, a container stop or a lane" + errorSuffix);
627  return;
628  }
629  edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
630  if (edge == 0) {
631  myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix);
632  return;
633  }
634  stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ENDPOS, 0, ok, edge->getLength());
635  stop.startPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS);
636  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false);
637  if (!ok || !checkStopPos(stop.startPos, stop.endPos, edge->getLength(), POSITION_EPS, friendlyPos)) {
638  myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix);
639  return;
640  }
641  }
642  if (myActivePerson != 0) {
643  myActivePerson->addStop(stop, edge);
644  } else if (myVehicleParameter != 0) {
645  myVehicleParameter->stops.push_back(stop);
646  } else {
647  myActiveRouteStops.push_back(stop);
648  }
649  if (myInsertStopEdgesAt >= 0) {
650  myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
652  }
653 }
654 
655 
656 void
657 RORouteHandler::parseEdges(const std::string& desc, ConstROEdgeVector& into,
658  const std::string& rid) {
659  if (desc[0] == BinaryFormatter::BF_ROUTE) {
660  std::istringstream in(desc, std::ios::binary);
661  char c;
662  in >> c;
663  FileHelpers::readEdgeVector(in, into, rid);
664  } else {
665  for (StringTokenizer st(desc); st.hasNext();) {
666  const std::string id = st.next();
667  const ROEdge* edge = myNet.getEdge(id);
668  if (edge == 0) {
669  myErrorOutput->inform("The edge '" + id + "' within the route " + rid + " is not known.");
670  } else {
671  into.push_back(edge);
672  }
673  }
674  }
675 }
676 
677 
678 bool
680  bool ok = true;
681  const char* id = myVehicleParameter->id.c_str();
682  assert(!attrs.hasAttribute(SUMO_ATTR_EDGES));
683  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, id, ok);
684  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, id, ok);
685  const std::string modes = attrs.getOpt<std::string>(SUMO_ATTR_MODES, id, ok, "");
686  const std::string types = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id, ok, "");
687  const std::string busStop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, id, ok, "");
688 
689  const ROEdge* from = myNet.getEdge(fromID);
690  if (from == 0) {
691  myErrorOutput->inform("The edge '" + fromID + "' within a walk of " + myVehicleParameter->id + " is not known."
692  + "\n The route can not be build.");
693  ok = false;
694  }
695  const ROEdge* to = myNet.getEdge(toID);
696  if (to == 0) {
697  myErrorOutput->inform("The edge '" + toID + "' within a walk of " + myVehicleParameter->id + " is not known."
698  + "\n The route can not be build.");
699  ok = false;
700  }
701  const SUMOReal departPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_DEPARTPOS, id, ok, 0);
702  const SUMOReal arrivalPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ARRIVALPOS, id, ok, -NUMERICAL_EPS);
703  SVCPermissions modeSet = 0;
704  for (StringTokenizer st(modes); st.hasNext();) {
705  const std::string mode = st.next();
706  if (mode == "car") {
707  modeSet |= SVC_PASSENGER;
708  } else if (mode == "bicycle") {
709  modeSet |= SVC_BICYCLE;
710  } else if (mode == "public") {
711  modeSet |= SVC_BUS;
712  } else {
713  throw InvalidArgument("Unknown person mode '" + mode + "'.");
714  }
715  }
716  if (ok) {
717  myActivePerson->addTrip(from, to, modeSet, types, departPos, arrivalPos, busStop);
718  }
719  return ok;
720 }
721 
722 
723 /****************************************************************************/
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.
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:107
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.
#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
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:66
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:337
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.
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: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.
std::string getString()
Returns the current content as a string.
#define POSITION_EPS
Definition: config.h:188
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
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
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::vector< std::string > getVector()
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:406
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:214
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:272
#define NUMERICAL_EPS
Definition: config.h:161
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: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.
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:420
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.