Eclipse SUMO - Simulation of Urban MObility
MSNet.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-2023 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/****************************************************************************/
26// The simulated network and simulation perfomer
27/****************************************************************************/
28#include <config.h>
29
30#ifdef HAVE_VERSION_H
31#include <version.h>
32#endif
33
34#include <string>
35#include <iostream>
36#include <sstream>
37#include <typeinfo>
38#include <algorithm>
39#include <cassert>
40#include <vector>
41#include <ctime>
42
43#ifdef HAVE_FOX
45#endif
63#include <utils/xml/XMLSubSys.h>
65#include <libsumo/Helper.h>
66#include <libsumo/Simulation.h>
67#include <mesosim/MELoop.h>
68#include <mesosim/MESegment.h>
103#include <netload/NLBuilder.h>
104
105#include "MSEdgeControl.h"
106#include "MSJunctionControl.h"
107#include "MSInsertionControl.h"
109#include "MSEventControl.h"
110#include "MSEdge.h"
111#include "MSJunction.h"
112#include "MSJunctionLogic.h"
113#include "MSLane.h"
114#include "MSVehicleControl.h"
115#include "MSVehicleTransfer.h"
116#include "MSRoute.h"
117#include "MSGlobals.h"
118#include "MSEdgeWeightsStorage.h"
119#include "MSStateHandler.h"
120#include "MSFrame.h"
121#include "MSParkingArea.h"
122#include "MSStoppingPlace.h"
123#include "MSNet.h"
124
125
126// ===========================================================================
127// debug constants
128// ===========================================================================
129//#define DEBUG_SIMSTEP
130
131
132// ===========================================================================
133// static member definitions
134// ===========================================================================
135MSNet* MSNet::myInstance = nullptr;
136
137const std::string MSNet::STAGE_EVENTS("events");
138const std::string MSNet::STAGE_MOVEMENTS("move");
139const std::string MSNet::STAGE_LANECHANGE("laneChange");
140const std::string MSNet::STAGE_INSERTIONS("insertion");
141const std::string MSNet::STAGE_REMOTECONTROL("remoteControl");
142
144
145// ===========================================================================
146// static member method definitions
147// ===========================================================================
148double
149MSNet::getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t) {
150 double value;
151 const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
152 if (veh != nullptr && veh->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
153 return value;
154 }
156 return value;
157 }
158 return 0;
159}
160
161
162double
163MSNet::getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, double t) {
164 double value;
165 const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
166 if (veh != nullptr && veh->getWeightsStorage().retrieveExistingTravelTime(e, t, value)) {
167 return value;
168 }
170 return value;
171 }
172 if (veh != nullptr && veh->getBaseInfluencer() != nullptr && veh->getBaseInfluencer()->getRoutingMode() == libsumo::ROUTING_MODE_AGGREGATED_CUSTOM) {
173 return MSRoutingEngine::getEffortExtra(e, v, t);
174 }
175 return e->getMinimumTravelTime(v);
176}
177
178
179// ---------------------------------------------------------------------------
180// MSNet - methods
181// ---------------------------------------------------------------------------
182MSNet*
184 if (myInstance != nullptr) {
185 return myInstance;
186 }
187 throw ProcessError(TL("A network was not yet constructed."));
188}
189
190void
194 }
195}
196
197void
201 }
202}
203
204
205MSNet::MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
206 MSEventControl* endOfTimestepEvents,
207 MSEventControl* insertionEvents,
208 ShapeContainer* shapeCont):
209 myAmInterrupted(false),
210 myVehiclesMoved(0),
211 myPersonsMoved(0),
212 myHavePermissions(false),
213 myHasInternalLinks(false),
214 myJunctionHigherSpeeds(false),
215 myHasElevation(false),
216 myHasPedestrianNetwork(false),
217 myHasBidiEdges(false),
218 myEdgeDataEndTime(-1),
219 myDynamicShapeUpdater(nullptr) {
220 if (myInstance != nullptr) {
221 throw ProcessError(TL("A network was already constructed."));
222 }
224 myStep = string2time(oc.getString("begin"));
225 myMaxTeleports = oc.getInt("max-num-teleports");
226 myLogExecutionTime = !oc.getBool("no-duration-log");
227 myLogStepNumber = !oc.getBool("no-step-log");
228 myLogStepPeriod = oc.getInt("step-log.period");
229 myInserter = new MSInsertionControl(*vc, string2time(oc.getString("max-depart-delay")), oc.getBool("eager-insert"), oc.getInt("max-num-vehicles"),
230 string2time(oc.getString("random-depart-offset")));
231 myVehicleControl = vc;
233 myEdges = nullptr;
234 myJunctions = nullptr;
235 myRouteLoaders = nullptr;
236 myLogics = nullptr;
237 myPersonControl = nullptr;
238 myContainerControl = nullptr;
239 myEdgeWeights = nullptr;
240 myShapeContainer = shapeCont == nullptr ? new ShapeContainer() : shapeCont;
241
242 myBeginOfTimestepEvents = beginOfTimestepEvents;
243 myEndOfTimestepEvents = endOfTimestepEvents;
244 myInsertionEvents = insertionEvents;
245 myLanesRTree.first = false;
246
248 MSGlobals::gMesoNet = new MELoop(string2time(oc.getString("meso-recheck")));
249 }
250 myInstance = this;
251 initStatic();
252}
253
254
255void
257 SUMORouteLoaderControl* routeLoaders,
258 MSTLLogicControl* tlc,
259 std::vector<SUMOTime> stateDumpTimes,
260 std::vector<std::string> stateDumpFiles,
261 bool hasInternalLinks,
262 bool junctionHigherSpeeds,
263 const MMVersion& version) {
264 myEdges = edges;
265 myJunctions = junctions;
266 myRouteLoaders = routeLoaders;
267 myLogics = tlc;
268 // save the time the network state shall be saved at
269 myStateDumpTimes = stateDumpTimes;
270 myStateDumpFiles = stateDumpFiles;
271 myStateDumpPeriod = string2time(oc.getString("save-state.period"));
272 myStateDumpPrefix = oc.getString("save-state.prefix");
273 myStateDumpSuffix = oc.getString("save-state.suffix");
274
275 // initialise performance computation
277 myTraCIMillis = 0;
279 myJunctionHigherSpeeds = junctionHigherSpeeds;
283 myVersion = version;
286 throw ProcessError(TL("Option weights.separate-turns is only supported when simulating with internal lanes"));
287 }
288}
289
290
293 // delete controls
294 delete myJunctions;
295 delete myDetectorControl;
296 // delete mean data
297 delete myEdges;
298 delete myInserter;
299 delete myLogics;
300 delete myRouteLoaders;
301 if (myPersonControl != nullptr) {
302 delete myPersonControl;
303 myPersonControl = nullptr; // just to have that clear for later cleanups
304 }
305 if (myContainerControl != nullptr) {
306 delete myContainerControl;
307 myContainerControl = nullptr; // just to have that clear for later cleanups
308 }
309 delete myVehicleControl; // must happen after deleting transportables
310 // delete events late so that vehicles can get rid of references first
312 myBeginOfTimestepEvents = nullptr;
314 myEndOfTimestepEvents = nullptr;
315 delete myInsertionEvents;
316 myInsertionEvents = nullptr;
317 delete myShapeContainer;
318 delete myEdgeWeights;
319 for (auto& router : myRouterTT) {
320 delete router.second;
321 }
322 myRouterTT.clear();
323 for (auto& router : myRouterEffort) {
324 delete router.second;
325 }
326 myRouterEffort.clear();
327 for (auto& router : myPedestrianRouter) {
328 delete router.second;
329 }
330 myPedestrianRouter.clear();
331 for (auto& router : myIntermodalRouter) {
332 delete router.second;
333 }
334 myIntermodalRouter.clear();
335 myLanesRTree.second.RemoveAll();
336 clearAll();
338 delete MSGlobals::gMesoNet;
339 }
340 myInstance = nullptr;
341}
342
343
344void
345MSNet::addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed) {
346 myRestrictions[id][svc] = speed;
347}
348
349
350const std::map<SUMOVehicleClass, double>*
351MSNet::getRestrictions(const std::string& id) const {
352 std::map<std::string, std::map<SUMOVehicleClass, double> >::const_iterator i = myRestrictions.find(id);
353 if (i == myRestrictions.end()) {
354 return nullptr;
355 }
356 return &i->second;
357}
358
359void
360MSNet::addMesoType(const std::string& typeID, const MESegment::MesoEdgeType& edgeType) {
361 myMesoEdgeTypes[typeID] = edgeType;
362}
363
365MSNet::getMesoType(const std::string& typeID) {
366 if (myMesoEdgeTypes.count(typeID) == 0) {
367 // init defaults
370 edgeType.tauff = string2time(oc.getString("meso-tauff"));
371 edgeType.taufj = string2time(oc.getString("meso-taufj"));
372 edgeType.taujf = string2time(oc.getString("meso-taujf"));
373 edgeType.taujj = string2time(oc.getString("meso-taujj"));
374 edgeType.jamThreshold = oc.getFloat("meso-jam-threshold");
375 edgeType.junctionControl = oc.getBool("meso-junction-control");
376 edgeType.tlsPenalty = oc.getFloat("meso-tls-penalty");
377 edgeType.tlsFlowPenalty = oc.getFloat("meso-tls-flow-penalty");
378 edgeType.minorPenalty = string2time(oc.getString("meso-minor-penalty"));
379 edgeType.overtaking = oc.getBool("meso-overtaking");
380 myMesoEdgeTypes[typeID] = edgeType;
381 }
382 return myMesoEdgeTypes[typeID];
383}
384
387 // report the begin when wished
388 WRITE_MESSAGEF(TL("Simulation version % started with time: %."), VERSION_STRING, time2string(start));
389 // the simulation loop
391 // state loading may have changed the start time so we need to reinit it
392 myStep = start;
393 int numSteps = 0;
394 bool doStepLog = false;
395 while (state == SIMSTATE_RUNNING) {
396 doStepLog = myLogStepNumber && (numSteps % myLogStepPeriod == 0);
397 if (doStepLog) {
399 }
401 if (doStepLog) {
403 }
404 state = adaptToState(simulationState(stop));
405#ifdef DEBUG_SIMSTEP
406 std::cout << SIMTIME << " MSNet::simulate(" << start << ", " << stop << ")"
407 << "\n simulation state: " << getStateMessage(state)
408 << std::endl;
409#endif
410 numSteps++;
411 }
412 if (myLogStepNumber && !doStepLog) {
413 // ensure some output on the last step
416 }
417 // exit simulation loop
418 if (myLogStepNumber) {
419 // start new line for final verbose output
420 std::cout << "\n";
421 }
422 closeSimulation(start, getStateMessage(state));
423 return state;
424}
425
426
427void
430}
431
432
433const std::string
434MSNet::generateStatistics(const SUMOTime start, const long now) {
435 std::ostringstream msg;
436 if (myLogExecutionTime) {
437 const long duration = now - mySimBeginMillis;
438 // print performance notice
439 msg << "Performance: " << "\n" << " Duration: " << elapsedMs2string(duration) << "\n";
440 if (duration != 0) {
441 if (TraCIServer::getInstance() != nullptr) {
442 msg << " TraCI-Duration: " << elapsedMs2string(myTraCIMillis) << "\n";
443 }
444 msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (double)duration) << "\n";
445 msg.setf(std::ios::fixed, std::ios::floatfield); // use decimal format
446 msg.setf(std::ios::showpoint); // print decimal point
447 msg << " UPS: " << ((double)myVehiclesMoved / ((double)duration / 1000)) << "\n";
448 if (myPersonsMoved > 0) {
449 msg << " UPS-Persons: " << ((double)myPersonsMoved / ((double)duration / 1000)) << "\n";
450 }
451 }
452 // print vehicle statistics
453 const std::string discardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ?
454 " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : "");
455 msg << "Vehicles: " << "\n"
456 << " Inserted: " << myVehicleControl->getDepartedVehicleNo() << discardNotice << "\n"
457 << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n"
458 << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n";
459
461 // print optional teleport statistics
462 std::vector<std::string> reasons;
464 reasons.push_back("Collisions: " + toString(myVehicleControl->getCollisionCount()));
465 }
467 reasons.push_back("Jam: " + toString(myVehicleControl->getTeleportsJam()));
468 }
470 reasons.push_back("Yield: " + toString(myVehicleControl->getTeleportsYield()));
471 }
473 reasons.push_back("Wrong Lane: " + toString(myVehicleControl->getTeleportsWrongLane()));
474 }
475 msg << " Teleports: " << myVehicleControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
476 }
478 msg << " Emergency Stops: " << myVehicleControl->getEmergencyStops() << "\n";
479 }
480 if (myPersonControl != nullptr && myPersonControl->getLoadedNumber() > 0) {
481 msg << "Persons: " << "\n"
482 << " Inserted: " << myPersonControl->getLoadedNumber() << "\n"
483 << " Running: " << myPersonControl->getRunningNumber() << "\n";
484 if (myPersonControl->getJammedNumber() > 0) {
485 msg << " Jammed: " << myPersonControl->getJammedNumber() << "\n";
486 }
488 std::vector<std::string> reasons;
490 reasons.push_back("Abort Wait: " + toString(myPersonControl->getTeleportsAbortWait()));
491 }
493 reasons.push_back("Wrong Dest: " + toString(myPersonControl->getTeleportsWrongDest()));
494 }
495 msg << " Teleports: " << myPersonControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
496 }
497 }
498 if (myContainerControl != nullptr && myContainerControl->getLoadedNumber() > 0) {
499 msg << "Containers: " << "\n"
500 << " Inserted: " << myContainerControl->getLoadedNumber() << "\n"
501 << " Running: " << myContainerControl->getRunningNumber() << "\n";
503 msg << " Jammed: " << myContainerControl->getJammedNumber() << "\n";
504 }
506 std::vector<std::string> reasons;
508 reasons.push_back("Abort Wait: " + toString(myContainerControl->getTeleportsAbortWait()));
509 }
511 reasons.push_back("Wrong Dest: " + toString(myContainerControl->getTeleportsWrongDest()));
512 }
513 msg << " Teleports: " << myContainerControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
514 }
515 }
516 }
517 if (OptionsCont::getOptions().getBool("duration-log.statistics")) {
519 }
520 return msg.str();
521}
522
523
524void
526 OutputDevice& od = OutputDevice::getDeviceByOption("collision-output");
527 for (const auto& item : myCollisions) {
528 for (const auto& c : item.second) {
529 od.openTag("collision");
531 od.writeAttr("type", c.type);
532 od.writeAttr("lane", c.lane->getID());
533 od.writeAttr("pos", c.pos);
534 od.writeAttr("collider", item.first);
535 od.writeAttr("victim", c.victim);
536 od.writeAttr("colliderType", c.colliderType);
537 od.writeAttr("victimType", c.victimType);
538 od.writeAttr("colliderSpeed", c.colliderSpeed);
539 od.writeAttr("victimSpeed", c.victimSpeed);
540 od.closeTag();
541 }
542 }
543}
544
545
546void
547MSNet::writeStatistics(const SUMOTime start, const long now) const {
548 const long duration = now - mySimBeginMillis;
549 OutputDevice& od = OutputDevice::getDeviceByOption("statistic-output");
550 od.openTag("performance");
551 od.writeAttr("clockBegin", time2string(mySimBeginMillis));
552 od.writeAttr("clockEnd", time2string(now));
553 od.writeAttr("clockDuration", time2string(duration));
554 od.writeAttr("traciDuration", time2string(myTraCIMillis));
555 od.writeAttr("realTimeFactor", duration != 0 ? (double)(myStep - start) / (double)duration : -1);
556 od.writeAttr("vehicleUpdatesPerSecond", duration != 0 ? (double)myVehiclesMoved / ((double)duration / 1000) : -1);
557 od.writeAttr("personUpdatesPerSecond", duration != 0 ? (double)myPersonsMoved / ((double)duration / 1000) : -1);
558 od.writeAttr("begin", time2string(start));
559 od.writeAttr("end", time2string(myStep));
560 od.writeAttr("duration", time2string(myStep - start));
561 od.closeTag();
562 od.openTag("vehicles");
566 od.writeAttr("waiting", myInserter->getWaitingVehicleNo());
567 od.closeTag();
568 od.openTag("teleports");
573 od.closeTag();
574 od.openTag("safety");
575 od.writeAttr("collisions", myVehicleControl->getCollisionCount());
576 od.writeAttr("emergencyStops", myVehicleControl->getEmergencyStops());
577 od.closeTag();
578 od.openTag("persons");
579 od.writeAttr("loaded", myPersonControl != nullptr ? myPersonControl->getLoadedNumber() : 0);
580 od.writeAttr("running", myPersonControl != nullptr ? myPersonControl->getRunningNumber() : 0);
581 od.writeAttr("jammed", myPersonControl != nullptr ? myPersonControl->getJammedNumber() : 0);
582 od.closeTag();
583 od.openTag("personTeleports");
584 od.writeAttr("total", myPersonControl != nullptr ? myPersonControl->getTeleportCount() : 0);
585 od.writeAttr("abortWait", myPersonControl != nullptr ? myPersonControl->getTeleportsAbortWait() : 0);
586 od.writeAttr("wrongDest", myPersonControl != nullptr ? myPersonControl->getTeleportsWrongDest() : 0);
587 od.closeTag();
588 if (OptionsCont::getOptions().isSet("tripinfo-output") || OptionsCont::getOptions().getBool("duration-log.statistics")) {
590 }
591
592}
593
594
595void
597 // summary output
599 const bool hasOutput = oc.isSet("summary-output");
600 const bool hasPersonOutput = oc.isSet("person-summary-output");
601 if (hasOutput || hasPersonOutput) {
602 const SUMOTime period = string2time(oc.getString("summary-output.period"));
603 const SUMOTime begin = string2time(oc.getString("begin"));
604 if (period > 0 && (myStep - begin) % period != 0) {
605 return;
606 }
607 }
608 if (hasOutput) {
609 OutputDevice& od = OutputDevice::getDeviceByOption("summary-output");
610 int departedVehiclesNumber = myVehicleControl->getDepartedVehicleNo();
611 const double meanWaitingTime = departedVehiclesNumber != 0 ? myVehicleControl->getTotalDepartureDelay() / (double) departedVehiclesNumber : -1.;
612 int endedVehicleNumber = myVehicleControl->getEndedVehicleNo();
613 const double meanTravelTime = endedVehicleNumber != 0 ? myVehicleControl->getTotalTravelTime() / (double) endedVehicleNumber : -1.;
614 od.openTag("step");
615 od.writeAttr("time", time2string(myStep));
619 od.writeAttr("waiting", myInserter->getWaitingVehicleNo());
622 od.writeAttr("collisions", myVehicleControl->getCollisionCount());
623 od.writeAttr("teleports", myVehicleControl->getTeleportCount());
626 od.writeAttr("meanWaitingTime", meanWaitingTime);
627 od.writeAttr("meanTravelTime", meanTravelTime);
628 std::pair<double, double> meanSpeed = myVehicleControl->getVehicleMeanSpeeds();
629 od.writeAttr("meanSpeed", meanSpeed.first);
630 od.writeAttr("meanSpeedRelative", meanSpeed.second);
631 if (myLogExecutionTime) {
632 od.writeAttr("duration", mySimStepDuration);
633 }
634 od.closeTag();
635 }
636 if (hasPersonOutput) {
637 OutputDevice& od = OutputDevice::getDeviceByOption("person-summary-output");
639 od.openTag("step");
640 od.writeAttr("time", time2string(myStep));
641 od.writeAttr("loaded", pc.getLoadedNumber());
642 od.writeAttr("inserted", pc.getDepartedNumber());
643 od.writeAttr("walking", pc.getMovingNumber());
644 od.writeAttr("waitingForRide", pc.getWaitingForVehicleNumber());
645 od.writeAttr("riding", pc.getRidingNumber());
646 od.writeAttr("stopping", pc.getWaitingUntilNumber());
647 od.writeAttr("jammed", pc.getJammedNumber());
648 od.writeAttr("ended", pc.getEndedNumber());
649 od.writeAttr("arrived", pc.getArrivedNumber());
650 od.writeAttr("teleports", pc.getTeleportCount());
651 if (myLogExecutionTime) {
652 od.writeAttr("duration", mySimStepDuration);
653 }
654 od.closeTag();
655 }
656}
657
658
659void
660MSNet::closeSimulation(SUMOTime start, const std::string& reason) {
661 // report the end when wished
662 WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
663 if (reason != "") {
664 WRITE_MESSAGE("Reason: " + reason);
665 }
667 if (MSStopOut::active() && OptionsCont::getOptions().getBool("stop-output.write-unfinished")) {
669 }
670 MSDevice_Vehroutes::writePendingOutput(OptionsCont::getOptions().getBool("vehroute-output.write-unfinished"));
671 if (OptionsCont::getOptions().getBool("tripinfo-output.write-unfinished")) {
673 }
674 if (OptionsCont::getOptions().isSet("chargingstations-output")) {
676 }
677 if (OptionsCont::getOptions().isSet("overheadwiresegments-output")) {
679 }
680 if (OptionsCont::getOptions().isSet("substations-output")) {
682 }
683 if (OptionsCont::getOptions().isSet("railsignal-block-output")) {
685 }
686 const long now = SysUtils::getCurrentMillis();
687 if (myLogExecutionTime || OptionsCont::getOptions().getBool("duration-log.statistics")) {
689 }
690 if (OptionsCont::getOptions().isSet("statistic-output")) {
691 writeStatistics(start, now);
692 }
693}
694
695
696void
697MSNet::simulationStep(const bool onlyMove) {
699 postMoveStep();
701 return;
702 }
703#ifdef DEBUG_SIMSTEP
704 std::cout << SIMTIME << ": MSNet::simulationStep() called"
705 << ", myStep = " << myStep
706 << std::endl;
707#endif
709 int lastTraCICmd = 0;
710 if (t != nullptr) {
711 if (myLogExecutionTime) {
713 }
714 lastTraCICmd = t->processCommands(myStep);
715#ifdef DEBUG_SIMSTEP
716 bool loadRequested = !TraCI::getLoadArgs().empty();
717 assert(t->getTargetTime() >= myStep || loadRequested || TraCIServer::wasClosed());
718#endif
719 if (myLogExecutionTime) {
721 }
722 if (TraCIServer::wasClosed() || !t->getLoadArgs().empty()) {
723 return;
724 }
725 }
726#ifdef DEBUG_SIMSTEP
727 std::cout << SIMTIME << ": TraCI target time: " << t->getTargetTime() << std::endl;
728#endif
729 // execute beginOfTimestepEvents
730 if (myLogExecutionTime) {
732 }
733 // simulation state output
734 std::vector<SUMOTime>::iterator timeIt = std::find(myStateDumpTimes.begin(), myStateDumpTimes.end(), myStep);
735 if (timeIt != myStateDumpTimes.end()) {
736 const int dist = (int)distance(myStateDumpTimes.begin(), timeIt);
738 }
739 if (myStateDumpPeriod > 0 && myStep % myStateDumpPeriod == 0) {
740 std::string timeStamp = time2string(myStep);
741 std::replace(timeStamp.begin(), timeStamp.end(), ':', '-');
742 const std::string filename = myStateDumpPrefix + "_" + timeStamp + myStateDumpSuffix;
744 myPeriodicStateFiles.push_back(filename);
745 int keep = OptionsCont::getOptions().getInt("save-state.period.keep");
746 if (keep > 0 && (int)myPeriodicStateFiles.size() > keep) {
747 std::remove(myPeriodicStateFiles.front().c_str());
749 }
750 }
753#ifdef HAVE_FOX
754 MSRoutingEngine::waitForAll();
755#endif
758 }
759 // check whether the tls programs need to be switched
761
764 } else {
765 // assure all lanes with vehicles are 'active'
767
768 // compute safe velocities for all vehicles for the next few lanes
769 // also register ApproachingVehicleInformation for all links
771
772 // register junction approaches based on planned velocities as basis for right-of-way decision
774
775 // decide right-of-way and execute movements
779 }
780
781 // vehicles may change lanes
783
786 }
787 }
788 // flush arrived meso vehicles and micro vehicles that were removed due to collision
790 loadRoutes();
791
792 // persons
795 }
796 // containers
799 }
800 // insert vehicles
803#ifdef HAVE_FOX
804 MSRoutingEngine::waitForAll();
805#endif
808 //myEdges->patchActiveLanes(); // @note required to detect collisions on lanes that were empty before insertion. wasteful?
810 }
812
813 // execute endOfTimestepEvents
815
816 if (myLogExecutionTime) {
818 }
819 if (onlyMove) {
821 return;
822 }
823 if (t != nullptr && lastTraCICmd == libsumo::CMD_EXECUTEMOVE) {
824 t->processCommands(myStep, true);
825 }
826 postMoveStep();
827}
828
829
830void
832 const int numControlled = libsumo::Helper::postProcessRemoteControl();
833 if (numControlled > 0 && MSGlobals::gCheck4Accidents) {
835 }
836 if (myLogExecutionTime) {
839 }
841 // collisions from the previous step were kept to avoid duplicate
842 // warnings. we must remove them now to ensure correct output.
844 }
845 // update and write (if needed) detector values
847 writeOutput();
848
849 if (myLogExecutionTime) {
851 if (myPersonControl != nullptr) {
853 }
854 }
855 myStep += DELTA_T;
856}
857
858
863 }
864 if (TraCIServer::getInstance() != nullptr && !TraCIServer::getInstance()->getLoadArgs().empty()) {
865 return SIMSTATE_LOADING;
866 }
867 if ((stopTime < 0 || myStep > stopTime) && TraCIServer::getInstance() == nullptr && (stopTime > 0 || myStep > myEdgeDataEndTime)) {
870 && (myPersonControl == nullptr || !myPersonControl->hasNonWaiting())
874 }
875 }
876 if (stopTime >= 0 && myStep >= stopTime) {
878 }
881 }
882 if (myAmInterrupted) {
884 }
885 return SIMSTATE_RUNNING;
886}
887
888
890MSNet::adaptToState(MSNet::SimulationState state, const bool isLibsumo) const {
891 if (state == SIMSTATE_LOADING) {
894 } else if (state != SIMSTATE_RUNNING && ((TraCIServer::getInstance() != nullptr && !TraCIServer::wasClosed()) || isLibsumo)) {
895 // overrides SIMSTATE_END_STEP_REACHED, e.g. (TraCI / Libsumo ignore SUMO's --end option)
896 return SIMSTATE_RUNNING;
897 } else if (state == SIMSTATE_NO_FURTHER_VEHICLES) {
898 if (myPersonControl != nullptr) {
900 }
901 if (myContainerControl != nullptr) {
903 }
905 }
906 return state;
907}
908
909
910std::string
912 switch (state) {
914 return "";
916 return "The final simulation step has been reached.";
918 return "All vehicles have left the simulation.";
920 return "TraCI requested termination.";
922 return "An error occurred (see log).";
924 return "Interrupted.";
926 return "Too many teleports.";
928 return "TraCI issued load command.";
929 default:
930 return "Unknown reason.";
931 }
932}
933
934
935void
937 // clear container
944 while (!MSLaneSpeedTrigger::getInstances().empty()) {
945 delete MSLaneSpeedTrigger::getInstances().begin()->second;
946 }
947 while (!MSTriggeredRerouter::getInstances().empty()) {
948 delete MSTriggeredRerouter::getInstances().begin()->second;
949 }
957 if (t != nullptr) {
958 t->cleanup();
959 }
962}
963
964
965void
966MSNet::clearState(const SUMOTime step, bool quickReload) {
970 for (MSEdge* const edge : MSEdge::getAllEdges()) {
971 for (MESegment* s = MSGlobals::gMesoNet->getSegmentForEdge(*edge); s != nullptr; s = s->getNextSegment()) {
972 s->clearState();
973 }
974 }
975 } else {
976 for (MSEdge* const edge : MSEdge::getAllEdges()) {
977 for (MSLane* const lane : edge->getLanes()) {
978 lane->getVehiclesSecure();
979 lane->clearState();
980 lane->releaseVehicles();
981 }
982 edge->clearState();
983 }
984 }
986 // detectors may still reference persons/vehicles
990
991 if (myPersonControl != nullptr) {
993 }
994 if (myContainerControl != nullptr) {
996 }
997 // delete vtypes after transportables have removed their types
1001 // delete all routes after vehicles and detector output is done
1003 for (auto& item : myStoppingPlaces) {
1004 for (auto& item2 : item.second) {
1005 item2.second->clearState();
1006 }
1007 }
1013 myStep = step;
1014 MSGlobals::gClearState = false;
1015}
1016
1017
1018void
1020 // update detector values
1023
1024 // check state dumps
1025 if (oc.isSet("netstate-dump")) {
1027 oc.getInt("netstate-dump.precision"));
1028 }
1029
1030 // check fcd dumps
1031 if (OptionsCont::getOptions().isSet("fcd-output")) {
1033 }
1034
1035 // check emission dumps
1036 if (OptionsCont::getOptions().isSet("emission-output")) {
1038 oc.getInt("emission-output.precision"));
1039 }
1040
1041 // battery dumps
1042 if (OptionsCont::getOptions().isSet("battery-output")) {
1044 oc.getInt("battery-output.precision"));
1045 }
1046
1047 // elecHybrid dumps
1048 if (OptionsCont::getOptions().isSet("elechybrid-output")) {
1049 std::string output = OptionsCont::getOptions().getString("elechybrid-output");
1050
1051 if (oc.getBool("elechybrid-output.aggregated")) {
1052 // build a xml file with aggregated device.elechybrid output
1054 oc.getInt("elechybrid-output.precision"));
1055 } else {
1056 // build a separate xml file for each vehicle equipped with device.elechybrid
1057 // RICE_TODO: Does this have to be placed here in MSNet.cpp ?
1059 for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
1060 const SUMOVehicle* veh = it->second;
1061 if (!veh->isOnRoad()) {
1062 continue;
1063 }
1064 if (static_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))) != nullptr) {
1065 std::string vehID = veh->getID();
1066 std::string filename2 = output + "_" + vehID + ".xml";
1067 OutputDevice& dev = OutputDevice::getDevice(filename2);
1068 std::map<SumoXMLAttr, std::string> attrs;
1069 attrs[SUMO_ATTR_VEHICLE] = vehID;
1072 dev.writeXMLHeader("elecHybrid-export", "", attrs);
1073 MSElecHybridExport::write(OutputDevice::getDevice(filename2), veh, myStep, oc.getInt("elechybrid-output.precision"));
1074 }
1075 }
1076 }
1077 }
1078
1079
1080 // check full dumps
1081 if (OptionsCont::getOptions().isSet("full-output")) {
1084 }
1085
1086 // check queue dumps
1087 if (OptionsCont::getOptions().isSet("queue-output")) {
1089 }
1090
1091 // check amitran dumps
1092 if (OptionsCont::getOptions().isSet("amitran-output")) {
1094 }
1095
1096 // check vtk dumps
1097 if (OptionsCont::getOptions().isSet("vtk-output")) {
1098
1099 if (MSNet::getInstance()->getVehicleControl().getRunningVehicleNo() > 0) {
1100 std::string timestep = time2string(myStep);
1101 timestep = timestep.substr(0, timestep.length() - 3);
1102 std::string output = OptionsCont::getOptions().getString("vtk-output");
1103 std::string filename = output + "_" + timestep + ".vtp";
1104
1105 OutputDevice_File dev(filename, false);
1106
1107 //build a huge mass of xml files
1109
1110 }
1111
1112 }
1113
1115
1116 // write detector values
1118
1119 // write link states
1120 if (OptionsCont::getOptions().isSet("link-output")) {
1121 OutputDevice& od = OutputDevice::getDeviceByOption("link-output");
1122 od.openTag("timestep");
1124 for (const MSEdge* const edge : myEdges->getEdges()) {
1125 for (const MSLane* const lane : edge->getLanes()) {
1126 for (const MSLink* const link : lane->getLinkCont()) {
1127 link->writeApproaching(od, lane->getID());
1128 }
1129 }
1130 }
1131 od.closeTag();
1132 }
1133
1134 // write SSM output
1136 dev->updateAndWriteOutput();
1137 }
1138
1139 // write ToC output
1141 if (dev->generatesOutput()) {
1142 dev->writeOutput();
1143 }
1144 }
1145
1146 if (OptionsCont::getOptions().isSet("collision-output")) {
1148 }
1149}
1150
1151
1152bool
1154 return myLogExecutionTime;
1155}
1156
1157
1160 if (myPersonControl == nullptr) {
1162 }
1163 return *myPersonControl;
1164}
1165
1166
1169 if (myContainerControl == nullptr) {
1171 }
1172 return *myContainerControl;
1173}
1174
1177 myDynamicShapeUpdater = std::unique_ptr<MSDynamicShapeUpdater> (new MSDynamicShapeUpdater(*myShapeContainer));
1178 return myDynamicShapeUpdater.get();
1179}
1180
1183 if (myEdgeWeights == nullptr) {
1185 }
1186 return *myEdgeWeights;
1187}
1188
1189
1190void
1192 std::cout << "Step #" << time2string(myStep);
1193}
1194
1195
1196void
1198 if (myLogExecutionTime) {
1199 std::ostringstream oss;
1200 oss.setf(std::ios::fixed, std::ios::floatfield); // use decimal format
1201 oss.setf(std::ios::showpoint); // print decimal point
1202 oss << std::setprecision(gPrecision);
1203 if (mySimStepDuration != 0) {
1204 const double durationSec = (double)mySimStepDuration / 1000.;
1205 oss << " (" << mySimStepDuration << "ms ~= "
1206 << (TS / durationSec) << "*RT, ~"
1207 << ((double) myVehicleControl->getRunningVehicleNo() / durationSec);
1208 } else {
1209 oss << " (0ms ?*RT. ?";
1210 }
1211 oss << "UPS, ";
1212 if (TraCIServer::getInstance() != nullptr) {
1213 oss << "TraCI: " << myTraCIStepDuration << "ms, ";
1214 }
1215 oss << "vehicles TOT " << myVehicleControl->getDepartedVehicleNo()
1216 << " ACT " << myVehicleControl->getRunningVehicleNo()
1217 << " BUF " << myInserter->getWaitingVehicleNo()
1218 << ") ";
1219 std::string prev = "Step #" + time2string(myStep - DELTA_T);
1220 std::cout << oss.str().substr(0, 90 - prev.length());
1221 }
1222 std::cout << '\r';
1223}
1224
1225
1226void
1228 if (find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener) == myVehicleStateListeners.end()) {
1229 myVehicleStateListeners.push_back(listener);
1230 }
1231}
1232
1233
1234void
1236 std::vector<VehicleStateListener*>::iterator i = std::find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener);
1237 if (i != myVehicleStateListeners.end()) {
1238 myVehicleStateListeners.erase(i);
1239 }
1240}
1241
1242
1243void
1244MSNet::informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info) {
1245#ifdef HAVE_FOX
1246 ScopedLocker<> lock(myVehicleStateListenerMutex, MSGlobals::gNumThreads > 1);
1247#endif
1248 for (VehicleStateListener* const listener : myVehicleStateListeners) {
1249 listener->vehicleStateChanged(vehicle, to, info);
1250 }
1251}
1252
1253
1254void
1257 myTransportableStateListeners.push_back(listener);
1258 }
1259}
1260
1261
1262void
1264 std::vector<TransportableStateListener*>::iterator i = std::find(myTransportableStateListeners.begin(), myTransportableStateListeners.end(), listener);
1265 if (i != myTransportableStateListeners.end()) {
1267 }
1268}
1269
1270
1271void
1272MSNet::informTransportableStateListener(const MSTransportable* const transportable, TransportableState to, const std::string& info) {
1273#ifdef HAVE_FOX
1274 ScopedLocker<> lock(myTransportableStateListenerMutex, MSGlobals::gNumThreads > 1);
1275#endif
1277 listener->transportableStateChanged(transportable, to, info);
1278 }
1279}
1280
1281
1282bool
1283MSNet::registerCollision(const SUMOTrafficObject* collider, const SUMOTrafficObject* victim, const std::string& collisionType, const MSLane* lane, double pos) {
1284 auto it = myCollisions.find(collider->getID());
1285 if (it != myCollisions.end()) {
1286 for (Collision& old : it->second) {
1287 if (old.victim == victim->getID()) {
1288 // collision from previous step continues
1289 old.colliderSpeed = collider->getSpeed();
1290 old.victimSpeed = victim->getSpeed();
1291 old.type = collisionType;
1292 old.lane = lane;
1293 old.pos = pos;
1294 old.time = myStep;
1295 return false;
1296 }
1297 }
1298 }
1299 Collision c;
1300 c.victim = victim->getID();
1301 c.colliderType = collider->getVehicleType().getID();
1302 c.victimType = victim->getVehicleType().getID();
1303 c.colliderSpeed = collider->getSpeed();
1304 c.victimSpeed = victim->getSpeed();
1305 c.type = collisionType;
1306 c.lane = lane;
1307 c.pos = pos;
1308 c.time = myStep;
1309 myCollisions[collider->getID()].push_back(c);
1310 return true;
1311}
1312
1313
1314void
1316 for (auto it = myCollisions.begin(); it != myCollisions.end();) {
1317 for (auto it2 = it->second.begin(); it2 != it->second.end();) {
1318 if (it2->time != myStep) {
1319 it2 = it->second.erase(it2);
1320 } else {
1321 it2++;
1322 }
1323 }
1324 if (it->second.size() == 0) {
1325 it = myCollisions.erase(it);
1326 } else {
1327 it++;
1328 }
1329 }
1330}
1331
1332
1333bool
1335 return myStoppingPlaces[category == SUMO_TAG_TRAIN_STOP ? SUMO_TAG_BUS_STOP : category].add(stop->getID(), stop);
1336}
1337
1338
1339bool
1341 if (find(myTractionSubstations.begin(), myTractionSubstations.end(), substation) == myTractionSubstations.end()) {
1342 myTractionSubstations.push_back(substation);
1343 return true;
1344 }
1345 return false;
1346}
1347
1348
1350MSNet::getStoppingPlace(const std::string& id, const SumoXMLTag category) const {
1351 if (myStoppingPlaces.count(category) > 0) {
1352 return myStoppingPlaces.find(category)->second.get(id);
1353 }
1354 return nullptr;
1355}
1356
1357
1358std::string
1359MSNet::getStoppingPlaceID(const MSLane* lane, const double pos, const SumoXMLTag category) const {
1360 if (myStoppingPlaces.count(category) > 0) {
1361 for (const auto& it : myStoppingPlaces.find(category)->second) {
1362 MSStoppingPlace* stop = it.second;
1363 if (&stop->getLane() == lane && stop->getBeginLanePosition() - POSITION_EPS <= pos && stop->getEndLanePosition() + POSITION_EPS >= pos) {
1364 return stop->getID();
1365 }
1366 }
1367 }
1368 return "";
1369}
1370
1371
1374 auto it = myStoppingPlaces.find(category);
1375 if (it != myStoppingPlaces.end()) {
1376 return it->second;
1377 } else {
1379 }
1380}
1381
1382
1383void
1386 OutputDevice& output = OutputDevice::getDeviceByOption("chargingstations-output");
1387 for (const auto& it : myStoppingPlaces.find(SUMO_TAG_CHARGING_STATION)->second) {
1388 static_cast<MSChargingStation*>(it.second)->writeChargingStationOutput(output);
1389 }
1390 }
1391}
1392
1393
1394void
1396 OutputDevice& output = OutputDevice::getDeviceByOption("railsignal-block-output");
1397 for (auto tls : myLogics->getAllLogics()) {
1398 MSRailSignal* rs = dynamic_cast<MSRailSignal*>(tls);
1399 if (rs != nullptr) {
1400 rs->writeBlocks(output);
1401 }
1402 }
1403}
1404
1405
1406void
1409 OutputDevice& output = OutputDevice::getDeviceByOption("overheadwiresegments-output");
1410 for (const auto& it : myStoppingPlaces.find(SUMO_TAG_OVERHEAD_WIRE_SEGMENT)->second) {
1411 static_cast<MSOverheadWire*>(it.second)->writeOverheadWireSegmentOutput(output);
1412 }
1413 }
1414}
1415
1416
1417void
1419 if (myTractionSubstations.size() > 0) {
1420 OutputDevice& output = OutputDevice::getDeviceByOption("substations-output");
1421 output.setPrecision(OptionsCont::getOptions().getInt("substations-output.precision"));
1422 for (auto& it : myTractionSubstations) {
1423 it->writeTractionSubstationOutput(output);
1424 }
1425 }
1426}
1427
1428
1430MSNet::findTractionSubstation(const std::string& substationId) {
1431 for (std::vector<MSTractionSubstation*>::iterator it = myTractionSubstations.begin(); it != myTractionSubstations.end(); ++it) {
1432 if ((*it)->getID() == substationId) {
1433 return *it;
1434 }
1435 }
1436 return nullptr;
1437}
1438
1439
1440bool
1441MSNet::existTractionSubstation(const std::string& substationId) {
1442 for (std::vector<MSTractionSubstation*>::iterator it = myTractionSubstations.begin(); it != myTractionSubstations.end(); ++it) {
1443 if ((*it)->getID() == substationId) {
1444 return true;
1445 }
1446 }
1447 return false;
1448}
1449
1450
1452MSNet::getRouterTT(const int rngIndex, const MSEdgeVector& prohibited) const {
1453 if (myRouterTT.count(rngIndex) == 0) {
1454 const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
1455 if (routingAlgorithm == "dijkstra") {
1456 myRouterTT[rngIndex] = new DijkstraRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, &MSNet::getTravelTime, nullptr, false, nullptr, true);
1457 } else {
1458 if (routingAlgorithm != "astar") {
1459 WRITE_WARNINGF(TL("TraCI and Triggers cannot use routing algorithm '%'. using 'astar' instead."), routingAlgorithm);
1460 }
1462 }
1463 }
1464 myRouterTT[rngIndex]->prohibit(prohibited);
1465 return *myRouterTT[rngIndex];
1466}
1467
1468
1470MSNet::getRouterEffort(const int rngIndex, const MSEdgeVector& prohibited) const {
1471 if (myRouterEffort.count(rngIndex) == 0) {
1473 }
1474 myRouterEffort[rngIndex]->prohibit(prohibited);
1475 return *myRouterEffort[rngIndex];
1476}
1477
1478
1480MSNet::getPedestrianRouter(const int rngIndex, const MSEdgeVector& prohibited) const {
1481 if (myPedestrianRouter.count(rngIndex) == 0) {
1482 myPedestrianRouter[rngIndex] = new MSPedestrianRouter();
1483 }
1484 myPedestrianRouter[rngIndex]->prohibit(prohibited);
1485 return *myPedestrianRouter[rngIndex];
1486}
1487
1488
1490MSNet::getIntermodalRouter(const int rngIndex, const int routingMode, const MSEdgeVector& prohibited) const {
1492 const int key = rngIndex * oc.getInt("thread-rngs") + routingMode;
1493 if (myIntermodalRouter.count(key) == 0) {
1494 int carWalk = 0;
1495 for (const std::string& opt : oc.getStringVector("persontrip.transfer.car-walk")) {
1496 if (opt == "parkingAreas") {
1498 } else if (opt == "ptStops") {
1500 } else if (opt == "allJunctions") {
1502 }
1503 }
1504 // XXX there is currently no reason to combine multiple values, thus getValueString rather than getStringVector
1505 const std::string& taxiDropoff = oc.getValueString("persontrip.transfer.taxi-walk");
1506 const std::string& taxiPickup = oc.getValueString("persontrip.transfer.walk-taxi");
1507 if (taxiDropoff == "") {
1508 if (MSDevice_Taxi::getTaxi() != nullptr) {
1510 }
1511 } else if (taxiDropoff == "ptStops") {
1513 } else if (taxiDropoff == "allJunctions") {
1515 }
1516 if (taxiPickup == "") {
1517 if (MSDevice_Taxi::getTaxi() != nullptr) {
1519 }
1520 } else if (taxiPickup == "ptStops") {
1522 } else if (taxiPickup == "allJunctions") {
1524 }
1525 const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
1526 double taxiWait = STEPS2TIME(string2time(OptionsCont::getOptions().getString("persontrip.taxi.waiting-time")));
1527 if (routingMode == libsumo::ROUTING_MODE_COMBINED) {
1528 myIntermodalRouter[key] = new MSIntermodalRouter(MSNet::adaptIntermodalRouter, carWalk, taxiWait, routingAlgorithm, routingMode, new FareModul());
1529 } else {
1530 myIntermodalRouter[key] = new MSIntermodalRouter(MSNet::adaptIntermodalRouter, carWalk, taxiWait, routingAlgorithm, routingMode);
1531 }
1532 }
1533 myIntermodalRouter[key]->prohibit(prohibited);
1534 return *myIntermodalRouter[key];
1535}
1536
1537
1538void
1540 double taxiWait = STEPS2TIME(string2time(OptionsCont::getOptions().getString("persontrip.taxi.waiting-time")));
1541 // add access to all parking areas
1542 EffortCalculator* const external = router.getExternalEffort();
1543 for (const auto& stopType : myInstance->myStoppingPlaces) {
1544 // add access to all stopping places
1545 const SumoXMLTag element = stopType.first;
1546 for (const auto& i : stopType.second) {
1547 const MSEdge* const edge = &i.second->getLane().getEdge();
1548 router.getNetwork()->addAccess(i.first, edge, i.second->getBeginLanePosition(), i.second->getEndLanePosition(),
1549 i.second->getAccessDistance(edge), element, false, taxiWait);
1550 if (element == SUMO_TAG_BUS_STOP) {
1551 // add access to all public transport stops
1552 for (const auto& a : i.second->getAllAccessPos()) {
1553 router.getNetwork()->addAccess(i.first, &std::get<0>(a)->getEdge(), std::get<1>(a), std::get<1>(a), std::get<2>(a), element, true, taxiWait);
1554 }
1555 if (external != nullptr) {
1556 external->addStop(router.getNetwork()->getStopEdge(i.first)->getNumericalID(), *i.second);
1557 }
1558 }
1559 }
1560 }
1563 // add access to transfer from walking to taxi-use
1565 for (MSEdge* edge : myInstance->getEdgeControl().getEdges()) {
1566 if ((edge->getPermissions() & SVC_PEDESTRIAN) != 0 && (edge->getPermissions() & SVC_TAXI) != 0) {
1567 router.getNetwork()->addCarAccess(edge, SVC_TAXI, taxiWait);
1568 }
1569 }
1570 }
1571}
1572
1573
1574bool
1576 const MSEdgeVector& edges = myEdges->getEdges();
1577 for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
1578 for (std::vector<MSLane*>::const_iterator i = (*e)->getLanes().begin(); i != (*e)->getLanes().end(); ++i) {
1579 if ((*i)->getShape().hasElevation()) {
1580 return true;
1581 }
1582 }
1583 }
1584 return false;
1585}
1586
1587
1588bool
1590 for (const MSEdge* e : myEdges->getEdges()) {
1591 if (e->getFunction() == SumoXMLEdgeFunc::WALKINGAREA) {
1592 return true;
1593 }
1594 }
1595 return false;
1596}
1597
1598
1599bool
1601 for (const MSEdge* e : myEdges->getEdges()) {
1602 if (e->getBidiEdge() != nullptr) {
1603 return true;
1604 }
1605 }
1606 return false;
1607}
1608
1609bool
1610MSNet::warnOnce(const std::string& typeAndID) {
1611 if (myWarnedOnce.find(typeAndID) == myWarnedOnce.end()) {
1612 myWarnedOnce[typeAndID] = true;
1613 return true;
1614 }
1615 return false;
1616}
1617
1618void
1621 clearState(string2time(oc.getString("begin")), true);
1623 // load traffic from additional files
1624 for (std::string file : oc.getStringVector("additional-files")) {
1625 // ignore failure on parsing calibrator flow
1626 MSRouteHandler rh(file, true);
1627 const long before = PROGRESS_BEGIN_TIME_MESSAGE("Loading traffic from '" + file + "'");
1628 if (!XMLSubSys::runParser(rh, file, false)) {
1629 throw ProcessError(TLF("Loading of % failed.", file));
1630 }
1631 PROGRESS_TIME_MESSAGE(before);
1632 }
1633 delete myRouteLoaders;
1635 updateGUI();
1636}
1637
1638
1640MSNet::loadState(const std::string& fileName, const bool catchExceptions) {
1641 // load time only
1642 const SUMOTime newTime = MSStateHandler::MSStateTimeHandler::getTime(fileName);
1643 // clean up state
1644 clearState(newTime);
1645 // load state
1646 MSStateHandler h(fileName, 0);
1647 XMLSubSys::runParser(h, fileName, false, false, false, catchExceptions);
1648 if (MsgHandler::getErrorInstance()->wasInformed()) {
1649 throw ProcessError(TLF("Loading state from '%' failed.", fileName));
1650 }
1651 // reset route loaders
1652 delete myRouteLoaders;
1654 // prevent loading errors on rewound route file
1656
1657 updateGUI();
1658 return newTime;
1659}
1660
1661
1662/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:268
#define WRITE_MESSAGEF(...)
Definition: MsgHandler.h:270
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:269
#define PROGRESS_BEGIN_TIME_MESSAGE(msg)
Definition: MsgHandler.h:273
#define TL(string)
Definition: MsgHandler.h:284
#define PROGRESS_TIME_MESSAGE(before)
Definition: MsgHandler.h:274
#define TLF(string,...)
Definition: MsgHandler.h:285
std::string elapsedMs2string(long long int t)
convert ms to string for log output
Definition: SUMOTime.cpp:110
SUMOTime DELTA_T
Definition: SUMOTime.cpp:37
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
#define STEPS2TIME(x)
Definition: SUMOTime.h:54
#define TS
Definition: SUMOTime.h:41
#define SIMTIME
Definition: SUMOTime.h:61
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_TAXI
vehicle is a taxi
@ SVC_PEDESTRIAN
pedestrian
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
@ SUMO_TAG_OVERHEAD_WIRE_SEGMENT
An overhead wire segment.
@ SUMO_ATTR_MAXIMUMBATTERYCAPACITY
Maxium battery capacity.
@ SUMO_ATTR_VEHICLE
@ SUMO_ATTR_RECUPERATIONENABLE
@ SUMO_ATTR_ID
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:26
std::pair< int, double > MMVersion
(M)ajor/(M)inor version for written networks and default version for loading
Definition: StdDefs.h:67
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:283
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:76
Computes the shortest path through a network using the Dijkstra algorithm.
the effort calculator interface
virtual void addStop(const int stopEdge, const Parameterised &params)=0
int getNumericalID() const
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.
_IntermodalEdge * getStopEdge(const std::string &stopId) const
Returns the associated stop edge.
@ TAXI_PICKUP_ANYWHERE
taxi customer may be picked up anywhere
@ TAXI_DROPOFF_ANYWHERE
taxi customer may exit anywhere
@ PARKING_AREAS
parking areas
@ ALL_JUNCTIONS
junctions with edges allowing the additional mode
@ TAXI_PICKUP_PT
taxi customer may be picked up at public transport stop
@ PT_STOPS
public transport stops and access
@ TAXI_DROPOFF_PT
taxi customer may be picked up at public transport stop
EffortCalculator * getExternalEffort() const
Network * getNetwork() const
int getCarWalkTransfer() const
The main mesocopic simulation loop.
Definition: MELoop.h:47
void simulate(SUMOTime tMax)
Perform simulation up to the given time.
Definition: MELoop.cpp:61
void clearState()
Remove all vehicles before quick-loading state.
Definition: MELoop.cpp:230
A single mesoscopic segment (cell)
Definition: MESegment.h:49
static void write(OutputDevice &of, const SUMOTime timestep)
Writes the complete network state into the given device.
int getRoutingMode() const
return the current routing mode
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle's internal edge travel times/efforts container.
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
static void cleanup()
cleanup remaining data structures
Detectors container; responsible for string and output generation.
void writeOutput(SUMOTime step, bool closing)
Writes the output to be generated within the given time step.
void clearState(SUMOTime step)
Remove all vehicles before quick-loading state.
void updateDetectors(const SUMOTime step)
Computes detector values.
void close(SUMOTime step)
Closes the detector outputs.
static void cleanup()
removes remaining vehicleInformation in sVehicles
A device which collects info on the vehicle trip (mainly on departure and arrival)
double getMaximumBatteryCapacity() const
Get the total vehicle's Battery Capacity in kWh.
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_SSM.h:55
static const std::set< MSDevice_SSM *, ComparatorNumericalIdLess > & getInstances()
returns all currently existing SSM devices
static void cleanup()
Clean up remaining devices instances.
static bool hasServableReservations()
check whether there are still (servable) reservations in the system
static SUMOVehicle * getTaxi()
returns a taxi if any exist or nullptr
The ToC Device controls transition of control between automated and manual driving.
Definition: MSDevice_ToC.h:52
static void cleanup()
Closes root tags of output files.
static const std::set< MSDevice_ToC *, ComparatorNumericalIdLess > & getInstances()
returns all currently existing ToC devices
Definition: MSDevice_ToC.h:91
static void writeStatistics(OutputDevice &od)
write statistic output to (xml) file
static std::string printStatistics()
get statistics for printing to stdout
static void generateOutputForUnfinished()
generate output for vehicles which are still in the network
static void writePendingOutput(const bool includeUnfinished)
generate vehroute output for pending vehicles at sim end, either due to sorting or because they are s...
static void cleanupAll()
perform cleanup for all devices
Definition: MSDevice.cpp:136
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:81
void patchActiveLanes()
Resets information whether a lane is active for all lanes.
void detectCollisions(SUMOTime timestep, const std::string &stage)
Detect collisions.
void setJunctionApproaches(SUMOTime t)
Register junction approaches for all vehicles after velocities have been planned. This is a prerequis...
void executeMovements(SUMOTime t)
Executes planned vehicle movements with regards to right-of-way.
const MSEdgeVector & getEdges() const
Returns loaded edges.
void planMovements(SUMOTime t)
Compute safe velocities for all vehicles based on positions and speeds from the last time step....
void changeLanes(const SUMOTime t)
Moves (precomputes) critical vehicles.
A road/street connecting two junctions.
Definition: MSEdge.h:77
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition: MSEdge.cpp:984
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:990
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:473
A storage for edge travel times and efforts.
bool retrieveExistingTravelTime(const MSEdge *const e, const double t, double &value) const
Returns a travel time for an edge and time if stored.
bool retrieveExistingEffort(const MSEdge *const e, const double t, double &value) const
Returns an effort for an edge and time if stored.
static void writeAggregated(OutputDevice &of, SUMOTime timestep, int precision)
static void write(OutputDevice &of, const SUMOVehicle *veh, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
Stores time-dependant events and executes them at the proper time.
virtual void execute(SUMOTime time)
Executes time-dependant commands.
void clearState(SUMOTime currentTime, SUMOTime newTime)
Remove all events before quick-loading state.
static void write(OutputDevice &of, SUMOTime timestep, bool elevation)
Writes the position and the angle of each vehicle into the given device.
Definition: MSFCDExport.cpp:50
static void write(OutputDevice &of, SUMOTime timestep)
Dumping a hugh List of Parameters available in the Simulation.
static bool gUseMesoSim
Definition: MSGlobals.h:103
static double gWeightsSeparateTurns
Whether turning specific weights are estimated (and how much)
Definition: MSGlobals.h:172
static bool gOverheadWireRecuperation
Definition: MSGlobals.h:121
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:109
static bool gStateLoaded
Information whether a state has been loaded.
Definition: MSGlobals.h:100
static bool gCheck4Accidents
Definition: MSGlobals.h:85
static bool gClearState
whether the simulation is in the process of clearing state (MSNet::clearState)
Definition: MSGlobals.h:140
static bool gHaveEmissions
Whether emission output of some type is needed (files or GUI)
Definition: MSGlobals.h:178
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:78
static int gNumThreads
how many threads to use
Definition: MSGlobals.h:146
Inserts vehicles into the network when their departure time is reached.
int getWaitingVehicleNo() const
Returns the number of waiting vehicles.
int emitVehicles(SUMOTime time)
Emits vehicles that want to depart at the given time.
void determineCandidates(SUMOTime time)
Checks for all vehicles whether they can be emitted.
int getPendingFlowCount() const
Returns the number of flows that are still active.
void adaptIntermodalRouter(MSNet::MSIntermodalRouter &router) const
void clearState()
Remove all vehicles before quick-loading state.
Container for junctions; performs operations on all stored junctions.
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
static void clear()
Clears the dictionary.
Definition: MSLane.cpp:2257
static const std::map< std::string, MSLaneSpeedTrigger * > & getInstances()
return all MSLaneSpeedTrigger instances
Interface for objects listening to transportable state changes.
Definition: MSNet.h:694
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:635
The simulated network and simulation perfomer.
Definition: MSNet.h:88
std::map< SumoXMLTag, NamedObjectCont< MSStoppingPlace * > > myStoppingPlaces
Dictionary of bus / container stops.
Definition: MSNet.h:979
long myTraCIMillis
The overall time spent waiting for traci operations including.
Definition: MSNet.h:918
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
Definition: MSNet.cpp:149
bool warnOnce(const std::string &typeAndID)
return whether a warning regarding the given object shall be issued
Definition: MSNet.cpp:1610
SUMOTime loadState(const std::string &fileName, const bool catchExceptions)
load state from file and return new time
Definition: MSNet.cpp:1640
std::map< int, SUMOAbstractRouter< MSEdge, SUMOVehicle > * > myRouterEffort
Definition: MSNet.h:1011
MSIntermodalRouter & getIntermodalRouter(const int rngIndex, const int routingMode=0, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1490
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:904
MSTransportableControl * myPersonControl
Controls person building and deletion;.
Definition: MSNet.h:873
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
Definition: MSNet.cpp:1235
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:851
bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace *stop)
Adds a stopping place.
Definition: MSNet.cpp:1334
void informTransportableStateListener(const MSTransportable *const transportable, TransportableState to, const std::string &info="")
Informs all added listeners about a transportable's state change.
Definition: MSNet.cpp:1272
SUMOTime myStateDumpPeriod
The period for writing state.
Definition: MSNet.h:937
static const NamedObjectCont< MSStoppingPlace * > myEmptyStoppingPlaceCont
Definition: MSNet.h:1000
void writeOverheadWireSegmentOutput() const
write the output generated by an overhead wire segment
Definition: MSNet.cpp:1407
void writeChargingStationOutput() const
write charging station output
Definition: MSNet.cpp:1384
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:1016
bool checkBidiEdges()
check wether bidirectional edges occur in the network
Definition: MSNet.cpp:1600
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:602
int myLogStepPeriod
Period between successive step-log outputs.
Definition: MSNet.h:909
SUMOTime myStep
Current time step.
Definition: MSNet.h:854
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:183
bool myHasBidiEdges
Whether the network contains bidirectional rail edges.
Definition: MSNet.h:967
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
Definition: MSNet.h:887
bool addTractionSubstation(MSTractionSubstation *substation)
Adds a traction substation.
Definition: MSNet.cpp:1340
std::map< std::string, bool > myWarnedOnce
container to record warnings that shall only be issued once
Definition: MSNet.h:1003
static void initStatic()
Place for static initializations of simulation components (called after successful net build)
Definition: MSNet.cpp:191
void removeOutdatedCollisions()
remove collisions from the previous simulation step
Definition: MSNet.cpp:1315
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:879
std::vector< std::string > myPeriodicStateFiles
The names of the last K periodic state files (only only K shall be kept)
Definition: MSNet.h:935
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
Definition: MSNet.h:893
std::string myStateDumpSuffix
Definition: MSNet.h:940
bool checkElevation()
check all lanes for elevation data
Definition: MSNet.cpp:1575
bool existTractionSubstation(const std::string &substationId)
return whether given electrical substation exists in the network
Definition: MSNet.cpp:1441
void removeTransportableStateListener(TransportableStateListener *listener)
Removes a transportable states listener.
Definition: MSNet.cpp:1263
SimulationState adaptToState(const SimulationState state, const bool isLibsumo=false) const
Called after a simulation step, this method adapts the current simulation state if necessary.
Definition: MSNet.cpp:890
void closeBuilding(const OptionsCont &oc, MSEdgeControl *edges, MSJunctionControl *junctions, SUMORouteLoaderControl *routeLoaders, MSTLLogicControl *tlc, std::vector< SUMOTime > stateDumpTimes, std::vector< std::string > stateDumpFiles, bool hasInternalLinks, bool junctionHigherSpeeds, const MMVersion &version)
Closes the network's building process.
Definition: MSNet.cpp:256
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:907
MMVersion myVersion
the network version
Definition: MSNet.h:973
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:891
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:1168
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:93
@ SIMSTATE_TOO_MANY_TELEPORTS
The simulation had too many teleports.
Definition: MSNet.h:109
@ SIMSTATE_NO_FURTHER_VEHICLES
The simulation does not contain further vehicles.
Definition: MSNet.h:101
@ SIMSTATE_LOADING
The simulation is loading.
Definition: MSNet.h:95
@ SIMSTATE_ERROR_IN_SIM
An error occurred during the simulation step.
Definition: MSNet.h:105
@ SIMSTATE_CONNECTION_CLOSED
The connection to a client was closed by the client.
Definition: MSNet.h:103
@ SIMSTATE_INTERRUPTED
An external interrupt occured.
Definition: MSNet.h:107
@ SIMSTATE_RUNNING
The simulation is running.
Definition: MSNet.h:97
@ SIMSTATE_END_STEP_REACHED
The final simulation step has been performed.
Definition: MSNet.h:99
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1452
std::map< int, MSPedestrianRouter * > myPedestrianRouter
Definition: MSNet.h:1012
static const std::string STAGE_MOVEMENTS
Definition: MSNet.h:824
int myMaxTeleports
Maximum number of teleports.
Definition: MSNet.h:860
long mySimStepDuration
Definition: MSNet.h:912
PedestrianRouter< MSEdge, MSLane, MSJunction, MSVehicle > MSPedestrianRouter
Definition: MSNet.h:112
MSEventControl * myEndOfTimestepEvents
Controls events executed at the end of a time step;.
Definition: MSNet.h:889
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:911
std::string getStoppingPlaceID(const MSLane *lane, const double pos, const SumoXMLTag category) const
Returns the stop of the given category close to the given position.
Definition: MSNet.cpp:1359
bool myHasInternalLinks
Whether the network contains internal links/lanes/edges.
Definition: MSNet.h:955
void writeSubstationOutput() const
write electrical substation output
Definition: MSNet.cpp:1418
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:826
long long int myPersonsMoved
Definition: MSNet.h:922
void quickReload()
reset state to the beginning without reloading the network
Definition: MSNet.cpp:1619
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:871
static void clearAll()
Clears all dictionaries.
Definition: MSNet.cpp:936
static void cleanupStatic()
Place for static initializations of simulation components (called after successful net build)
Definition: MSNet.cpp:198
void writeStatistics(const SUMOTime start, const long now) const
write statistic output to (xml) file
Definition: MSNet.cpp:547
IntermodalRouter< MSEdge, MSLane, MSJunction, SUMOVehicle > MSIntermodalRouter
Definition: MSNet.h:113
void writeSummaryOutput()
write summary-output to (xml) file
Definition: MSNet.cpp:596
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:320
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:877
std::unique_ptr< MSDynamicShapeUpdater > myDynamicShapeUpdater
Updater for dynamic shapes that are tracking traffic objects (ensures removal of shape dynamics when ...
Definition: MSNet.h:1021
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: MSNet.cpp:351
void closeSimulation(SUMOTime start, const std::string &reason="")
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:660
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:1350
bool myHasElevation
Whether the network contains elevation data.
Definition: MSNet.h:961
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:163
MSTransportableControl * myContainerControl
Controls container building and deletion;.
Definition: MSNet.h:875
std::vector< TransportableStateListener * > myTransportableStateListeners
Container for transportable state listener.
Definition: MSNet.h:988
void writeOutput()
Write netstate, summary and detector output.
Definition: MSNet.cpp:1019
virtual void updateGUI() const
update view after simulation.loadState
Definition: MSNet.h:590
bool myAmInterrupted
whether an interrupt occured
Definition: MSNet.h:863
void simulationStep(const bool onlyMove=false)
Performs a single simulation step.
Definition: MSNet.cpp:697
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:1227
void clearState(const SUMOTime step, bool quickReload=false)
Resets events when quick-loading state.
Definition: MSNet.cpp:966
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:1191
void writeCollisions() const
write collision output to (xml) file
Definition: MSNet.cpp:525
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:931
void addTransportableStateListener(TransportableStateListener *listener)
Adds a transportable states listener.
Definition: MSNet.cpp:1255
std::vector< MSTractionSubstation * > myTractionSubstations
Dictionary of traction substations.
Definition: MSNet.h:982
SUMOTime myEdgeDataEndTime
end of loaded edgeData
Definition: MSNet.h:976
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net's internal edge travel times/efforts container.
Definition: MSNet.cpp:1182
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition: MSNet.h:949
std::vector< std::string > myStateDumpFiles
The names for the state files.
Definition: MSNet.h:933
void addMesoType(const std::string &typeID, const MESegment::MesoEdgeType &edgeType)
Adds edge type specific meso parameters.
Definition: MSNet.cpp:360
void writeRailSignalBlocks() const
write rail signal block output
Definition: MSNet.cpp:1395
MSTLLogicControl * myLogics
Controls tls logics, realizes waiting on tls rules;.
Definition: MSNet.h:881
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:1153
long long int myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:921
static const std::string STAGE_REMOTECONTROL
Definition: MSNet.h:827
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to, const std::string &info="")
Informs all added listeners about a vehicle's state change.
Definition: MSNet.cpp:1244
std::vector< VehicleStateListener * > myVehicleStateListeners
Container for vehicle state listener.
Definition: MSNet.h:985
SimulationState simulationState(SUMOTime stopTime) const
This method returns the current simulation state. It should not modify status.
Definition: MSNet.cpp:860
long myTraCIStepDuration
The last simulation step duration.
Definition: MSNet.h:912
TransportableState
Definition of a transportable state.
Definition: MSNet.h:679
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:431
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition: MSNet.h:885
bool myStepCompletionMissing
whether libsumo triggered a partial step (executeMove)
Definition: MSNet.h:857
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:825
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:205
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition: MSNet.cpp:345
std::map< int, SUMOAbstractRouter< MSEdge, SUMOVehicle > * > myRouterTT
Definition: MSNet.h:1010
std::map< std::string, MESegment::MesoEdgeType > myMesoEdgeTypes
The edge type specific meso parameters.
Definition: MSNet.h:952
static void adaptIntermodalRouter(MSIntermodalRouter &router)
Definition: MSNet.cpp:1539
MSEdgeWeightsStorage * myEdgeWeights
The net's knowledge about edge efforts/travel times;.
Definition: MSNet.h:895
MSDynamicShapeUpdater * makeDynamicShapeUpdater()
Creates and returns a dynamic shapes updater.
Definition: MSNet.cpp:1176
std::map< int, MSIntermodalRouter * > myIntermodalRouter
Definition: MSNet.h:1013
virtual ~MSNet()
Destructor.
Definition: MSNet.cpp:291
MSPedestrianRouter & getPedestrianRouter(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1480
MSTractionSubstation * findTractionSubstation(const std::string &substationId)
find electrical substation by its id
Definition: MSNet.cpp:1430
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:848
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:378
MSInsertionControl * myInserter
Controls vehicle insertion;.
Definition: MSNet.h:883
void postSimStepOutput() const
Prints the statistics of the step at its end.
Definition: MSNet.cpp:1197
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1159
bool registerCollision(const SUMOTrafficObject *collider, const SUMOTrafficObject *victim, const std::string &collisionType, const MSLane *lane, double pos)
register collision and return whether it was the first one involving these vehicles
Definition: MSNet.cpp:1283
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:823
void loadRoutes()
loads routes for the next few steps
Definition: MSNet.cpp:428
std::string myStateDumpPrefix
name components for periodic state
Definition: MSNet.h:939
bool myJunctionHigherSpeeds
Whether the network was built with higher speed on junctions.
Definition: MSNet.h:958
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:421
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:915
bool myHasPedestrianNetwork
Whether the network contains pedestrian network elements.
Definition: MSNet.h:964
const MESegment::MesoEdgeType & getMesoType(const std::string &typeID)
Returns edge type specific meso parameters if no type specific parameters have been loaded,...
Definition: MSNet.cpp:365
void postMoveStep()
Performs the parts of the simulation step which happen after the move.
Definition: MSNet.cpp:831
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:776
const std::string generateStatistics(const SUMOTime start, const long now)
Writes performance output and running vehicle stats.
Definition: MSNet.cpp:434
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterEffort(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1470
bool checkWalkingarea()
check all lanes for type walkingArea
Definition: MSNet.cpp:1589
CollisionMap myCollisions
collisions in the current time step
Definition: MSNet.h:991
const NamedObjectCont< MSStoppingPlace * > & getStoppingPlaces(SumoXMLTag category) const
Definition: MSNet.cpp:1373
SimulationState simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:386
Definition of overhead wire segment.
static void write(OutputDevice &of, SUMOTime timestep)
Export the queueing length in front of a junction (very experimental!)
static void cleanup()
clean up state
static void clearState()
Perform resets events when quick-loading state.
A signal for rails.
Definition: MSRailSignal.h:46
void writeBlocks(OutputDevice &od) const
write rail signal block output for all links and driveways
static void recheckGreen()
final check for driveway compatibility of signals that switched green in this step
Parser and container for routes during their loading.
static void dict_clearState()
Decrement all route references before quick-loading state.
Definition: MSRoute.cpp:297
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:174
static double getEffortExtra(const MSEdge *const e, const SUMOVehicle *const v, double t)
static SUMOTime getTime(const std::string &fileName)
parse time from state file
Parser and output filter for routes and vehicles state saving and loading.
static void saveState(const std::string &file, SUMOTime step, bool usePrefix=true)
Saves the current state.
static bool active()
Definition: MSStopOut.h:54
static void cleanup()
Definition: MSStopOut.cpp:50
void generateOutputForUnfinished()
generate output for vehicles which are still stopped at simulation end
Definition: MSStopOut.cpp:174
static MSStopOut * getInstance()
Definition: MSStopOut.h:60
A lane area vehicles can halt at.
double getBeginLanePosition() const
Returns the begin position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
A class that stores and controls tls and switching of their programs.
void clearState(SUMOTime time, bool quickReload=false)
Clear all tls states before quick-loading state.
std::vector< MSTrafficLightLogic * > getAllLogics() const
Returns a vector which contains all logics.
void check2Switch(SUMOTime step)
Checks whether any WAUT is trying to switch a tls into another program.
Traction substaction powering one or more overhead wire sections.
int getRunningNumber() const
Returns the number of build and inserted, but not yet deleted transportables.
bool hasTransportables() const
checks whether any transportable waits to finish her plan
int getWaitingForVehicleNumber() const
Returns the number of transportables waiting for a ride.
int getEndedNumber() const
Returns the number of transportables that exited the simulation.
void checkWaiting(MSNet *net, const SUMOTime time)
checks whether any transportables waiting time is over
int getArrivedNumber() const
Returns the number of transportables that arrived at their destination.
int getTeleportCount() const
Returns the number of teleports transportables did.
int getLoadedNumber() const
Returns the number of build transportables.
int getWaitingUntilNumber() const
Returns the number of transportables waiting for a specified amount of time.
int getTeleportsWrongDest() const
return the number of teleports of transportables riding to the wrong destination
void abortAnyWaitingForVehicle()
aborts the plan for any transportable that is still waiting for a ride
bool hasNonWaiting() const
checks whether any transportable is still engaged in walking / stopping
int getMovingNumber() const
Returns the number of transportables moving by themselvs (i.e. walking)
int getJammedNumber() const
Returns the number of times a transportables was jammed.
void clearState()
Resets transportables when quick-loading state.
int getTeleportsAbortWait() const
return the number of teleports due to excessive waiting for a ride
int getRidingNumber() const
Returns the number of transportables riding a vehicle.
static const std::map< std::string, MSTriggeredRerouter * > & getInstances()
return all rerouter instances
static void write(OutputDevice &of, SUMOTime timestep)
Produce a VTK output to use with Tools like ParaView.
Definition: MSVTKExport.cpp:41
static void init()
Static initalization.
Definition: MSVehicle.cpp:385
static void cleanup()
Static cleanup.
Definition: MSVehicle.cpp:390
The class responsible for building and deletion of vehicles.
int getRunningVehicleNo() const
Returns the number of build and inserted, but not yet deleted vehicles.
void removePending()
Removes a vehicle after it has ended.
double getTotalTravelTime() const
Returns the total travel time.
void adaptIntermodalRouter(MSNet::MSIntermodalRouter &router) const
int getLoadedVehicleNo() const
Returns the number of build vehicles.
int getCollisionCount() const
return the number of collisions
int getTeleportsWrongLane() const
return the number of teleports due to vehicles stuck on the wrong lane
int getStoppedVehiclesCount() const
return the number of vehicles that are currently stopped
int getTeleportsYield() const
return the number of teleports due to vehicles stuck on a minor road
void clearState(const bool reinit)
Remove all vehicles before quick-loading state.
int getEmergencyStops() const
return the number of emergency stops
double getTotalDepartureDelay() const
Returns the total departure delay.
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
int getDepartedVehicleNo() const
Returns the number of inserted vehicles.
int getArrivedVehicleNo() const
Returns the number of arrived vehicles.
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger or a ...
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
int getTeleportsJam() const
return the number of teleports due to jamming
int getEndedVehicleNo() const
Returns the number of removed vehicles.
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
int getTeleportCount() const
return the number of teleports (including collisions)
void abortWaiting()
informes about all waiting vehicles (deletion in destructor)
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
BaseInfluencer & getBaseInfluencer()
Returns the velocity/lane influencer.
Definition: MSVehicle.cpp:6947
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
void checkInsertions(SUMOTime time)
Checks "movement" of stored vehicles.
void clearState()
Remove all vehicles before quick-loading state.
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:91
static void write(OutputDevice &of, const MSEdgeControl &ec, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
Definition: MSXMLRawOut.cpp:47
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
static SUMORouteLoaderControl * buildRouteLoaderControl(const OptionsCont &oc)
Builds the route loader control.
Definition: NLBuilder.cpp:437
static void initRandomness()
initializes all RNGs
Definition: NLBuilder.cpp:358
const std::string & getID() const
Returns the id.
Definition: Named.h:74
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 getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
std::string getValueString(const std::string &name) const
Returns the string-value of the named option (all options)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:59
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:58
An output device that encapsulates an ofstream.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
static void closeAll(bool keepErrorRetrievers=false)
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.
void loadNext(SUMOTime step)
loads the next routes up to and including the given time step
Representation of a vehicle, person, or container.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getSpeed() const =0
Returns the object's current speed.
Representation of a vehicle.
Definition: SUMOVehicle.h:62
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
virtual MSVehicleDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or 0.
A scoped lock which only triggers on condition.
Definition: ScopedLocker.h:40
Storage for geometrical objects.
void clearState()
Remove all dynamics before quick-loading state.
static long getCurrentMillis()
Returns the current time in milliseconds.
Definition: SysUtils.cpp:43
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:59
static bool wasClosed()
check whether close was requested
SUMOTime getTargetTime() const
Definition: TraCIServer.h:64
static TraCIServer * getInstance()
Definition: TraCIServer.h:68
std::vector< std::string > & getLoadArgs()
Definition: TraCIServer.h:258
void cleanup()
clean up subscriptions
int processCommands(const SUMOTime step, const bool afterMove=false)
process all commands until the next SUMO simulation step. It is guaranteed that t->getTargetTime() >=...
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false, const bool isRoute=false, const bool isExternal=false, const bool catchExceptions=true)
Runs the given handler on the given file; returns if everything's ok.
Definition: XMLSubSys.cpp:157
static void cleanup()
Definition: Helper.cpp:677
static int postProcessRemoteControl()
return number of remote-controlled entities
Definition: Helper.cpp:1392
TRACI_CONST int CMD_EXECUTEMOVE
TRACI_CONST int ROUTING_MODE_AGGREGATED_CUSTOM
TRACI_CONST int ROUTING_MODE_COMBINED
edge type specific meso parameters
Definition: MESegment.h:55
collision tracking
Definition: MSNet.h:116
double victimSpeed
Definition: MSNet.h:121
const MSLane * lane
Definition: MSNet.h:123
std::string victimType
Definition: MSNet.h:119
double pos
Definition: MSNet.h:124
std::string type
Definition: MSNet.h:122
std::string colliderType
Definition: MSNet.h:118
std::string victim
Definition: MSNet.h:117
double colliderSpeed
Definition: MSNet.h:120
SUMOTime time
Definition: MSNet.h:125