SUMO - Simulation of Urban MObility
RONet.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // The router's network representation
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <algorithm>
32 #include <utils/common/ToString.h>
36 #include "ROEdge.h"
37 #include "RONode.h"
38 #include "ROPerson.h"
39 #include "RORoute.h"
40 #include "RORouteDef.h"
41 #include "ROVehicle.h"
42 #include "RONet.h"
43 
44 
45 // ===========================================================================
46 // static member definitions
47 // ===========================================================================
48 RONet* RONet::myInstance = nullptr;
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 RONet*
56  if (myInstance != nullptr) {
57  return myInstance;
58  }
59  throw ProcessError("A network was not yet constructed.");
60 }
61 
62 
66  myHaveActiveFlows(true),
67  myRoutesOutput(nullptr), myRouteAlternativesOutput(nullptr), myTypesOutput(nullptr),
69  myHavePermissions(false),
71  myErrorHandler(OptionsCont::getOptions().exists("ignore-errors")
72  && OptionsCont::getOptions().getBool("ignore-errors") ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance()),
73  myKeepVTypeDist(OptionsCont::getOptions().exists("keep-vtype-distributions")
74  && OptionsCont::getOptions().getBool("keep-vtype-distributions")) {
75  if (myInstance != nullptr) {
76  throw ProcessError("A network was already constructed.");
77  }
79  type->onlyReferenced = true;
80  myVehicleTypes.add(type->id, type);
82  defPedType->onlyReferenced = true;
84  myVehicleTypes.add(defPedType->id, defPedType);
86  defBikeType->onlyReferenced = true;
88  myVehicleTypes.add(defBikeType->id, defBikeType);
89  myInstance = this;
90 }
91 
92 
94  for (RoutablesMap::iterator routables = myRoutables.begin(); routables != myRoutables.end(); ++routables) {
95  for (RORoutable* const r : routables->second) {
96  const ROVehicle* const veh = dynamic_cast<const ROVehicle*>(r);
97  // delete routes and the vehicle
98  if (veh != nullptr && veh->getRouteDefinition()->getID()[0] == '!') {
99  if (!myRoutes.remove(veh->getRouteDefinition()->getID())) {
100  delete veh->getRouteDefinition();
101  }
102  }
103  delete r;
104  }
105  }
106  for (const RORoutable* const r : myPTVehicles) {
107  const ROVehicle* const veh = dynamic_cast<const ROVehicle*>(r);
108  // delete routes and the vehicle
109  if (veh != nullptr && veh->getRouteDefinition()->getID()[0] == '!') {
110  if (!myRoutes.remove(veh->getRouteDefinition()->getID())) {
111  delete veh->getRouteDefinition();
112  }
113  }
114  delete r;
115  }
116  myRoutables.clear();
117 }
118 
119 
120 void
121 RONet::addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed) {
122  myRestrictions[id][svc] = speed;
123 }
124 
125 
126 const std::map<SUMOVehicleClass, double>*
127 RONet::getRestrictions(const std::string& id) const {
128  std::map<std::string, std::map<SUMOVehicleClass, double> >::const_iterator i = myRestrictions.find(id);
129  if (i == myRestrictions.end()) {
130  return nullptr;
131  }
132  return &i->second;
133 }
134 
135 
136 bool
138  if (!myEdges.add(edge->getID(), edge)) {
139  WRITE_ERROR("The edge '" + edge->getID() + "' occurs at least twice.");
140  delete edge;
141  return false;
142  }
143  if (edge->isInternal()) {
144  myNumInternalEdges += 1;
145  }
146  return true;
147 }
148 
149 
150 bool
151 RONet::addDistrict(const std::string id, ROEdge* source, ROEdge* sink) {
152  if (myDistricts.count(id) > 0) {
153  WRITE_ERROR("The TAZ '" + id + "' occurs at least twice.");
154  delete source;
155  delete sink;
156  return false;
157  }
159  addEdge(sink);
161  addEdge(source);
162  myDistricts[id] = std::make_pair(std::vector<std::string>(), std::vector<std::string>());
163  return true;
164 }
165 
166 
167 bool
168 RONet::addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource) {
169  if (myDistricts.count(tazID) == 0) {
170  WRITE_ERROR("The TAZ '" + tazID + "' is unknown.");
171  return false;
172  }
173  ROEdge* edge = getEdge(edgeID);
174  if (edge == nullptr) {
175  WRITE_ERROR("The edge '" + edgeID + "' for TAZ '" + tazID + "' is unknown.");
176  return false;
177  }
178  if (isSource) {
179  getEdge(tazID + "-source")->addSuccessor(edge);
180  myDistricts[tazID].first.push_back(edgeID);
181  } else {
182  edge->addSuccessor(getEdge(tazID + "-sink"));
183  myDistricts[tazID].second.push_back(edgeID);
184  }
185  return true;
186 }
187 
188 
189 void
191  if (!myNodes.add(node->getID(), node)) {
192  WRITE_ERROR("The node '" + node->getID() + "' occurs at least twice.");
193  delete node;
194  }
195 }
196 
197 
198 void
199 RONet::addStoppingPlace(const std::string& id, const SumoXMLTag category, SUMOVehicleParameter::Stop* stop) {
200  if (!myStoppingPlaces[category == SUMO_TAG_TRAIN_STOP ? SUMO_TAG_BUS_STOP : category].add(id, stop)) {
201  WRITE_ERROR("The " + toString(category) + " '" + id + "' occurs at least twice.");
202  delete stop;
203  }
204 }
205 
206 
207 bool
209  return myRoutes.add(def->getID(), def);
210 }
211 
212 
213 void
215  if (options.isSet("output-file") && options.getString("output-file") != "") {
216  myRoutesOutput = &OutputDevice::getDevice(options.getString("output-file"));
218  myRoutesOutput->writeAttr("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").writeAttr("xsi:noNamespaceSchemaLocation", "http://sumo.dlr.de/xsd/routes_file.xsd");
219  }
220  if (options.exists("alternatives-output") && options.isSet("alternatives-output")) {
221  myRouteAlternativesOutput = &OutputDevice::getDevice(options.getString("alternatives-output"));
223  myRouteAlternativesOutput->writeAttr("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").writeAttr("xsi:noNamespaceSchemaLocation", "http://sumo.dlr.de/xsd/routes_file.xsd");
224  }
225  if (options.isSet("vtype-output")) {
226  myTypesOutput = &OutputDevice::getDevice(options.getString("vtype-output"));
228  myTypesOutput->writeAttr("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").writeAttr("xsi:noNamespaceSchemaLocation", "http://sumo.dlr.de/xsd/routes_file.xsd");
229  }
230 }
231 
232 
233 void
234 RONet::writeIntermodal(const OptionsCont& options, ROIntermodalRouter& router) const {
235  if (options.exists("intermodal-network-output") && options.isSet("intermodal-network-output")) {
236  OutputDevice::createDeviceByOption("intermodal-network-output", "intermodal");
237  router.writeNetwork(OutputDevice::getDevice(options.getString("intermodal-network-output")));
238  }
239  if (options.exists("intermodal-weight-output") && options.isSet("intermodal-weight-output")) {
240  OutputDevice::createDeviceByOption("intermodal-weight-output", "weights", "meandata_file.xsd");
241  OutputDevice& dev = OutputDevice::getDeviceByOption("intermodal-weight-output");
243  dev.writeAttr(SUMO_ATTR_ID, "intermodalweights");
244  dev.writeAttr(SUMO_ATTR_BEGIN, 0);
246  router.writeWeights(dev);
247  dev.closeTag();
248  }
249 }
250 
251 
252 void
254  // end writing
255  if (myRoutesOutput != nullptr) {
257  }
258  // only if opened
259  if (myRouteAlternativesOutput != nullptr) {
261  }
262  // only if opened
263  if (myTypesOutput != nullptr) {
264  myTypesOutput->close();
265  }
267 #ifdef HAVE_FOX
268  if (myThreadPool.size() > 0) {
269  myThreadPool.clear();
270  }
271 #endif
272 }
273 
274 
275 
277 RONet::getVehicleTypeSecure(const std::string& id) {
278  // check whether the type was already known
280  if (id == DEFAULT_VTYPE_ID) {
282  }
283  if (id == DEFAULT_PEDTYPE_ID) {
285  }
286  if (id == DEFAULT_BIKETYPE_ID) {
288  }
289  if (type != nullptr) {
290  return type;
291  }
292  VTypeDistDictType::iterator it2 = myVTypeDistDict.find(id);
293  if (it2 != myVTypeDistDict.end()) {
294  return it2->second->get();
295  }
296  if (id == "") {
297  // ok, no vehicle type or an unknown type was given within the user input
298  // return the default type
301  }
302  return type;
303 }
304 
305 
306 bool
307 RONet::checkVType(const std::string& id) {
308  if (id == DEFAULT_VTYPE_ID) {
312  } else {
313  return false;
314  }
315  } else if (id == DEFAULT_PEDTYPE_ID) {
319  } else {
320  return false;
321  }
322  } else {
323  if (myVehicleTypes.get(id) != 0 || myVTypeDistDict.find(id) != myVTypeDistDict.end()) {
324  return false;
325  }
326  }
327  return true;
328 }
329 
330 
331 bool
333  if (checkVType(type->id)) {
334  myVehicleTypes.add(type->id, type);
335  } else {
336  WRITE_ERROR("The vehicle type '" + type->id + "' occurs at least twice.");
337  delete type;
338  return false;
339  }
340  return true;
341 }
342 
343 
344 bool
345 RONet::addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution) {
346  if (checkVType(id)) {
347  myVTypeDistDict[id] = vehTypeDistribution;
348  return true;
349  }
350  return false;
351 }
352 
353 
354 bool
355 RONet::addVehicle(const std::string& id, ROVehicle* veh) {
356  if (myVehIDs.find(id) == myVehIDs.end()) {
357  myVehIDs.insert(id);
358  if (veh->isPublicTransport()) {
359  if (!veh->isPartOfFlow()) {
360  myPTVehicles.push_back(veh);
361  }
362  if (OptionsCont::getOptions().exists("ptline-routing") && !OptionsCont::getOptions().getBool("ptline-routing")) {
363  return true;
364  }
365  }
366  myRoutables[veh->getDepart()].push_back(veh);
367  return true;
368  }
369  WRITE_ERROR("Another vehicle with the id '" + id + "' exists.");
370  return false;
371 }
372 
373 
374 bool
375 RONet::addFlow(SUMOVehicleParameter* flow, const bool randomize) {
376  if (randomize) {
377  myDepartures[flow->id].reserve(flow->repetitionNumber);
378  for (int i = 0; i < flow->repetitionNumber; ++i) {
379  myDepartures[flow->id].push_back(flow->depart + RandHelper::rand(flow->repetitionNumber * flow->repetitionOffset));
380  }
381  std::sort(myDepartures[flow->id].begin(), myDepartures[flow->id].end());
382  std::reverse(myDepartures[flow->id].begin(), myDepartures[flow->id].end());
383  }
384  return myFlows.add(flow->id, flow);
385 }
386 
387 
388 bool
390  if (myPersonIDs.count(person->getID()) == 0) {
391  myPersonIDs.insert(person->getID());
392  myRoutables[person->getDepart()].push_back(person);
393  return true;
394  }
395  WRITE_ERROR("Another person with the id '" + person->getID() + "' exists.");
396  return false;
397 }
398 
399 
400 void
401 RONet::addContainer(const SUMOTime depart, const std::string desc) {
402  myContainers.insert(std::pair<const SUMOTime, const std::string>(depart, desc));
403 }
404 
405 
406 void
407 RONet::checkFlows(SUMOTime time, MsgHandler* errorHandler) {
408  myHaveActiveFlows = false;
409  for (const auto& i : myFlows) {
410  SUMOVehicleParameter* pars = i.second;
411  if (pars->repetitionProbability > 0) {
412  if (pars->repetitionEnd > pars->depart) {
413  myHaveActiveFlows = true;
414  }
415  const SUMOTime origDepart = pars->depart;
416  while (pars->depart < time) {
417  if (pars->repetitionEnd <= pars->depart) {
418  break;
419  }
420  // only call rand if all other conditions are met
421  if (RandHelper::rand() < (pars->repetitionProbability * TS)) {
422  SUMOVehicleParameter* newPars = new SUMOVehicleParameter(*pars);
423  newPars->id = pars->id + "." + toString(pars->repetitionsDone);
424  newPars->depart = pars->depart;
425  for (std::vector<SUMOVehicleParameter::Stop>::iterator stop = newPars->stops.begin(); stop != newPars->stops.end(); ++stop) {
426  if (stop->until >= 0) {
427  stop->until += pars->depart - origDepart;
428  }
429  }
430  pars->repetitionsDone++;
431  // try to build the vehicle
433  if (!myKeepVTypeDist) {
434  // fix the type id in case we used a distribution
435  newPars->vtypeid = type->id;
436  }
437  const SUMOTime stopOffset = pars->routeid[0] == '!' ? pars->depart - origDepart : pars->depart;
438  RORouteDef* route = getRouteDef(pars->routeid)->copy("!" + newPars->id, stopOffset);
439  ROVehicle* veh = new ROVehicle(*newPars, route, type, this, errorHandler);
440  addVehicle(newPars->id, veh);
441  delete newPars;
442  }
443  pars->depart += DELTA_T;
444  }
445  } else {
446  while (pars->repetitionsDone < pars->repetitionNumber) {
447  myHaveActiveFlows = true;
448  SUMOTime depart = static_cast<SUMOTime>(pars->depart + pars->repetitionsDone * pars->repetitionOffset);
449  if (myDepartures.find(pars->id) != myDepartures.end()) {
450  depart = myDepartures[pars->id].back();
451  }
452  if (depart >= time + DELTA_T) {
453  break;
454  }
455  if (myDepartures.find(pars->id) != myDepartures.end()) {
456  myDepartures[pars->id].pop_back();
457  }
458  SUMOVehicleParameter* newPars = new SUMOVehicleParameter(*pars);
459  newPars->id = pars->id + "." + toString(pars->repetitionsDone);
460  newPars->depart = depart;
461  for (std::vector<SUMOVehicleParameter::Stop>::iterator stop = newPars->stops.begin(); stop != newPars->stops.end(); ++stop) {
462  if (stop->until >= 0) {
463  stop->until += depart - pars->depart;
464  }
465  }
466  pars->repetitionsDone++;
467  // try to build the vehicle
469  if (type == nullptr) {
471  } else {
472  // fix the type id in case we used a distribution
473  newPars->vtypeid = type->id;
474  }
475  const SUMOTime stopOffset = pars->routeid[0] == '!' ? depart - pars->depart : depart;
476  RORouteDef* route = getRouteDef(pars->routeid)->copy("!" + newPars->id, stopOffset);
477  ROVehicle* veh = new ROVehicle(*newPars, route, type, this, errorHandler);
478  addVehicle(newPars->id, veh);
479  delete newPars;
480  }
481  }
482  }
483 }
484 
485 
486 void
487 RONet::createBulkRouteRequests(const RORouterProvider& provider, const SUMOTime time, const bool removeLoops) {
488  std::map<const int, std::vector<RORoutable*> > bulkVehs;
489  for (RoutablesMap::const_iterator i = myRoutables.begin(); i != myRoutables.end(); ++i) {
490  if (i->first >= time) {
491  break;
492  }
493  for (RORoutable* const routable : i->second) {
494  const ROEdge* const depEdge = routable->getDepartEdge();
495  bulkVehs[depEdge->getNumericalID()].push_back(routable);
496  RORoutable* const first = bulkVehs[depEdge->getNumericalID()].front();
497  if (first->getMaxSpeed() != routable->getMaxSpeed()) {
498  WRITE_WARNING("Bulking different maximum speeds ('" + first->getID() + "' and '" + routable->getID() + "') may lead to suboptimal routes.");
499  }
500  if (first->getVClass() != routable->getVClass()) {
501  WRITE_WARNING("Bulking different vehicle classes ('" + first->getID() + "' and '" + routable->getID() + "') may lead to invalid routes.");
502  }
503  }
504  }
505  int workerIndex = 0;
506  for (std::map<const int, std::vector<RORoutable*> >::const_iterator i = bulkVehs.begin(); i != bulkVehs.end(); ++i) {
507 #ifdef HAVE_FOX
508  if (myThreadPool.size() > 0) {
509  RORoutable* const first = i->second.front();
510  myThreadPool.add(new RoutingTask(first, removeLoops, myErrorHandler), workerIndex);
511  myThreadPool.add(new BulkmodeTask(true), workerIndex);
512  for (std::vector<RORoutable*>::const_iterator j = i->second.begin() + 1; j != i->second.end(); ++j) {
513  myThreadPool.add(new RoutingTask(*j, removeLoops, myErrorHandler), workerIndex);
514  }
515  myThreadPool.add(new BulkmodeTask(false), workerIndex);
516  workerIndex++;
517  if (workerIndex == (int)myThreadPool.size()) {
518  workerIndex = 0;
519  }
520  continue;
521  }
522 #endif
523  for (std::vector<RORoutable*>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
524  (*j)->computeRoute(provider, removeLoops, myErrorHandler);
525  provider.getVehicleRouter().setBulkMode(true);
526  }
527  provider.getVehicleRouter().setBulkMode(false);
528  }
529 }
530 
531 
532 SUMOTime
534  SUMOTime time) {
535  MsgHandler* mh = (options.getBool("ignore-errors") ?
537  if (myHaveActiveFlows) {
538  checkFlows(time, mh);
539  }
540  SUMOTime lastTime = -1;
541  const bool removeLoops = options.getBool("remove-loops");
542  const int maxNumThreads = options.getInt("routing-threads");
543  if (myRoutables.size() != 0) {
544  if (options.getBool("bulk-routing")) {
545 #ifdef HAVE_FOX
546  while ((int)myThreadPool.size() < maxNumThreads) {
547  new WorkerThread(myThreadPool, provider);
548  }
549 #endif
550  createBulkRouteRequests(provider, time, removeLoops);
551  } else {
552  for (RoutablesMap::const_iterator i = myRoutables.begin(); i != myRoutables.end(); ++i) {
553  if (i->first >= time) {
554  break;
555  }
556  for (RORoutable* const routable : i->second) {
557 #ifdef HAVE_FOX
558  // add task
559  if (maxNumThreads > 0) {
560  const int numThreads = (int)myThreadPool.size();
561  if (numThreads == 0) {
562  // This is the very first routing. Since at least the CHRouter needs initialization
563  // before it gets cloned, we do not do this in parallel
564  routable->computeRoute(provider, removeLoops, myErrorHandler);
565  new WorkerThread(myThreadPool, provider);
566  } else {
567  // add thread if necessary
568  if (numThreads < maxNumThreads && myThreadPool.isFull()) {
569  new WorkerThread(myThreadPool, provider);
570  }
571  myThreadPool.add(new RoutingTask(routable, removeLoops, myErrorHandler));
572  }
573  continue;
574  }
575 #endif
576  routable->computeRoute(provider, removeLoops, myErrorHandler);
577  }
578  }
579  }
580 #ifdef HAVE_FOX
581  myThreadPool.waitAll();
582 #endif
583  }
584  // write all vehicles (and additional structures)
585  while (myRoutables.size() != 0 || myContainers.size() != 0) {
586  // get the next vehicle, person or container
587  RoutablesMap::iterator routables = myRoutables.begin();
588  const SUMOTime routableTime = routables == myRoutables.end() ? SUMOTime_MAX : routables->first;
589  ContainerMap::iterator container = myContainers.begin();
590  const SUMOTime containerTime = container == myContainers.end() ? SUMOTime_MAX : container->first;
591  // check whether it shall not yet be computed
592  if (routableTime >= time && containerTime >= time) {
593  lastTime = MIN2(routableTime, containerTime);
594  break;
595  }
596  const SUMOTime minTime = MIN2(routableTime, containerTime);
597  if (routableTime == minTime) {
598  // check whether to print the output
599  if (lastTime != routableTime && lastTime != -1) {
600  // report writing progress
601  if (options.getInt("stats-period") >= 0 && ((int)routableTime % options.getInt("stats-period")) == 0) {
602  WRITE_MESSAGE("Read: " + toString(myVehIDs.size()) + ", Discarded: " + toString(myDiscardedRouteNo) + ", Written: " + toString(myWrittenRouteNo));
603  }
604  }
605  lastTime = routableTime;
606  for (const RORoutable* const r : routables->second) {
607  // ok, check whether it has been routed
608  if (r->getRoutingSuccess()) {
609  // write the route
612  } else {
614  }
615  // delete routes and the vehicle
616  if (!r->isPublicTransport() || r->isPartOfFlow()) {
617  const ROVehicle* const veh = dynamic_cast<const ROVehicle*>(r);
618  if (veh != nullptr && veh->getRouteDefinition()->getID()[0] == '!') {
619  if (!myRoutes.remove(veh->getRouteDefinition()->getID())) {
620  delete veh->getRouteDefinition();
621  }
622  }
623  delete r;
624  }
625  }
626  myRoutables.erase(routables);
627  }
628  if (containerTime == minTime) {
629  myRoutesOutput->writePreformattedTag(container->second);
630  if (myRouteAlternativesOutput != nullptr) {
632  }
633  myContainers.erase(container);
634  }
635  }
636  return lastTime;
637 }
638 
639 
640 bool
642  return myRoutables.size() > 0 || (myFlows.size() > 0 && myHaveActiveFlows) || myContainers.size() > 0;
643 }
644 
645 
646 int
648  return myEdges.size();
649 }
650 
651 
652 int
654  return myNumInternalEdges;
655 }
656 
657 
658 void
660  // add access to all parking areas
661  for (const auto& i : myInstance->myStoppingPlaces[SUMO_TAG_PARKING_AREA]) {
662  router.getNetwork()->addAccess(i.first, myInstance->getEdgeForLaneID(i.second->lane), (i.second->startPos + i.second->endPos) / 2., 0., SUMO_TAG_PARKING_AREA);
663  }
664  // add access to all public transport stops
665  for (const auto& stop : myInstance->myStoppingPlaces[SUMO_TAG_BUS_STOP]) {
666  router.getNetwork()->addAccess(stop.first, myInstance->getEdgeForLaneID(stop.second->lane), (stop.second->startPos + stop.second->endPos) / 2., 0., SUMO_TAG_BUS_STOP);
667  for (const auto& a : stop.second->accessPos) {
668  router.getNetwork()->addAccess(stop.first, myInstance->getEdgeForLaneID(std::get<0>(a)), std::get<1>(a), std::get<2>(a), SUMO_TAG_BUS_STOP);
669  }
670  }
671  // fill the public transport router with pre-parsed public transport lines
672  for (const auto& i : myInstance->myFlows) {
673  if (i.second->line != "") {
674  const RORouteDef* const route = myInstance->getRouteDef(i.second->routeid);
675  const std::vector<SUMOVehicleParameter::Stop>* addStops = nullptr;
676  if (route != nullptr && route->getFirstRoute() != nullptr) {
677  addStops = &route->getFirstRoute()->getStops();
678  }
679  router.getNetwork()->addSchedule(*i.second, addStops);
680  }
681  }
682  for (const RORoutable* const veh : myInstance->myPTVehicles) {
683  // add single vehicles with line attribute which are not part of a flow
684  // no need to add route stops here, they have been added to the vehicle before
685  router.getNetwork()->addSchedule(veh->getParameter());
686  }
687 }
688 
689 
690 bool
692  return myHavePermissions;
693 }
694 
695 
696 void
698  myHavePermissions = true;
699 }
700 
701 const std::string
702 RONet::getStoppingPlaceName(const std::string& id) const {
703  for (const auto& mapItem : myStoppingPlaces) {
704  SUMOVehicleParameter::Stop* stop = mapItem.second.get(id);
705  if (stop != nullptr) {
706  // see RONetHandler::parseStoppingPlace
707  return stop->busstop;
708  }
709  }
710  return "";
711 }
712 
713 #ifdef HAVE_FOX
714 // ---------------------------------------------------------------------------
715 // RONet::RoutingTask-methods
716 // ---------------------------------------------------------------------------
717 void
718 RONet::RoutingTask::run(FXWorkerThread* context) {
719  myRoutable->computeRoute(*static_cast<WorkerThread*>(context), myRemoveLoops, myErrorHandler);
720 }
721 #endif
722 
723 
724 /****************************************************************************/
725 
RORouteDef * copy(const std::string &id, const SUMOTime stopOffset) const
Returns a deep copy of the route definition.
Definition: RORouteDef.cpp:384
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:67
SUMOTime repetitionEnd
The time at which the flow ends (only needed when using repetitionProbability)
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition: RONet.cpp:168
void writeWeights(OutputDevice &dev)
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
std::map< SumoXMLTag, NamedObjectCont< SUMOVehicleParameter::Stop * > > myStoppingPlaces
Known bus / train / container stops and parking areas.
Definition: RONet.h:466
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition: RONet.h:514
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:647
void close()
Closes the device and removes it from the dictionary.
SumoXMLTag
Numbers representing SUMO-XML - element names.
bool isPartOfFlow() const
Definition: RORoutable.h:126
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:76
SUMOVehicleClass getVClass() const
Definition: RORoutable.h:108
long long int SUMOTime
Definition: SUMOTime.h:36
int getNumericalID() const
Returns the index (numeric id) of the edge.
Definition: ROEdge.h:206
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition: RONet.h:492
ROEdge * getEdgeForLaneID(const std::string &laneID) const
Retrieves an edge from the network when the lane id is given.
Definition: RONet.h:167
is a pedestrian
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
Definition: RONet.cpp:653
void writeNetwork(OutputDevice &dev)
int repetitionNumber
The number of times the vehicle shall be repeatedly inserted.
virtual const ROEdge * getDepartEdge() const =0
std::map< std::string, std::pair< std::vector< std::string >, std::vector< std::string > > > myDistricts
traffic assignment zones with sources and sinks
Definition: RONet.h:508
std::string vtypeid
The vehicle&#39;s type id.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
void writeIntermodal(const OptionsCont &options, ROIntermodalRouter &router) const
Writes the intermodal network and weights if requested.
Definition: RONet.cpp:234
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: RONet.h:529
Represents a generic random distribution.
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition: RONet.h:535
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition: RONet.cpp:307
double getMaxSpeed() const
Returns the vehicle&#39;s maximum speed.
Definition: RORoutable.h:114
int size() const
Returns the number of stored items within the container.
Structure representing possible vehicle parameter.
const SUMOVehicleParameter & getParameter() const
Returns the definition of the vehicle / person parameter.
Definition: RORoutable.h:74
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition: RONet.cpp:659
void addNode(RONode *node)
Definition: RONet.cpp:190
const RORoute * getFirstRoute() const
Definition: RORouteDef.h:101
void write(OutputDevice &os, OutputDevice *const altos, OutputDevice *const typeos, OptionsCont &options) const
Saves the routable including the vehicle type (if it was not saved before).
Definition: RORoutable.h:141
vehicle is a bicycle
T get(const std::string &id) const
Retrieves an item.
double repetitionProbability
The probability for emitting a vehicle per second.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:61
OutputDevice & writePreformattedTag(const std::string &val)
writes a preformatted tag to the device but ensures that any pending tags are closed ...
Definition: OutputDevice.h:302
int repetitionsDone
The number of times the vehicle was already inserted.
void checkFlows(SUMOTime time, MsgHandler *errorHandler)
Definition: RONet.cpp:407
weights: time range begin
bool myHaveActiveFlows
whether any flows are still active
Definition: RONet.h:495
SUMOTime DELTA_T
Definition: SUMOTime.cpp:35
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition: RONet.h:463
const std::map< SUMOVehicleClass, double > * getRestrictions(const std::string &id) const
Returns the restrictions for an edge type If no restrictions are present, 0 is returned.
Definition: RONet.cpp:127
const std::string DEFAULT_BIKETYPE_ID
bool hasPermissions() const
Definition: RONet.cpp:691
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getID() const
Returns the id.
Definition: Named.h:78
int myDiscardedRouteNo
The number of discarded routes.
Definition: RONet.h:523
#define TS
Definition: SUMOTime.h:45
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition: RONet.h:505
std::vector< const RORoutable * > myPTVehicles
vehicles to keep for public transport routing
Definition: RONet.h:502
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition: RONet.h:517
const std::string DEFAULT_VTYPE_ID
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition: RONet.h:298
int myWrittenRouteNo
The number of written routes.
Definition: RONet.h:526
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition: RONet.cpp:332
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition: RONet.cpp:355
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition: RONet.cpp:55
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
bool add(const std::string &id, T item)
Adds an item.
SUMOTime getDepart() const
Returns the time the vehicle starts at, -1 for triggered vehicles.
Definition: RORoutable.h:103
bool writeHeader(const SumoXMLTag &rootElement)
Definition: OutputDevice.h:188
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter *> *vehTypeDistribution)
Adds a vehicle type distribution.
Definition: RONet.cpp:345
std::string busstop
(Optional) bus stop if one is assigned to the stop
std::set< std::string > myPersonIDs
Known person ids.
Definition: RONet.h:457
A routable thing such as a vehicle or person.
Definition: RORoutable.h:55
void openOutput(const OptionsCont &options)
Opens the output for computed routes.
Definition: RONet.cpp:214
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
A vehicle as used by router.
Definition: ROVehicle.h:53
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary ...
Definition: RONet.cpp:253
root element of a route file
bool addRouteDef(RORouteDef *def)
Definition: RONet.cpp:208
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition: RONet.cpp:121
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
std::string routeid
The vehicle&#39;s route id.
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition: RONet.h:511
bool isPublicTransport() const
Definition: RORoutable.h:122
void addContainer(const SUMOTime depart, const std::string desc)
Definition: RONet.cpp:401
bool getRoutingSuccess() const
Definition: RORoutable.h:154
RoutablesMap myRoutables
Known routables.
Definition: RONet.h:489
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
Definition: RONet.h:483
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition: RONet.h:469
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the list of stops this route contains.
Definition: RORoute.h:184
SUMOTime depart
The vehicle&#39;s departure time.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
ContainerMap myContainers
Definition: RONet.h:499
bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition: RONet.cpp:641
T MIN2(T a, T b)
Definition: StdDefs.h:70
A person as used by router.
Definition: ROPerson.h:51
static RONet * myInstance
Unique instance of RONet.
Definition: RONet.h:451
bool myDefaultVTypeMayBeDeleted
Whether the default vehicle type was already used or can still be replaced.
Definition: RONet.h:477
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition: RONet.h:486
void createBulkRouteRequests(const RORouterProvider &provider, const SUMOTime time, const bool removeLoops)
Definition: RONet.cpp:487
const bool myKeepVTypeDist
whether to keep the the vtype distribution in output
Definition: RONet.h:541
const std::string & getID() const
Returns the id of the routable.
Definition: RORoutable.h:94
vehicle is a passenger car (a "normal" car)
A basic edge for routing applications.
Definition: ROEdge.h:72
bool onlyReferenced
Information whether this is a type-stub, being only referenced but not defined (needed by routers) ...
RORouteDef * getRouteDefinition() const
Returns the definition of the route the vehicle takes.
Definition: ROVehicle.h:76
virtual void computeRoute(const RORouterProvider &provider, const bool removeLoops, MsgHandler *errorHandler)=0
int parametersSet
Information for the router which parameter were set.
bool isInternal() const
return whether this edge is an internal edge
Definition: ROEdge.h:144
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:247
SUMOAbstractRouter< E, V > & getVehicleRouter() const
RONet()
Constructor.
Definition: RONet.cpp:63
The router&#39;s network representation.
Definition: RONet.h:68
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Definition: RONet.cpp:151
Structure representing possible vehicle parameter.
A train stop (alias for bus stop)
void addSchedule(const SUMOVehicleParameter &pars, const std::vector< SUMOVehicleParameter::Stop > *addStops=nullptr)
#define SUMOTime_MAX
Definition: SUMOTime.h:37
int myReadRouteNo
The number of read routes.
Definition: RONet.h:520
void addStoppingPlace(const std::string &id, const SumoXMLTag category, SUMOVehicleParameter::Stop *stop)
Definition: RONet.cpp:199
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition: RONet.h:532
const std::string DEFAULT_PEDTYPE_ID
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
virtual void addSuccessor(ROEdge *s, ROEdge *via=nullptr, std::string dir="")
Adds information about a connected edge.
Definition: ROEdge.cpp:103
weights: time range end
Definition of vehicle stop (position and duration)
A storage for options typed value containers)
Definition: OptionsCont.h:92
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition: RONet.h:474
Base class for a vehicle&#39;s route definition.
Definition: RORouteDef.h:56
std::string id
The vehicle type&#39;s id.
const std::string getStoppingPlaceName(const std::string &id) const
return the name for the given stopping place id
Definition: RONet.cpp:702
virtual bool addEdge(ROEdge *edge)
Definition: RONet.cpp:137
an aggreagated-output interval
static bool createDeviceByOption(const std::string &optionName, const std::string &rootElement="", const std::string &schemaFile="")
Creates the device using the output definition stored in the named option.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
std::set< std::string > myVehIDs
Known vehicle ids.
Definition: RONet.h:454
virtual ~RONet()
Destructor.
Definition: RONet.cpp:93
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition: RONet.cpp:277
A thread repeatingly calculating incoming tasks.
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition: RONet.h:538
Base class for nodes used by the router.
Definition: RONode.h:46
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition: RONet.h:460
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:157
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition: RONet.cpp:375
bool remove(const std::string &id, const bool del=true)
Removes an item.
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:242
const int VTYPEPARS_VEHICLECLASS_SET
bool addPerson(ROPerson *person)
Definition: RONet.cpp:389
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, const RORouterProvider &provider, SUMOTime time)
Computes routes described by their definitions and saves them.
Definition: RONet.cpp:533
void addAccess(const std::string &stopId, const E *stopEdge, const double pos, const double length, const SumoXMLTag category)
Adds access edges for stopping places to the intermodal network.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Network * getNetwork() const
std::string id
The vehicle&#39;s id.
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
Definition: RONet.h:480
void setPermissionsFound()
Definition: RONet.cpp:697
void setFunction(SumoXMLEdgeFunc func)
Sets the function of the edge.
Definition: ROEdge.h:114