Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
RONet.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// The router's network representation
21/****************************************************************************/
22#include <config.h>
23
24#include <algorithm>
35#include "ROEdge.h"
36#include "ROLane.h"
37#include "RONode.h"
38#include "ROPerson.h"
39#include "RORoute.h"
40#include "RORouteDef.h"
41#include "ROVehicle.h"
43#include "RONet.h"
44
45
46// ===========================================================================
47// static member definitions
48// ===========================================================================
49RONet* RONet::myInstance = nullptr;
50
51
52// ===========================================================================
53// method definitions
54// ===========================================================================
55RONet*
57 if (myInstance != nullptr) {
58 return myInstance;
59 }
60 throw ProcessError(TL("A network was not yet constructed."));
61}
62
63
65 myVehicleTypes(), myDefaultVTypeMayBeDeleted(true),
66 myDefaultPedTypeMayBeDeleted(true),
67 myDefaultBikeTypeMayBeDeleted(true),
68 myDefaultTaxiTypeMayBeDeleted(true),
69 myDefaultRailTypeMayBeDeleted(true),
70 myHaveActiveFlows(true),
71 myRoutesOutput(nullptr), myRouteAlternativesOutput(nullptr), myTypesOutput(nullptr),
72 myReadRouteNo(0), myDiscardedRouteNo(0), myWrittenRouteNo(0),
73 myHavePermissions(false),
74 myNumInternalEdges(0),
75 myErrorHandler(OptionsCont::getOptions().exists("ignore-errors")
76 && OptionsCont::getOptions().getBool("ignore-errors") ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance()),
77 myKeepVTypeDist(OptionsCont::getOptions().exists("keep-vtype-distributions")
78 && OptionsCont::getOptions().getBool("keep-vtype-distributions")),
79 myDoPTRouting(!OptionsCont::getOptions().exists("ptline-routing")
80 || OptionsCont::getOptions().getBool("ptline-routing")),
81 myHasBidiEdges(false) {
82 if (myInstance != nullptr) {
83 throw ProcessError(TL("A network was already constructed."));
84 }
86 type->onlyReferenced = true;
87 myVehicleTypes.add(type->id, type);
88
90 defPedType->onlyReferenced = true;
92 myVehicleTypes.add(defPedType->id, defPedType);
93
95 defBikeType->onlyReferenced = true;
97 myVehicleTypes.add(defBikeType->id, defBikeType);
98
100 defTaxiType->onlyReferenced = true;
102 myVehicleTypes.add(defTaxiType->id, defTaxiType);
103
105 defRailType->onlyReferenced = true;
107 myVehicleTypes.add(defRailType->id, defRailType);
108
109 myInstance = this;
110}
111
112
114 for (const auto& routables : myRoutables) {
115 for (RORoutable* const r : routables.second) {
116 const ROVehicle* const veh = dynamic_cast<const ROVehicle*>(r);
117 // delete routes and the vehicle
118 if (veh != nullptr && veh->getRouteDefinition()->getID()[0] == '!') {
119 if (!myRoutes.remove(veh->getRouteDefinition()->getID())) {
120 delete veh->getRouteDefinition();
121 }
122 }
123 delete r;
124 }
125 }
126 for (const RORoutable* const r : myPTVehicles) {
127 const ROVehicle* const veh = dynamic_cast<const ROVehicle*>(r);
128 // delete routes and the vehicle
129 if (veh != nullptr && veh->getRouteDefinition()->getID()[0] == '!') {
130 if (!myRoutes.remove(veh->getRouteDefinition()->getID())) {
131 delete veh->getRouteDefinition();
132 }
133 }
134 delete r;
135 }
136 myRoutables.clear();
137 for (const auto& vTypeDist : myVTypeDistDict) {
138 delete vTypeDist.second;
139 }
140}
141
142
143void
144RONet::addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed) {
145 myRestrictions[id][svc] = speed;
146}
147
148
149const std::map<SUMOVehicleClass, double>*
150RONet::getRestrictions(const std::string& id) const {
151 std::map<std::string, std::map<SUMOVehicleClass, double> >::const_iterator i = myRestrictions.find(id);
152 if (i == myRestrictions.end()) {
153 return nullptr;
154 }
155 return &i->second;
156}
157
158
159bool
161 if (!myEdges.add(edge->getID(), edge)) {
162 WRITE_ERRORF(TL("The edge '%' occurs at least twice."), edge->getID());
163 delete edge;
164 return false;
165 }
166 if (edge->isInternal()) {
168 }
169 return true;
170}
171
172
173bool
174RONet::addDistrict(const std::string id, ROEdge* source, ROEdge* sink) {
175 if (myDistricts.count(id) > 0) {
176 WRITE_ERRORF(TL("The TAZ '%' occurs at least twice."), id);
177 delete source;
178 delete sink;
179 return false;
180 }
182 if (!addEdge(sink)) {
183 return false;
184 }
186 if (!addEdge(source)) {
187 return false;
188 }
189 sink->setOtherTazConnector(source);
190 source->setOtherTazConnector(sink);
191 myDistricts[id] = std::make_pair(std::vector<std::string>(), std::vector<std::string>());
192 return true;
193}
194
195
196bool
197RONet::addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource) {
198 if (myDistricts.count(tazID) == 0) {
199 WRITE_ERRORF(TL("The TAZ '%' is unknown."), tazID);
200 return false;
201 }
202 ROEdge* edge = getEdge(edgeID);
203 if (edge == nullptr) {
204 WRITE_ERRORF(TL("The edge '%' for TAZ '%' is unknown."), edgeID, tazID);
205 return false;
206 }
207 if (isSource) {
208 getEdge(tazID + "-source")->addSuccessor(edge);
209 myDistricts[tazID].first.push_back(edgeID);
210 } else {
211 edge->addSuccessor(getEdge(tazID + "-sink"));
212 myDistricts[tazID].second.push_back(edgeID);
213 }
214 return true;
215}
216
217
218void
220 for (auto item : myNodes) {
221 const std::string tazID = item.first;
222 if (myDistricts.count(tazID) != 0) {
223 WRITE_WARNINGF(TL("A TAZ with id '%' already exists. Not building junction TAZ."), tazID);
224 continue;
225 }
226 const std::string sourceID = tazID + "-source";
227 const std::string sinkID = tazID + "-sink";
228 // sink must be added before source
229 ROEdge* sink = eb.buildEdge(sinkID, nullptr, nullptr, 0, "");
230 ROEdge* source = eb.buildEdge(sourceID, nullptr, nullptr, 0, "");
231 sink->setOtherTazConnector(source);
232 source->setOtherTazConnector(sink);
233 if (!addDistrict(tazID, source, sink)) {
234 continue;
235 }
236 auto& district = myDistricts[tazID];
237 const RONode* junction = item.second;
238 for (const ROEdge* edge : junction->getIncoming()) {
239 if (!edge->isInternal()) {
240 const_cast<ROEdge*>(edge)->addSuccessor(sink);
241 district.second.push_back(edge->getID());
242 }
243 }
244 for (const ROEdge* edge : junction->getOutgoing()) {
245 if (!edge->isInternal()) {
246 source->addSuccessor(const_cast<ROEdge*>(edge));
247 district.first.push_back(edge->getID());
248 }
249 }
250 }
251}
252
253
254void
255RONet::setBidiEdges(const std::map<ROEdge*, std::string>& bidiMap) {
256 for (const auto& item : bidiMap) {
257 ROEdge* bidi = myEdges.get(item.second);
258 if (bidi == nullptr) {
259 WRITE_ERRORF(TL("The bidi edge '%' is not known."), item.second);
260 }
261 item.first->setBidiEdge(bidi);
262 myHasBidiEdges = true;
263 }
264}
265
266
267void
269 if (!myNodes.add(node->getID(), node)) {
270 WRITE_ERRORF(TL("The node '%' occurs at least twice."), node->getID());
271 delete node;
272 }
273}
274
275
276void
277RONet::addStoppingPlace(const std::string& id, const SumoXMLTag category, SUMOVehicleParameter::Stop* stop) {
278 if (!myStoppingPlaces[category == SUMO_TAG_TRAIN_STOP ? SUMO_TAG_BUS_STOP : category].add(id, stop)) {
279 WRITE_ERRORF(TL("The % '%' occurs at least twice."), toString(category), id);
280 delete stop;
281 }
282}
283
284
285bool
287 return myRoutes.add(def->getID(), def);
288}
289
290
291void
293 if (options.isSet("output-file") && options.getString("output-file") != "") {
294 myRoutesOutput = &OutputDevice::getDevice(options.getString("output-file"));
295 if (myRoutesOutput->isNull()) {
296 myRoutesOutput = nullptr;
297 } else {
298 myRoutesOutput->writeXMLHeader("routes", "routes_file.xsd");
299 }
300 }
301 if (options.exists("alternatives-output") && options.isSet("alternatives-output")
302 && !(options.exists("write-trips") && options.getBool("write-trips"))) {
303 myRouteAlternativesOutput = &OutputDevice::getDevice(options.getString("alternatives-output"));
306 } else {
307 myRouteAlternativesOutput->writeXMLHeader("routes", "routes_file.xsd");
308 }
309 }
310 if (options.isSet("vtype-output")) {
311 myTypesOutput = &OutputDevice::getDevice(options.getString("vtype-output"));
312 myTypesOutput->writeXMLHeader("routes", "routes_file.xsd");
313 }
314}
315
316
317void
319 if (options.exists("intermodal-network-output") && options.isSet("intermodal-network-output")) {
320 OutputDevice::createDeviceByOption("intermodal-network-output", "intermodal");
321 router.writeNetwork(OutputDevice::getDevice(options.getString("intermodal-network-output")));
322 }
323 if (options.exists("intermodal-weight-output") && options.isSet("intermodal-weight-output")) {
324 OutputDevice::createDeviceByOption("intermodal-weight-output", "weights", "meandata_file.xsd");
325 OutputDevice& dev = OutputDevice::getDeviceByOption("intermodal-weight-output");
327 dev.writeAttr(SUMO_ATTR_ID, "intermodalweights");
330 router.writeWeights(dev);
331 dev.closeTag();
332 }
333}
334
335
336void
338 // end writing
339 if (myRoutesOutput != nullptr) {
341 }
342 // only if opened
343 if (myRouteAlternativesOutput != nullptr) {
345 }
346 // only if opened
347 if (myTypesOutput != nullptr) {
349 }
351#ifdef HAVE_FOX
352 if (myThreadPool.size() > 0) {
353 myThreadPool.clear();
354 }
355#endif
356}
357
358
359
361RONet::getVehicleTypeSecure(const std::string& id) {
362 // check whether the type was already known
364 if (id == DEFAULT_VTYPE_ID) {
366 } else if (id == DEFAULT_PEDTYPE_ID) {
368 } else if (id == DEFAULT_BIKETYPE_ID) {
370 } else if (id == DEFAULT_TAXITYPE_ID) {
372 } else if (id == DEFAULT_RAILTYPE_ID) {
374 }
375 if (type != nullptr) {
376 return type;
377 }
378 VTypeDistDictType::iterator it2 = myVTypeDistDict.find(id);
379 if (it2 != myVTypeDistDict.end()) {
380 return it2->second->get();
381 }
382 if (id == "") {
383 // ok, no vehicle type or an unknown type was given within the user input
384 // return the default type
387 }
388 return type;
389}
390
391
392bool
393RONet::checkVType(const std::string& id) {
394 if (id == DEFAULT_VTYPE_ID) {
398 } else {
399 return false;
400 }
401 } else if (id == DEFAULT_PEDTYPE_ID) {
405 } else {
406 return false;
407 }
408 } else if (id == DEFAULT_BIKETYPE_ID) {
412 } else {
413 return false;
414 }
415 } else if (id == DEFAULT_TAXITYPE_ID) {
419 } else {
420 return false;
421 }
422 } else if (id == DEFAULT_RAILTYPE_ID) {
426 } else {
427 return false;
428 }
429 } else {
430 if (myVehicleTypes.get(id) != 0 || myVTypeDistDict.find(id) != myVTypeDistDict.end()) {
431 return false;
432 }
433 }
434 return true;
435}
436
437
438bool
440 if (checkVType(type->id)) {
441 myVehicleTypes.add(type->id, type);
442 } else {
443 WRITE_ERRORF(TL("The vehicle type '%' occurs at least twice."), type->id);
444 delete type;
445 return false;
446 }
447 return true;
448}
449
450
451bool
452RONet::addVTypeDistribution(const std::string& id, RandomDistributor<SUMOVTypeParameter*>* vehTypeDistribution) {
453 if (checkVType(id)) {
454 myVTypeDistDict[id] = vehTypeDistribution;
455 return true;
456 }
457 delete vehTypeDistribution;
458 return false;
459}
460
461
462bool
463RONet::addVehicle(const std::string& id, ROVehicle* veh) {
464 if (myVehIDs.find(id) == myVehIDs.end()) {
466
467 if (veh->isPublicTransport()) {
468 if (!veh->isPartOfFlow()) {
469 myPTVehicles.push_back(veh);
470 }
471 if (!myDoPTRouting) {
472 return true;
473 }
474 }
475 myRoutables[veh->getDepart()].push_back(veh);
476 return true;
477 }
478 WRITE_ERRORF(TL("Another vehicle with the id '%' exists."), id);
479 delete veh;
480 return false;
481}
482
483
484bool
485RONet::knowsVehicle(const std::string& id) const {
486 return myVehIDs.find(id) != myVehIDs.end();
487}
488
490RONet::getDeparture(const std::string& vehID) const {
491 auto it = myVehIDs.find(vehID);
492 if (it != myVehIDs.end()) {
493 return it->second;
494 } else {
495 throw ProcessError(TLF("Requesting departure time for unknown vehicle '%'", vehID));
496 }
497}
498
499
500bool
501RONet::addFlow(SUMOVehicleParameter* flow, const bool randomize) {
502 if (randomize && flow->repetitionOffset >= 0) {
503 myDepartures[flow->id].reserve(flow->repetitionNumber);
504 for (int i = 0; i < flow->repetitionNumber; ++i) {
505 myDepartures[flow->id].push_back(flow->depart + RandHelper::rand(flow->repetitionNumber * flow->repetitionOffset));
506 }
507 std::sort(myDepartures[flow->id].begin(), myDepartures[flow->id].end());
508 std::reverse(myDepartures[flow->id].begin(), myDepartures[flow->id].end());
509 }
510 const bool added = myFlows.add(flow->id, flow);
511 if (added) {
512 myHaveActiveFlows = true;
513 }
514 return added;
515}
516
517
518bool
520 if (myPersonIDs.count(person->getID()) == 0) {
521 myPersonIDs.insert(person->getID());
522 myRoutables[person->getDepart()].push_back(person);
523 return true;
524 }
525 WRITE_ERRORF(TL("Another person with the id '%' exists."), person->getID());
526 return false;
527}
528
529
530void
531RONet::addContainer(const SUMOTime depart, const std::string desc) {
532 myContainers.insert(std::pair<const SUMOTime, const std::string>(depart, desc));
533}
534
535
536void
538 myHaveActiveFlows = false;
539 for (const auto& i : myFlows) {
540 SUMOVehicleParameter* const pars = i.second;
541 if (pars->line != "" && !myDoPTRouting) {
542 continue;
543 }
544 if (pars->repetitionProbability > 0) {
545 if (pars->repetitionEnd > pars->depart && pars->repetitionsDone < pars->repetitionNumber) {
546 myHaveActiveFlows = true;
547 }
548 const SUMOTime origDepart = pars->depart;
549 while (pars->depart < time && pars->repetitionsDone < pars->repetitionNumber) {
550 if (pars->repetitionEnd <= pars->depart) {
551 break;
552 }
553 // only call rand if all other conditions are met
554 if (RandHelper::rand() < (pars->repetitionProbability * TS)) {
555 SUMOVehicleParameter* newPars = new SUMOVehicleParameter(*pars);
556 newPars->id = pars->id + "." + toString(pars->repetitionsDone);
557 newPars->depart = pars->depart;
558 for (StopParVector::iterator stop = newPars->stops.begin(); stop != newPars->stops.end(); ++stop) {
559 if (stop->until >= 0) {
560 stop->until += pars->depart - origDepart;
561 }
562 }
563 pars->repetitionsDone++;
564 // try to build the vehicle
566 if (type == nullptr) {
568 } else if (!myKeepVTypeDist) {
569 // fix the type id in case we used a distribution
570 newPars->vtypeid = type->id;
571 }
572 const SUMOTime stopOffset = pars->routeid[0] == '!' ? pars->depart - origDepart : pars->depart;
573 RORouteDef* route = getRouteDef(pars->routeid)->copy("!" + newPars->id, stopOffset);
574 ROVehicle* veh = new ROVehicle(*newPars, route, type, this, errorHandler);
575 addVehicle(newPars->id, veh);
576 delete newPars;
577 }
578 pars->depart += DELTA_T;
579 }
580 } else {
581 SUMOTime depart = static_cast<SUMOTime>(pars->depart + pars->repetitionTotalOffset);
582 while (pars->repetitionsDone < pars->repetitionNumber && pars->repetitionEnd >= depart) {
583 myHaveActiveFlows = true;
584 depart = static_cast<SUMOTime>(pars->depart + pars->repetitionTotalOffset);
585 if (myDepartures.find(pars->id) != myDepartures.end()) {
586 depart = myDepartures[pars->id].back();
587 }
588 if (depart >= time + DELTA_T) {
589 break;
590 }
591 if (myDepartures.find(pars->id) != myDepartures.end()) {
592 myDepartures[pars->id].pop_back();
593 }
594 SUMOVehicleParameter* newPars = new SUMOVehicleParameter(*pars);
595 newPars->id = pars->id + "." + toString(pars->repetitionsDone);
596 newPars->depart = depart;
597 for (StopParVector::iterator stop = newPars->stops.begin(); stop != newPars->stops.end(); ++stop) {
598 if (stop->until >= 0) {
599 stop->until += depart - pars->depart;
600 }
601 }
602 pars->incrementFlow(1);
603 // try to build the vehicle
605 if (type == nullptr) {
607 } else {
608 // fix the type id in case we used a distribution
609 newPars->vtypeid = type->id;
610 }
611 const SUMOTime stopOffset = pars->routeid[0] == '!' ? depart - pars->depart : depart;
612 RORouteDef* route = getRouteDef(pars->routeid)->copy("!" + newPars->id, stopOffset);
613 ROVehicle* veh = new ROVehicle(*newPars, route, type, this, errorHandler);
614 addVehicle(newPars->id, veh);
615 delete newPars;
616 }
617 }
618 }
619}
620
621
622void
623RONet::createBulkRouteRequests(const RORouterProvider& provider, const SUMOTime time, const bool removeLoops) {
624 std::map<const int, std::vector<RORoutable*> > bulkVehs;
625 for (RoutablesMap::const_iterator i = myRoutables.begin(); i != myRoutables.end(); ++i) {
626 if (i->first >= time) {
627 break;
628 }
629 for (RORoutable* const routable : i->second) {
630 const ROEdge* const depEdge = routable->getDepartEdge();
631 bulkVehs[depEdge->getNumericalID()].push_back(routable);
632 RORoutable* const first = bulkVehs[depEdge->getNumericalID()].front();
633 if (first->getMaxSpeed() != routable->getMaxSpeed()) {
634 WRITE_WARNINGF(TL("Bulking different maximum speeds ('%' and '%') may lead to suboptimal routes."), first->getID(), routable->getID());
635 }
636 if (first->getVClass() != routable->getVClass()) {
637 WRITE_WARNINGF(TL("Bulking different vehicle classes ('%' and '%') may lead to invalid routes."), first->getID(), routable->getID());
638 }
639 }
640 }
641#ifdef HAVE_FOX
642 int workerIndex = 0;
643#endif
644 for (std::map<const int, std::vector<RORoutable*> >::const_iterator i = bulkVehs.begin(); i != bulkVehs.end(); ++i) {
645#ifdef HAVE_FOX
646 if (myThreadPool.size() > 0) {
647 bool bulk = true;
648 for (RORoutable* const r : i->second) {
649 myThreadPool.add(new RoutingTask(r, removeLoops, myErrorHandler), workerIndex);
650 if (bulk) {
651 myThreadPool.add(new BulkmodeTask(true), workerIndex);
652 bulk = false;
653 }
654 }
655 myThreadPool.add(new BulkmodeTask(false), workerIndex);
656 workerIndex++;
657 if (workerIndex == (int)myThreadPool.size()) {
658 workerIndex = 0;
659 }
660 continue;
661 }
662#endif
663 for (RORoutable* const r : i->second) {
664 r->computeRoute(provider, removeLoops, myErrorHandler);
665 provider.setBulkMode(true);
666 }
667 provider.setBulkMode(false);
668 }
669}
670
671
674 SUMOTime time) {
675 MsgHandler* mh = (options.getBool("ignore-errors") ?
677 if (myHaveActiveFlows) {
678 checkFlows(time, mh);
679 }
680 SUMOTime lastTime = -1;
681 const bool removeLoops = options.getBool("remove-loops");
682#ifdef HAVE_FOX
683 const int maxNumThreads = options.getInt("routing-threads");
684#endif
685 if (myRoutables.size() != 0) {
686 if (options.getBool("bulk-routing")) {
687#ifdef HAVE_FOX
688 while ((int)myThreadPool.size() < maxNumThreads) {
689 new WorkerThread(myThreadPool, provider);
690 }
691#endif
692 createBulkRouteRequests(provider, time, removeLoops);
693 } else {
694 for (RoutablesMap::const_iterator i = myRoutables.begin(); i != myRoutables.end(); ++i) {
695 if (i->first >= time) {
696 break;
697 }
698 for (RORoutable* const routable : i->second) {
699#ifdef HAVE_FOX
700 // add task
701 if (maxNumThreads > 0) {
702 const int numThreads = (int)myThreadPool.size();
703 if (numThreads == 0) {
704 // This is the very first routing. Since at least the CHRouter needs initialization
705 // before it gets cloned, we do not do this in parallel
706 routable->computeRoute(provider, removeLoops, myErrorHandler);
707 new WorkerThread(myThreadPool, provider);
708 } else {
709 // add thread if necessary
710 if (numThreads < maxNumThreads && myThreadPool.isFull()) {
711 new WorkerThread(myThreadPool, provider);
712 }
713 myThreadPool.add(new RoutingTask(routable, removeLoops, myErrorHandler));
714 }
715 continue;
716 }
717#endif
718 routable->computeRoute(provider, removeLoops, myErrorHandler);
719 }
720 }
721 }
722#ifdef HAVE_FOX
723 myThreadPool.waitAll();
724#endif
725 }
726 const double scale = options.exists("scale-suffix") ? options.getFloat("scale") : 1;
727 // write all vehicles (and additional structures)
728 while (myRoutables.size() != 0 || myContainers.size() != 0) {
729 // get the next vehicle, person or container
730 RoutablesMap::iterator routables = myRoutables.begin();
731 const SUMOTime routableTime = routables == myRoutables.end() ? SUMOTime_MAX : routables->first;
732 ContainerMap::iterator container = myContainers.begin();
733 const SUMOTime containerTime = container == myContainers.end() ? SUMOTime_MAX : container->first;
734 // check whether it shall not yet be computed
735 if (routableTime >= time && containerTime >= time) {
736 lastTime = MIN2(routableTime, containerTime);
737 break;
738 }
739 const SUMOTime minTime = MIN2(routableTime, containerTime);
740 if (routableTime == minTime) {
741 // check whether to print the output
742 if (lastTime != routableTime && lastTime != -1) {
743 // report writing progress
744 if (options.getInt("stats-period") >= 0 && ((int)routableTime % options.getInt("stats-period")) == 0) {
745 WRITE_MESSAGE("Read: " + toString(myVehIDs.size()) + ", Discarded: " + toString(myDiscardedRouteNo) + ", Written: " + toString(myWrittenRouteNo));
746 }
747 }
748 lastTime = routableTime;
749 for (const RORoutable* const r : routables->second) {
750 // ok, check whether it has been routed
751 if (r->getRoutingSuccess()) {
752 // write the route
753 int quota = getScalingQuota(scale, myWrittenRouteNo);
754 r->write(myRoutesOutput, myRouteAlternativesOutput, myTypesOutput, options, quota);
756 } else {
758 }
759 // we need to keep individual public transport vehicles but not the flows
760 if (!r->isPublicTransport() || r->isPartOfFlow()) {
761 // delete routes and the vehicle
762 const ROVehicle* const veh = dynamic_cast<const ROVehicle*>(r);
763 if (veh != nullptr && veh->getRouteDefinition()->getID()[0] == '!') {
764 if (r->isPartOfFlow() || !myRoutes.remove(veh->getRouteDefinition()->getID())) {
765 delete veh->getRouteDefinition();
766 }
767 }
768 delete r;
769 }
770 }
771 myRoutables.erase(routables);
772 }
773 if (containerTime == minTime) {
774 myRoutesOutput->writePreformattedTag(container->second);
775 if (myRouteAlternativesOutput != nullptr) {
777 }
778 myContainers.erase(container);
779 }
780 }
781 return lastTime;
782}
783
784
785bool
787 return myRoutables.size() > 0 || (myFlows.size() > 0 && myHaveActiveFlows) || myContainers.size() > 0;
788}
789
790
791int
793 return myEdges.size();
794}
795
796
797int
801
802
803ROEdge*
804RONet::getEdgeForLaneID(const std::string& laneID) const {
806}
807
808
809ROLane*
810RONet::getLane(const std::string& laneID) const {
811 int laneIndex = SUMOXMLDefinitions::getIndexFromLane(laneID);
812 return getEdgeForLaneID(laneID)->getLanes()[laneIndex];
813}
814
815
816void
818 double taxiWait = STEPS2TIME(string2time(OptionsCont::getOptions().getString("persontrip.taxi.waiting-time")));
819 for (const auto& stopType : myInstance->myStoppingPlaces) {
820 // add access to all stopping places
821 const SumoXMLTag element = stopType.first;
822 for (const auto& stop : stopType.second) {
823 router.getNetwork()->addAccess(stop.first, myInstance->getEdgeForLaneID(stop.second->lane),
824 stop.second->startPos, stop.second->endPos, 0., element, false, taxiWait);
825 // add access to all public transport stops
826 if (element == SUMO_TAG_BUS_STOP) {
827 for (const auto& a : stop.second->accessPos) {
828 router.getNetwork()->addAccess(stop.first, myInstance->getEdgeForLaneID(std::get<0>(a)),
829 std::get<1>(a), std::get<1>(a), std::get<2>(a), SUMO_TAG_BUS_STOP, true, taxiWait);
830 }
831 }
832 }
833 }
834 // fill the public transport router with pre-parsed public transport lines
835 for (const auto& i : myInstance->myFlows) {
836 if (i.second->line != "") {
837 const RORouteDef* const route = myInstance->getRouteDef(i.second->routeid);
838 const StopParVector* addStops = nullptr;
839 if (route != nullptr && route->getFirstRoute() != nullptr) {
840 addStops = &route->getFirstRoute()->getStops();
841 }
842 router.getNetwork()->addSchedule(*i.second, addStops);
843 }
844 }
845 for (const RORoutable* const veh : myInstance->myPTVehicles) {
846 // add single vehicles with line attribute which are not part of a flow
847 // no need to add route stops here, they have been added to the vehicle before
848 router.getNetwork()->addSchedule(veh->getParameter());
849 }
850 // add access to transfer from walking to taxi-use
852 for (const ROEdge* edge : ROEdge::getAllEdges()) {
853 if ((edge->getPermissions() & SVC_PEDESTRIAN) != 0 && (edge->getPermissions() & SVC_TAXI) != 0) {
854 router.getNetwork()->addCarAccess(edge, SVC_TAXI, taxiWait);
855 }
856 }
857 }
858}
859
860
861bool
863 return myHavePermissions;
864}
865
866
867void
871
872bool
874 for (const auto& item : myEdges) {
875 if (item.second->hasStoredEffort()) {
876 return true;
877 }
878 }
879 return false;
880}
881
882const std::string
883RONet::getStoppingPlaceName(const std::string& id) const {
884 for (const auto& mapItem : myStoppingPlaces) {
885 SUMOVehicleParameter::Stop* stop = mapItem.second.get(id);
886 if (stop != nullptr) {
887 // see RONetHandler::parseStoppingPlace
888 return stop->busstop;
889 }
890 }
891 return "";
892}
893
894const std::string
895RONet::getStoppingPlaceElement(const std::string& id) const {
896 for (const auto& mapItem : myStoppingPlaces) {
897 SUMOVehicleParameter::Stop* stop = mapItem.second.get(id);
898 if (stop != nullptr) {
899 // see RONetHandler::parseStoppingPlace
900 return stop->actType;
901 }
902 }
904}
905
906
907#ifdef HAVE_FOX
908// ---------------------------------------------------------------------------
909// RONet::RoutingTask-methods
910// ---------------------------------------------------------------------------
911void
912RONet::RoutingTask::run(MFXWorkerThread* context) {
913 myRoutable->computeRoute(*static_cast<WorkerThread*>(context), myRemoveLoops, myErrorHandler);
914}
915#endif
916
917
918/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ TAXI_PICKUP_ANYWHERE
taxi customer may be picked up anywhere
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:288
#define WRITE_ERRORF(...)
Definition MsgHandler.h:297
#define WRITE_MESSAGE(msg)
Definition MsgHandler.h:289
#define TL(string)
Definition MsgHandler.h:305
#define TLF(string,...)
Definition MsgHandler.h:307
SUMOTime DELTA_T
Definition SUMOTime.cpp:38
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
#define STEPS2TIME(x)
Definition SUMOTime.h:55
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define TS
Definition SUMOTime.h:42
const long long int VTYPEPARS_VEHICLECLASS_SET
const std::string DEFAULT_TAXITYPE_ID
const std::string DEFAULT_RAILTYPE_ID
const std::string DEFAULT_PEDTYPE_ID
const std::string DEFAULT_VTYPE_ID
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_RAIL
vehicle is a not electrified rail
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_TAXI
vehicle is a taxi
@ SVC_PEDESTRIAN
pedestrian
const std::string DEFAULT_BIKETYPE_ID
std::vector< SUMOVehicleParameter::Stop > StopParVector
@ TRIGGERED
The departure is person triggered.
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_ID
int getScalingQuota(double frac, int loaded)
Returns the number of instances of the current object that shall be emitted given the number of loade...
Definition StdDefs.cpp:62
T MIN2(T a, T b)
Definition StdDefs.h:76
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
void addCarAccess(const E *edge, SUMOVehicleClass svc, double traveltime)
Adds access edges for transfering from walking to vehicle use.
void addAccess(const std::string &stopId, const E *stopEdge, const double startPos, const double endPos, const double length, const SumoXMLTag category, bool isAccess, double taxiWait)
Adds access edges for stopping places to the intermodal network.
void addSchedule(const SUMOVehicleParameter &pars, const StopParVector *addStops=nullptr)
Network * getNetwork() const
void writeWeights(OutputDevice &dev)
int getCarWalkTransfer() const
void writeNetwork(OutputDevice &dev)
A thread repeatingly calculating incoming tasks.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
const std::string & getID() const
Returns the id.
Definition Named.h:74
T get(const std::string &id) const
Retrieves an item.
int size() const
Returns the number of stored items within the container.
bool remove(const std::string &id, const bool del=true)
Removes an item.
bool add(const std::string &id, T item)
Adds an item.
A storage for options typed value containers)
Definition OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & writePreformattedTag(const std::string &val)
writes a preformatted tag to the device but ensures that any pending tags are closed
void close()
Closes the device and removes it from the dictionary.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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.
virtual bool isNull()
returns the information whether the device will discard all output
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >(), bool includeConfig=true)
Writes an XML header with optional configuration.
Interface for building instances of router-edges.
virtual ROEdge * buildEdge(const std::string &name, RONode *from, RONode *to, const int priority, const std::string &type)=0
Builds an edge with the given name.
A basic edge for routing applications.
Definition ROEdge.h:72
int getNumericalID() const
Returns the index (numeric id) of the edge.
Definition ROEdge.h:231
void setFunction(SumoXMLEdgeFunc func)
Sets the function of the edge.
Definition ROEdge.h:117
bool isInternal() const
return whether this edge is an internal edge
Definition ROEdge.h:159
void setOtherTazConnector(const ROEdge *edge)
Definition ROEdge.h:177
const std::vector< ROLane * > & getLanes() const
Returns this edge's lanes.
Definition ROEdge.h:534
virtual void addSuccessor(ROEdge *s, ROEdge *via=nullptr, std::string dir="")
Adds information about a connected edge.
Definition ROEdge.cpp:134
static const ROEdgeVector & getAllEdges()
Returns all ROEdges.
Definition ROEdge.cpp:375
A single lane the router may use.
Definition ROLane.h:48
The router's network representation.
Definition RONet.h:63
void createBulkRouteRequests(const RORouterProvider &provider, const SUMOTime time, const bool removeLoops)
Definition RONet.cpp:623
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
Definition RONet.cpp:361
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition RONet.cpp:56
int myNumInternalEdges
The number of internal edges in the dictionary.
Definition RONet.h:578
bool myDefaultPedTypeMayBeDeleted
Whether the default pedestrian type was already used or can still be replaced.
Definition RONet.h:517
void setPermissionsFound()
Definition RONet.cpp:868
bool myDefaultRailTypeMayBeDeleted
Whether the default rail type was already used or can still be replaced.
Definition RONet.h:526
bool myDefaultVTypeMayBeDeleted
Whether the default vehicle type was already used or can still be replaced.
Definition RONet.h:514
void checkFlows(SUMOTime time, MsgHandler *errorHandler)
Definition RONet.cpp:537
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:150
ContainerMap myContainers
Definition RONet.h:542
std::set< std::string > myPersonIDs
Known person ids.
Definition RONet.h:494
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:551
bool addRouteDef(RORouteDef *def)
Definition RONet.cpp:286
void addStoppingPlace(const std::string &id, const SumoXMLTag category, SUMOVehicleParameter::Stop *stop)
Definition RONet.cpp:277
bool knowsVehicle(const std::string &id) const
returns whether a vehicle with the given id was already loaded
Definition RONet.cpp:485
void cleanup()
closes the file output for computed routes and deletes associated threads if necessary
Definition RONet.cpp:337
bool myHaveActiveFlows
whether any flows are still active
Definition RONet.h:538
std::map< std::string, SUMOTime > myVehIDs
Known vehicle ids and their departure.
Definition RONet.h:491
void openOutput(const OptionsCont &options)
Opens the output for computed routes.
Definition RONet.cpp:292
NamedObjectCont< SUMOVehicleParameter * > myFlows
Known flows.
Definition RONet.h:535
OutputDevice * myRouteAlternativesOutput
The file to write the computed route alternatives into.
Definition RONet.h:557
bool myDefaultBikeTypeMayBeDeleted
Whether the default bicycle type was already used or can still be replaced.
Definition RONet.h:520
RoutablesMap myRoutables
Known routables.
Definition RONet.h:532
int getInternalEdgeNumber() const
Returns the number of internal edges the network contains.
Definition RONet.cpp:798
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
Definition RONet.cpp:463
SUMOTime getDeparture(const std::string &vehID) const
returns departure time for the given vehicle id
Definition RONet.cpp:490
bool myHasBidiEdges
whether the network contains bidirectional railway edges
Definition RONet.h:590
bool addDistrictEdge(const std::string tazID, const std::string edgeID, const bool isSource)
Definition RONet.cpp:197
MsgHandler * myErrorHandler
handler for ignorable error messages
Definition RONet.h:581
void writeIntermodal(const OptionsCont &options, ROIntermodalRouter &router) const
Writes the intermodal network and weights if requested.
Definition RONet.cpp:318
RONet()
Constructor.
Definition RONet.cpp:64
NamedObjectCont< RONode * > myNodes
Known nodes.
Definition RONet.h:497
const std::string getStoppingPlaceElement(const std::string &id) const
return the element name for the given stopping place id
Definition RONet.cpp:895
void addContainer(const SUMOTime depart, const std::string desc)
Definition RONet.cpp:531
static void adaptIntermodalRouter(ROIntermodalRouter &router)
Definition RONet.cpp:817
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition RONet.h:161
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition RONet.cpp:144
NamedObjectCont< RORouteDef * > myRoutes
Known routes.
Definition RONet.h:529
bool furtherStored()
Returns the information whether further vehicles, persons or containers are stored.
Definition RONet.cpp:786
bool checkVType(const std::string &id)
Checks whether the vehicle type (distribution) may be added.
Definition RONet.cpp:393
OutputDevice * myRoutesOutput
The file to write the computed routes into.
Definition RONet.h:554
bool addPerson(ROPerson *person)
Definition RONet.cpp:519
int myWrittenRouteNo
The number of written routes.
Definition RONet.h:569
static RONet * myInstance
Unique instance of RONet.
Definition RONet.h:488
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
Definition RONet.h:322
SUMOTime saveAndRemoveRoutesUntil(OptionsCont &options, const RORouterProvider &provider, SUMOTime time)
Computes routes described by their definitions and saves them.
Definition RONet.cpp:673
virtual bool addEdge(ROEdge *edge)
Definition RONet.cpp:160
bool myDefaultTaxiTypeMayBeDeleted
Whether the default taxi type was already used or can still be replaced.
Definition RONet.h:523
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition RONet.h:575
std::map< SumoXMLTag, NamedObjectCont< SUMOVehicleParameter::Stop * > > myStoppingPlaces
Known bus / train / container stops and parking areas.
Definition RONet.h:503
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
Definition RONet.cpp:439
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition RONet.h:572
bool hasPermissions() const
Definition RONet.cpp:862
void setBidiEdges(const std::map< ROEdge *, std::string > &bidiMap)
add a taz for every junction unless a taz with the same id already exists
Definition RONet.cpp:255
ROLane * getLane(const std::string &laneID) const
Retrieves a lane rom the network given its id.
Definition RONet.cpp:810
int myDiscardedRouteNo
The number of discarded routes.
Definition RONet.h:566
VTypeDistDictType myVTypeDistDict
A distribution of vehicle types (probability->vehicle type)
Definition RONet.h:511
std::vector< const RORoutable * > myPTVehicles
vehicles to keep for public transport routing
Definition RONet.h:545
NamedObjectCont< ROEdge * > myEdges
Known edges.
Definition RONet.h:500
void addNode(RONode *node)
Definition RONet.cpp:268
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
Definition RONet.cpp:452
void addJunctionTaz(ROAbstractEdgeBuilder &eb)
add a taz for every junction unless a taz with the same id already exists
Definition RONet.cpp:219
OutputDevice * myTypesOutput
The file to write the vehicle types into.
Definition RONet.h:560
const bool myDoPTRouting
whether to calculate routes for public transport
Definition RONet.h:587
const bool myKeepVTypeDist
whether to keep the vtype distribution in output
Definition RONet.h:584
virtual ~RONet()
Destructor.
Definition RONet.cpp:113
const std::string getStoppingPlaceName(const std::string &id) const
return the name for the given stopping place id
Definition RONet.cpp:883
std::map< std::string, std::vector< SUMOTime > > myDepartures
Departure times for randomized flows.
Definition RONet.h:548
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition RONet.cpp:792
ROEdge * getEdgeForLaneID(const std::string &laneID) const
Retrieves an edge from the network when the lane id is given.
Definition RONet.cpp:804
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
Definition RONet.cpp:501
bool hasLoadedEffort() const
whether efforts were loaded from file
Definition RONet.cpp:873
NamedObjectCont< SUMOVTypeParameter * > myVehicleTypes
Known vehicle types.
Definition RONet.h:506
bool addDistrict(const std::string id, ROEdge *source, ROEdge *sink)
Definition RONet.cpp:174
Base class for nodes used by the router.
Definition RONode.h:46
const ConstROEdgeVector & getOutgoing() const
Definition RONode.h:76
const ConstROEdgeVector & getIncoming() const
Definition RONode.h:72
A person as used by router.
Definition ROPerson.h:50
A routable thing such as a vehicle or person.
Definition RORoutable.h:52
SUMOVehicleClass getVClass() const
Definition RORoutable.h:109
bool isPublicTransport() const
Definition RORoutable.h:129
bool isPartOfFlow() const
Definition RORoutable.h:133
SUMOTime getDepart() const
Returns the time the vehicle starts at, -1 for triggered vehicles.
Definition RORoutable.h:100
const std::string & getID() const
Returns the id of the routable.
Definition RORoutable.h:91
const SUMOVehicleParameter & getParameter() const
Returns the definition of the vehicle / person parameter.
Definition RORoutable.h:71
double getMaxSpeed() const
Returns the vehicle's maximum speed.
Definition RORoutable.h:121
Base class for a vehicle's route definition.
Definition RORouteDef.h:53
const RORoute * getFirstRoute() const
Definition RORouteDef.h:100
RORouteDef * copy(const std::string &id, const SUMOTime stopOffset) const
Returns a deep copy of the route definition.
const StopParVector & getStops() const
Returns the list of stops this route contains.
Definition RORoute.h:187
A vehicle as used by router.
Definition ROVehicle.h:50
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at, 0 for triggered vehicles.
Definition ROVehicle.h:92
RORouteDef * getRouteDefinition() const
Returns the definition of the route the vehicle takes.
Definition ROVehicle.h:73
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Represents a generic random distribution.
void setBulkMode(const bool mode) const
Structure representing possible vehicle parameter.
long long int parametersSet
Information for the router which parameter were set.
bool onlyReferenced
Information whether this is a type-stub, being only referenced but not defined (needed by routers)
std::string id
The vehicle type's id.
Definition of vehicle stop (position and duration)
std::string actType
act Type (only used by Persons) (used by netedit)
std::string busstop
(Optional) bus stop if one is assigned to the stop
Structure representing possible vehicle parameter.
double repetitionProbability
The probability for emitting a vehicle per second.
void incrementFlow(double scale, SumoRNG *rng=nullptr)
increment flow
std::string vtypeid
The vehicle's type id.
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
int repetitionsDone
The number of times the vehicle was already inserted.
SUMOTime repetitionTotalOffset
The offset between depart and the time for the next vehicle insertions.
SUMOTime repetitionEnd
The time at which the flow ends (only needed when using repetitionProbability)
std::string routeid
The vehicle's route id.
std::string id
The vehicle's id.
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
std::string line
The vehicle's line (mainly for public transport)
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
static int getIndexFromLane(const std::string laneID)
return lane index when given the lane ID