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-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <map>
36 #include <vector>
37 #include <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 
57 // ===========================================================================
58 // method definitions
59 // ===========================================================================
60 RORouteHandler::RORouteHandler(RONet& net, const std::string& file,
61  const bool tryRepair,
62  const bool emptyDestinationsAllowed,
63  const bool ignoreErrors) :
64  SUMORouteHandler(file),
65  myNet(net),
66  myActivePerson(0),
67  myActiveContainerPlan(0),
68  myActiveContainerPlanSize(0),
69  myTryRepair(tryRepair),
70  myEmptyDestinationsAllowed(emptyDestinationsAllowed),
71  myErrorOutput(ignoreErrors ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance()),
72  myCurrentVTypeDistribution(0),
73  myCurrentAlternatives(0) {
74  myActiveRoute.reserve(100);
75 }
76 
77 
79 }
80 
81 
82 void
83 RORouteHandler::parseFromViaTo(std::string element,
84  const SUMOSAXAttributes& attrs) {
85  myActiveRoute.clear();
86  bool useTaz = OptionsCont::getOptions().getBool("with-taz");
88  WRITE_WARNING("Taz usage was requested but no taz present in " + element + " '" + myVehicleParameter->id + "'!");
89  useTaz = false;
90  }
91  bool ok = true;
93  const ROEdge* fromTaz = myNet.getEdge(myVehicleParameter->fromTaz + "-source");
94  if (fromTaz == 0) {
95  myErrorOutput->inform("Source taz '" + myVehicleParameter->fromTaz + "' not known for " + element + " '" + myVehicleParameter->id + "'!");
96  } else if (fromTaz->getNumSuccessors() == 0) {
97  myErrorOutput->inform("Source taz '" + myVehicleParameter->fromTaz + "' has no outgoing edges for " + element + " '" + myVehicleParameter->id + "'!");
98  } else {
99  myActiveRoute.push_back(fromTaz);
100  }
101  } else {
102  parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_FROM, myVehicleParameter->id.c_str(), ok, "", true),
103  myActiveRoute, "for " + element + " '" + myVehicleParameter->id + "'");
104  }
105  if (!attrs.hasAttribute(SUMO_ATTR_VIA)) {
106  myInsertStopEdgesAt = (int)myActiveRoute.size();
107  }
108  ConstROEdgeVector viaEdges;
109  parseEdges(attrs.getOpt<std::string>(SUMO_ATTR_VIA, myVehicleParameter->id.c_str(), ok, "", true),
110  viaEdges, "for " + element + " '" + myVehicleParameter->id + "'");
111  for (ConstROEdgeVector::const_iterator i = viaEdges.begin(); i != viaEdges.end(); ++i) {
112  myActiveRoute.push_back(*i);
113  myVehicleParameter->via.push_back((*i)->getID());
114  }
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 double duration = attrs.getOpt<double>(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 double speed = attrs.getOpt<double>(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 double departPos = attrs.getOpt<double>(SUMO_ATTR_DEPARTPOS, objId, ok, std::numeric_limits<double>::infinity());
190  const double arrivalPos = attrs.getOpt<double>(SUMO_ATTR_ARRIVALPOS, objId, ok, std::numeric_limits<double>::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(type, 1.);
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<double>(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  if (type->vehicleClass == SVC_PEDESTRIAN) {
485  WRITE_WARNING("Vehicle type '" + type->id + "' with vClass=pedestrian should only be used for persons and not for vehicle '" + myVehicleParameter->id + "'.");
486  }
487  // get the route
489  if (route == 0) {
490  myErrorOutput->inform("The route of the vehicle '" + myVehicleParameter->id + "' is not known.");
491  return;
492  }
493  if (route->getID()[0] != '!') {
494  route = route->copy("!" + myVehicleParameter->id, myVehicleParameter->depart);
495  }
496  // build the vehicle
497  if (!MsgHandler::getErrorInstance()->wasInformed()) {
498  ROVehicle* veh = new ROVehicle(*myVehicleParameter, route, type, &myNet, myErrorOutput);
499  if (myNet.addVehicle(myVehicleParameter->id, veh)) {
501  }
502  }
503 }
504 
505 
506 void
508  if (myActivePerson->getPlan().empty()) {
509  WRITE_WARNING("Discarding person '" + myVehicleParameter->id + "' because it's plan is empty");
510  } else {
513  }
514  }
515  delete myVehicleParameter;
516  myVehicleParameter = 0;
517  myActivePerson = 0;
518 }
519 
520 void
523  if (myActiveContainerPlanSize > 0) {
526  } else {
527  WRITE_WARNING("Discarding container '" + myVehicleParameter->id + "' because it's plan is empty");
528  }
529  delete myVehicleParameter;
530  myVehicleParameter = 0;
531  delete myActiveContainerPlan;
534 }
535 
536 
537 void
539  // @todo: consider myScale?
541  delete myVehicleParameter;
542  myVehicleParameter = 0;
543  return;
544  }
545  // let's check whether vehicles had to depart before the simulation starts
547  const SUMOTime offsetToBegin = string2time(OptionsCont::getOptions().getString("begin")) - myVehicleParameter->depart;
551  delete myVehicleParameter;
552  myVehicleParameter = 0;
553  return;
554  }
555  }
557  myErrorOutput->inform("The vehicle type '" + myVehicleParameter->vtypeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
558  }
560  closeRoute(true);
561  }
563  myErrorOutput->inform("The route '" + myVehicleParameter->routeid + "' for flow '" + myVehicleParameter->id + "' is not known.");
564  delete myVehicleParameter;
565  myVehicleParameter = 0;
566  return;
567  }
568  myActiveRouteID = "";
569  if (!MsgHandler::getErrorInstance()->wasInformed()) {
570  if (myNet.addFlow(myVehicleParameter, OptionsCont::getOptions().getBool("randomize-flows"))) {
572  } else {
573  myErrorOutput->inform("Another flow with the id '" + myVehicleParameter->id + "' exists.");
574  }
575  } else {
576  delete myVehicleParameter;
577  }
578  myVehicleParameter = 0;
579  myInsertStopEdgesAt = -1;
580 }
581 
582 
583 void
585  if (myActiveContainerPlan != 0) {
587  (*myActiveContainerPlan) << attrs;
590  return;
591  }
592  std::string errorSuffix;
593  if (myVehicleParameter != 0) {
594  errorSuffix = " in vehicle '" + myVehicleParameter->id + "'.";
595  } else {
596  errorSuffix = " in route '" + myActiveRouteID + "'.";
597  }
599  bool ok = parseStop(stop, attrs, errorSuffix, myErrorOutput);
600  if (!ok) {
601  return;
602  }
603  // try to parse the assigned bus stop
604  ROEdge* edge = 0;
605  if (stop.busstop != "") {
606  const SUMOVehicleParameter::Stop* busstop = myNet.getBusStop(stop.busstop);
607  if (busstop == 0) {
608  myErrorOutput->inform("Unknown bus stop '" + stop.busstop + "'" + errorSuffix);
609  return;
610  }
611  stop.lane = busstop->lane;
612  stop.endPos = busstop->endPos;
613  stop.startPos = busstop->startPos;
614  edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
615  } // try to parse the assigned container stop
616  else if (stop.containerstop != "") {
617  const SUMOVehicleParameter::Stop* containerstop = myNet.getContainerStop(stop.containerstop);
618  if (containerstop == 0) {
619  myErrorOutput->inform("Unknown container stop '" + stop.containerstop + "'" + errorSuffix);
620  }
621  stop.lane = containerstop->lane;
622  stop.endPos = containerstop->endPos;
623  stop.startPos = containerstop->startPos;
624  edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
625  } // try to parse the assigned parking area
626  else if (stop.parkingarea != "") {
627  const SUMOVehicleParameter::Stop* parkingarea = myNet.getParkingArea(stop.parkingarea);
628  if (parkingarea == 0) {
629  myErrorOutput->inform("Unknown parking area '" + stop.parkingarea + "'" + errorSuffix);
630  }
631  stop.lane = parkingarea->lane;
632  stop.endPos = parkingarea->endPos;
633  stop.startPos = parkingarea->startPos;
634  edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
635  } else {
636  // no, the lane and the position should be given
637  stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, "");
638  if (!ok || stop.lane == "") {
639  myErrorOutput->inform("A stop must be placed on a bus stop, a container stop, a parking area or a lane" + errorSuffix);
640  return;
641  }
642  edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_')));
643  if (edge == 0) {
644  myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix);
645  return;
646  }
647  stop.endPos = attrs.getOpt<double>(SUMO_ATTR_ENDPOS, 0, ok, edge->getLength());
648  stop.startPos = attrs.getOpt<double>(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS);
649  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false);
650  if (!ok || !checkStopPos(stop.startPos, stop.endPos, edge->getLength(), POSITION_EPS, friendlyPos)) {
651  myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix);
652  return;
653  }
654  }
655  if (myActivePerson != 0) {
656  myActivePerson->addStop(stop, edge);
657  } else if (myVehicleParameter != 0) {
658  myVehicleParameter->stops.push_back(stop);
659  } else {
660  myActiveRouteStops.push_back(stop);
661  }
662  if (myInsertStopEdgesAt >= 0) {
663  myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge);
665  }
666 }
667 
668 
669 void
670 RORouteHandler::parseEdges(const std::string& desc, ConstROEdgeVector& into,
671  const std::string& rid) {
672  if (desc[0] == BinaryFormatter::BF_ROUTE) {
673  std::istringstream in(desc, std::ios::binary);
674  char c;
675  in >> c;
676  FileHelpers::readEdgeVector(in, into, rid);
677  } else {
678  for (StringTokenizer st(desc); st.hasNext();) {
679  const std::string id = st.next();
680  const ROEdge* edge = myNet.getEdge(id);
681  if (edge == 0) {
682  myErrorOutput->inform("The edge '" + id + "' within the route " + rid + " is not known.");
683  } else {
684  into.push_back(edge);
685  }
686  }
687  }
688 }
689 
690 
691 bool
693  bool ok = true;
694  const char* id = myVehicleParameter->id.c_str();
695  assert(!attrs.hasAttribute(SUMO_ATTR_EDGES));
696  const std::string fromID = attrs.get<std::string>(SUMO_ATTR_FROM, id, ok);
697  const std::string toID = attrs.get<std::string>(SUMO_ATTR_TO, id, ok);
698  const std::string modes = attrs.getOpt<std::string>(SUMO_ATTR_MODES, id, ok, "");
699  const std::string types = attrs.getOpt<std::string>(SUMO_ATTR_VTYPES, id, ok, "");
700  const std::string busStop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, id, ok, "");
701 
702  const ROEdge* from = myNet.getEdge(fromID);
703  if (from == 0) {
704  myErrorOutput->inform("The edge '" + fromID + "' within a walk of " + myVehicleParameter->id + " is not known."
705  + "\n The route can not be build.");
706  ok = false;
707  }
708  const ROEdge* to = myNet.getEdge(toID);
709  if (to == 0) {
710  myErrorOutput->inform("The edge '" + toID + "' within a walk of " + myVehicleParameter->id + " is not known."
711  + "\n The route can not be build.");
712  ok = false;
713  }
714  const double departPos = attrs.getOpt<double>(SUMO_ATTR_DEPARTPOS, id, ok, 0);
715  const double arrivalPos = attrs.getOpt<double>(SUMO_ATTR_ARRIVALPOS, id, ok, -NUMERICAL_EPS);
716  SVCPermissions modeSet = 0;
717  for (StringTokenizer st(modes); st.hasNext();) {
718  const std::string mode = st.next();
719  if (mode == "car") {
720  modeSet |= SVC_PASSENGER;
721  } else if (mode == "bicycle") {
722  modeSet |= SVC_BICYCLE;
723  } else if (mode == "public") {
724  modeSet |= SVC_BUS;
725  } else {
726  throw InvalidArgument("Unknown person mode '" + mode + "'.");
727  }
728  }
729  double walkFactor = attrs.getOpt<double>(SUMO_ATTR_WALKFACTOR, id, ok, OptionsCont::getOptions().getFloat("persontrip.walkfactor"));
730  if (ok) {
731  myActivePerson->addTrip(from, to, modeSet, types, departPos, arrivalPos, busStop, walkFactor);
732  }
733  return ok;
734 }
735 
736 
737 /****************************************************************************/
RORouteDef * copy(const std::string &id, const SUMOTime stopOffset) const
Returns a deep copy of the route definition.
Definition: RORouteDef.cpp:402
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:94
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:76
virtual void myEndElement(int element)
Called when a closing tag occurs.
description of a vehicle type
void closeVehicleTypeDistribution()
The time is given.
is a pedestrian
std::string next()
std::string containerstop
(Optional) container stop if one is assigned to the stop
int repetitionNumber
The number of times the vehicle shall be repeatedly inserted.
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:215
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.
a flow definition (used by router)
Represents a generic random distribution.
SUMOVehicleParameter * myVehicleParameter
Parameter of the current vehicle, trip, person, container or flow.
static void readEdgeVector(std::istream &in, std::vector< const E *> &edges, const std::string &rid)
Reads an edge vector binary.
Definition: FileHelpers.h:274
Structure representing possible vehicle parameter.
ConstROEdgeVector myActiveRoute
The current route.
void addAlternativeDef(const RORouteDef *alternative)
Adds an alternative loaded from the file.
Definition: RORouteDef.cpp:82
double defaultProbability
The probability when being added to a distribution without an explicit probability.
vehicle is a bicycle
std::string getString() const
Returns the current content as a string.
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
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;.
SUMOVehicleClass vehicleClass
The vehicle&#39;s class.
double myActiveRouteProbability
The probability of the current route.
MsgHandler *const myErrorOutput
Depending on the "ignore-errors" option different outputs are used.
virtual void myEndElement(int element)
Called when a closing tag occurs.
double getLength() const
Returns the length of the edge.
Definition: ROEdge.h:198
void registerLastDepart()
save last depart (only to be used if vehicle is not discarded)
const double DEFAULT_VEH_PROB
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
double getOverallProb() const
Returns the sum of the probablities of the contained routes.
Definition: RORouteDef.cpp:416
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:351
std::string parkingarea
(Optional) parking area if one is assigned to the stop
#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:333
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:356
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
std::string toTaz
The vehicle&#39;s destination zone (district)
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
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:224
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter *> *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:346
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:231
ROPerson * myActivePerson
The plan of the current person.
the edges of a route
std::string routeid
The vehicle&#39;s route id.
double startPos
The stopping position start.
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.
parameter associated to a certain key
std::vector< PlanItem * > & getPlan()
Definition: ROPerson.h:319
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:395
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:112
SUMOTime depart
The vehicle&#39;s departure time.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:47
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:175
std::string fromTaz
The vehicle&#39;s origin zone (district)
double endPos
The stopping position end.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
vehicle is a passenger car (a "normal" car)
A basic edge for routing applications.
Definition: ROEdge.h:77
const int VEHPARS_FROM_TAZ_SET
void addTrip(const ROEdge *const from, const ROEdge *const to, const SVCPermissions modeSet, const std::string &vTypes, const double departPos, const double arrivalPos, const std::string &busStop, double walkFactor)
Definition: ROPerson.cpp:67
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
stop for vehicles
static bool checkStopPos(double &startPos, double &endPos, const double laneLength, const double minLength, const bool friendlyPos)
check start and end position of a stop
std::vector< SUMOVehicleParameter::Stop > myActiveRouteStops
List of the stops on the parsed route.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
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
void addWalk(const ConstROEdgeVector &edges, const double duration, const double speed, const double departPos, const double arrivalPos, const std::string &busStop)
Definition: ROPerson.cpp:103
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:253
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:85
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.
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
void addLoadedAlternative(RORoute *alternative)
Adds a single alternative loaded from the file An alternative may also be generated during DUA...
Definition: RORouteDef.cpp:76
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.
double myCurrentCosts
The currently parsed route costs.
virtual ~RORouteHandler()
standard destructor
bool closeTag()
Closes the most recently opened tag.
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:281
long long int SUMOTime
Definition: TraCIDefs.h:52
#define NUMERICAL_EPS
Definition: config.h:151
a single trip definition (used by router)
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:239
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:369
An edge representing a whole district.
Definition: ROEdge.h:87
const SUMOVehicleParameter::Stop * getParkingArea(const std::string &id) const
Retrieves a parking area from the network.
Definition: RONet.h:267
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
std::string myActiveRouteRefID
The id of the route the current route references to.
A color information.
bool addPerson(ROPerson *person)
Definition: RONet.cpp:383
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.