Line data Source code
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 : /****************************************************************************/
14 : /// @file MSNet.h
15 : /// @author Christian Roessel
16 : /// @author Jakob Erdmann
17 : /// @author Daniel Krajzewicz
18 : /// @author Thimor Bohn
19 : /// @author Eric Nicolay
20 : /// @author Clemens Honomichl
21 : /// @author Michael Behrisch
22 : /// @author Leonhard Luecken
23 : /// @date Mon, 12 Mar 2001
24 : ///
25 : // The simulated network and simulation performer
26 : /****************************************************************************/
27 : #pragma once
28 : #include <config.h>
29 :
30 : #include <typeinfo>
31 : #include <vector>
32 : #include <map>
33 : #include <string>
34 : #include <fstream>
35 : #include <iostream>
36 : #include <cmath>
37 : #include <iomanip>
38 : #include <memory>
39 : #include <utils/common/SUMOTime.h>
40 : #include <utils/common/UtilExceptions.h>
41 : #include <utils/common/NamedObjectCont.h>
42 : #include <utils/common/NamedRTree.h>
43 : #include <utils/router/SUMOAbstractRouter.h>
44 : #include <mesosim/MESegment.h>
45 : #include "MSRouterDefs.h"
46 : #include "MSJunction.h"
47 :
48 :
49 : // ===========================================================================
50 : // class declarations
51 : // ===========================================================================
52 : class MSEdge;
53 : class MSEdgeControl;
54 : class MSEventControl;
55 : class MSVehicleControl;
56 : class MSJunctionControl;
57 : class MSInsertionControl;
58 : class SUMORouteLoaderControl;
59 : class MSTransportableControl;
60 : class MSTransportable;
61 : class MSVehicle;
62 : class MSRoute;
63 : class MSLane;
64 : class MSTLLogicControl;
65 : class MSTrafficLightLogic;
66 : class MSDetectorControl;
67 : class ShapeContainer;
68 : class MSDynamicShapeUpdater;
69 : class PolygonDynamics;
70 : class MSEdgeWeightsStorage;
71 : class SUMOVehicle;
72 : class SUMOTrafficObject;
73 : class MSTractionSubstation;
74 : class MSStoppingPlace;
75 : template<class E, class L, class N, class V>
76 : class IntermodalRouter;
77 : template<class E, class L, class N, class V>
78 : class PedestrianRouter;
79 : class OptionsCont;
80 :
81 :
82 : // ===========================================================================
83 : // class definitions
84 : // ===========================================================================
85 : /**
86 : * @class MSNet
87 : * @brief The simulated network and simulation perfomer
88 : */
89 : class MSNet : public Parameterised {
90 : public:
91 : /** @enum SimulationState
92 : * @brief Possible states of a simulation - running or stopped with different reasons
93 : */
94 : enum SimulationState {
95 : /// @brief The simulation is loading
96 : SIMSTATE_LOADING,
97 : /// @brief The simulation is running
98 : SIMSTATE_RUNNING,
99 : /// @brief The final simulation step has been performed
100 : SIMSTATE_END_STEP_REACHED,
101 : /// @brief The simulation does not contain further vehicles
102 : SIMSTATE_NO_FURTHER_VEHICLES,
103 : /// @brief The connection to a client was closed by the client
104 : SIMSTATE_CONNECTION_CLOSED,
105 : /// @brief An error occurred during the simulation step
106 : SIMSTATE_ERROR_IN_SIM,
107 : /// @brief An external interrupt occurred
108 : SIMSTATE_INTERRUPTED,
109 : /// @brief The simulation had too many teleports
110 : SIMSTATE_TOO_MANY_TELEPORTS
111 : };
112 :
113 : /// @brief collision tracking
114 : struct Collision {
115 : std::string victim;
116 : std::string colliderType;
117 : std::string victimType;
118 : double colliderSpeed;
119 : double victimSpeed;
120 : Position colliderFront;
121 : Position victimFront;
122 : Position colliderBack;
123 : Position victimBack;
124 : std::string type;
125 : const MSLane* lane;
126 : double pos;
127 : SUMOTime time;
128 : SUMOTime continuationTime;
129 : };
130 :
131 : typedef std::map<std::string, std::vector<Collision> > CollisionMap;
132 : typedef std::map<const MSEdge*, double> Prohibitions;
133 :
134 : public:
135 : /** @brief Returns the pointer to the unique instance of MSNet (singleton).
136 : * @return Pointer to the unique MSNet-instance
137 : * @exception ProcessError If a network was not yet constructed
138 : */
139 : static MSNet* getInstance();
140 :
141 : /**
142 : * @brief Returns whether this is a GUI Net
143 : */
144 40 : virtual bool isGUINet() const {
145 40 : return false;
146 : }
147 :
148 : /// @brief Place for static initializations of simulation components (called after successful net build)
149 : static void initStatic();
150 :
151 : /// @brief Place for static initializations of simulation components (called after successful net build)
152 : static void cleanupStatic();
153 :
154 :
155 : /** @brief Returns whether the network was already constructed
156 : * @return whether the network was already constructed
157 : */
158 : static bool hasInstance() {
159 7411953 : return myInstance != nullptr;
160 : }
161 :
162 :
163 : /** @brief Constructor
164 : *
165 : * This constructor builds a net of which only some basic structures are initialised.
166 : * It prepares the network for being filled while loading.
167 : * As soon as all edge/junction/traffic lights and other containers are build, they
168 : * must be initialised using "closeBuilding".
169 : * @param[in] vc The vehicle control to use
170 : * @param[in] beginOfTimestepEvents The event control to use for simulation step begin events
171 : * @param[in] endOfTimestepEvents The event control to use for simulation step end events
172 : * @param[in] insertionEvents The event control to use for insertion events
173 : * @param[in] shapeCont The shape container to use
174 : * @exception ProcessError If a network was already constructed
175 : * @see closeBuilding
176 : */
177 : MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
178 : MSEventControl* endOfTimestepEvents,
179 : MSEventControl* insertionEvents,
180 : ShapeContainer* shapeCont = 0);
181 :
182 :
183 : /// @brief Destructor
184 : virtual ~MSNet();
185 :
186 :
187 : /** @brief Closes the network's building process
188 : *
189 : * Assigns the structures built while loading to this network.
190 : * @param[in] oc The options to use
191 : * @param[in] edges The control of edges which belong to this network
192 : * @param[in] junctions The control of junctions which belong to this network
193 : * @param[in] routeLoaders The route loaders used
194 : * @param[in] tlc The control of traffic lights which belong to this network
195 : * @param[in] stateDumpTimes List of time steps at which state shall be written
196 : * @param[in] stateDumpFiles Filenames for states
197 : * @param[in] hasInternalLinks Whether the network actually contains internal links
198 : * @param[in] junctionHigherSpeeds Whether the network was built with higher junction speeds
199 : * @param[in] version The network version
200 : * @todo Try to move all this to the constructor?
201 : */
202 : void closeBuilding(const OptionsCont& oc, MSEdgeControl* edges, MSJunctionControl* junctions,
203 : SUMORouteLoaderControl* routeLoaders, MSTLLogicControl* tlc,
204 : std::vector<SUMOTime> stateDumpTimes, std::vector<std::string> stateDumpFiles,
205 : bool hasInternalLinks,
206 : bool junctionHigherSpeeds,
207 : const MMVersion& version);
208 :
209 :
210 : /** @brief Returns whether the network has specific vehicle class permissions
211 : * @return whether permissions are present
212 : */
213 : bool hasPermissions() const {
214 44500831 : return myHavePermissions;
215 : }
216 :
217 :
218 : /// @brief Labels the network to contain vehicle class permissions
219 : void setPermissionsFound() {
220 811181 : myHavePermissions = true;
221 811181 : }
222 :
223 :
224 : /** @brief Adds a restriction for an edge type
225 : * @param[in] id The id of the type
226 : * @param[in] svc The vehicle class the restriction refers to
227 : * @param[in] speed The restricted speed
228 : */
229 : void addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed);
230 :
231 :
232 : /** @brief Returns the restrictions for an edge type
233 : * If no restrictions are present, 0 is returned.
234 : * @param[in] id The id of the type
235 : * @return The mapping of vehicle classes to maximum speeds
236 : */
237 : const std::map<SUMOVehicleClass, double>* getRestrictions(const std::string& id) const;
238 :
239 : /// @brief retriefe edge type specific routing preference
240 : double getPreference(const std::string& routingType, const SUMOVTypeParameter& pars) const;
241 :
242 : /// @brief add edge type specific routing preference
243 : void addPreference(const std::string& routingType, SUMOVehicleClass svc, double prio);
244 : /// @brief add edge type specific routing preference
245 : void addPreference(const std::string& routingType, std::string vType, double prio);
246 :
247 : /** @brief Adds edge type specific meso parameters
248 : * @param[in] id The id of the type
249 : * @param[in] edgeType The parameter object
250 : */
251 : void addMesoType(const std::string& typeID, const MESegment::MesoEdgeType& edgeType);
252 :
253 : /** @brief Returns edge type specific meso parameters
254 : * if no type specific parameters have been loaded, default values are returned
255 : */
256 : const MESegment::MesoEdgeType& getMesoType(const std::string& typeID);
257 :
258 : /** @brief Clears all dictionaries
259 : * @todo Try to move all this to the destructor
260 : */
261 : static void clearAll();
262 :
263 : /// @brief return whether the given flow is known
264 : bool hasFlow(const std::string& id) const;
265 :
266 : /** @brief Simulates from timestep start to stop
267 : * @param[in] start The begin time step of the simulation
268 : * @param[in] stop The end time step of the simulation
269 : * @return Returns always 0
270 : * @todo Recheck return value
271 : * @todo What exceptions may occure?
272 : */
273 : SimulationState simulate(SUMOTime start, SUMOTime stop);
274 :
275 :
276 : /** @brief Performs a single simulation step
277 : * @todo Which exceptions may occur?
278 : */
279 : void simulationStep(const bool onlyMove = false);
280 :
281 : /** @brief loads routes for the next few steps */
282 : void loadRoutes();
283 :
284 :
285 : /** @brief Writes performance output and running vehicle stats
286 : *
287 : * @param[in] start The step the simulation was started with
288 : */
289 : const std::string generateStatistics(const SUMOTime start, const long now);
290 :
291 : /// @brief write collision output to (xml) file
292 : void writeCollisions() const;
293 :
294 : /// @brief write statistic output to (xml) file
295 : void writeStatistics(const SUMOTime start, const long now) const;
296 :
297 : /// @brief write summary-output to (xml) file
298 : void writeSummaryOutput(bool finalStep = false);
299 :
300 : /** @brief Closes the simulation (all files, connections, etc.)
301 : *
302 : * Writes also performance output
303 : *
304 : * @param[in] start The step the simulation was started with
305 : */
306 : void closeSimulation(SUMOTime start, const std::string& reason = "");
307 :
308 :
309 : /** @brief This method returns the current simulation state. It should not modify status.
310 : * @param[in] stopTime The time the simulation shall stop at
311 : * @return The current simulation state
312 : * @see SimulationState
313 : */
314 : SimulationState simulationState(SUMOTime stopTime) const;
315 :
316 :
317 : /** @brief Called after a simulation step, this method adapts the current simulation state if necessary
318 : * @param[in] state The current simulation state
319 : * @return The new simulation state
320 : * @see SimulationState
321 : */
322 : SimulationState adaptToState(const SimulationState state, const bool isLibsumo = false) const;
323 :
324 :
325 : /** @brief Returns the message to show if a certain state occurs
326 : * @return Readable description of the state
327 : */
328 : static std::string getStateMessage(SimulationState state);
329 :
330 :
331 : /** @brief Returns the current simulation step
332 : * @return the current simulation step
333 : */
334 : inline SUMOTime getCurrentTimeStep() const {
335 3056587494 : return myStep;
336 : }
337 :
338 :
339 : /** @brief Sets the current simulation step (used by state loading)
340 : * @param step the current simulation step
341 : */
342 : inline void setCurrentTimeStep(const SUMOTime step) {
343 8553 : myStep = step;
344 : }
345 :
346 :
347 : /** @brief Resets events when quick-loading state
348 : * @param step The new simulation step
349 : */
350 : void clearState(const SUMOTime step, bool quickReload = false);
351 :
352 : /** @brief Write netstate, summary and detector output
353 : * @todo Which exceptions may occur?
354 : */
355 : void writeOutput();
356 :
357 :
358 : /** @brief Returns whether duration shall be logged
359 : * @return Whether duration shall be logged
360 : */
361 : bool logSimulationDuration() const;
362 :
363 :
364 :
365 : /// @name Output during the simulation
366 : //@{
367 :
368 : /** @brief Prints the current step number
369 : *
370 : * Called on the begin of a simulation step
371 : */
372 : void preSimStepOutput() const;
373 :
374 :
375 : /** @brief Prints the statistics of the step at its end
376 : *
377 : * Called on the end of a simulation step
378 : */
379 : void postSimStepOutput() const;
380 : //}
381 :
382 :
383 :
384 : /// @name Retrieval of references to substructures
385 : /// @{
386 :
387 : /** @brief Returns the vehicle control
388 : * @return The vehicle control
389 : * @see MSVehicleControl
390 : * @see myVehicleControl
391 : */
392 : MSVehicleControl& getVehicleControl() {
393 687723791 : return *myVehicleControl;
394 : }
395 :
396 :
397 : /** @brief Returns the person control
398 : *
399 : * If the person control does not exist, yet, it is created.
400 : *
401 : * @return The person control
402 : * @see MSPersonControl
403 : * @see myPersonControl
404 : */
405 : virtual MSTransportableControl& getPersonControl();
406 :
407 : /** @brief Returns whether persons are simulated
408 : */
409 : bool hasPersons() const {
410 397972720 : return myPersonControl != nullptr;
411 : }
412 :
413 : /** @brief Returns the container control
414 : *
415 : * If the container control does not exist, yet, it is created.
416 : *
417 : * @return The container control
418 : * @see MSContainerControl
419 : * @see myContainerControl
420 : */
421 : virtual MSTransportableControl& getContainerControl();
422 :
423 : /** @brief Returns whether containers are simulated
424 : */
425 : bool hasContainers() const {
426 35283648 : return myContainerControl != nullptr;
427 : }
428 :
429 :
430 : /** @brief Returns the edge control
431 : * @return The edge control
432 : * @see MSEdgeControl
433 : * @see myEdges
434 : */
435 : MSEdgeControl& getEdgeControl() {
436 176717816 : return *myEdges;
437 : }
438 :
439 :
440 : /** @brief Returns the insertion control
441 : * @return The insertion control
442 : * @see MSInsertionControl
443 : * @see myInserter
444 : */
445 : MSInsertionControl& getInsertionControl() {
446 11124761 : return *myInserter;
447 : }
448 :
449 :
450 : /** @brief Returns the detector control
451 : * @return The detector control
452 : * @see MSDetectorControl
453 : * @see myDetectorControl
454 : */
455 : MSDetectorControl& getDetectorControl() {
456 199320 : return *myDetectorControl;
457 : }
458 :
459 :
460 : /** @brief Returns the tls logics control
461 : * @return The tls logics control
462 : * @see MSTLLogicControl
463 : * @see myLogics
464 : */
465 : MSTLLogicControl& getTLSControl() {
466 354010 : return *myLogics;
467 : }
468 :
469 :
470 : /** @brief Returns the junctions control
471 : * @return The junctions control
472 : * @see MSJunctionControl
473 : * @see myJunctions
474 : */
475 : MSJunctionControl& getJunctionControl() {
476 32951 : return *myJunctions;
477 : }
478 :
479 :
480 : /** @brief Returns the event control for events executed at the begin of a time step
481 : * @return The control responsible for events that are executed at the begin of a time step
482 : * @see MSEventControl
483 : * @see myBeginOfTimestepEvents
484 : */
485 : MSEventControl* getBeginOfTimestepEvents() {
486 342677 : return myBeginOfTimestepEvents;
487 : }
488 :
489 :
490 : /** @brief Returns the event control for events executed at the end of a time step
491 : * @return The control responsible for events that are executed at the end of a time step
492 : * @see MSEventControl
493 : * @see myEndOfTimestepEvents
494 : */
495 : MSEventControl* getEndOfTimestepEvents() {
496 25711 : return myEndOfTimestepEvents;
497 : }
498 :
499 :
500 : /** @brief Returns the event control for insertion events
501 : * @return The control responsible for insertion events
502 : * @see MSEventControl
503 : * @see myInsertionEvents
504 : */
505 : MSEventControl* getInsertionEvents() {
506 1566520 : return myInsertionEvents;
507 : }
508 :
509 :
510 : /** @brief Returns the shapes container
511 : * @return The shapes container
512 : * @see ShapeContainer
513 : * @see myShapeContainer
514 : */
515 : ShapeContainer& getShapeContainer() {
516 96671 : return *myShapeContainer;
517 : }
518 :
519 : /** @brief Returns the dynamic shapes updater
520 : * @see PolygonDynamics
521 : */
522 : MSDynamicShapeUpdater* getDynamicShapeUpdater() {
523 : return myDynamicShapeUpdater.get();
524 : }
525 :
526 : /** @brief Creates and returns a dynamic shapes updater
527 : * @see PolygonDynamics
528 : */
529 : MSDynamicShapeUpdater* makeDynamicShapeUpdater();
530 :
531 : /** @brief Returns the net's internal edge travel times/efforts container
532 : *
533 : * If the net does not have such a container, it is built.
534 : * @return The net's knowledge about edge weights
535 : */
536 : MSEdgeWeightsStorage& getWeightsStorage();
537 : /// @}
538 :
539 : /// @name Insertion and retrieval of stopping places
540 : /// @{
541 :
542 : /** @brief Adds a stopping place
543 : *
544 : * If another stop with the same id and category exists, false is returned.
545 : * Otherwise, the stop is added to the internal stopping place container.
546 : *
547 : * This control gets responsible for deletion of the added stop.
548 : *
549 : * @param[in] stop The stop to add
550 : * @return Whether the stop could be added
551 : */
552 : bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace* stop);
553 :
554 :
555 : /** @brief Adds a traction substation
556 : *
557 : * If another traction substation with the same id and category exists, false is returned.
558 : * Otherwise, the traction substation is added to the internal substations container.
559 : *
560 : * @param[in] substation The traction substation to add
561 : * @return Whether the stop could be added
562 : */
563 : bool addTractionSubstation(MSTractionSubstation* substation);
564 :
565 :
566 : /** @brief Returns the named stopping place of the given category
567 : * @param[in] id The id of the stop to return.
568 : * @param[in] category The type of stop
569 : * @return The named stop, or 0 if no such stop exists
570 : */
571 : MSStoppingPlace* getStoppingPlace(const std::string& id, const SumoXMLTag category) const;
572 :
573 : /** @brief Returns the named stopping place by looking through all categories
574 : * @param[in] id The id of the stop to return.
575 : * @return The named stop, or 0 if no such stop exists
576 : */
577 : MSStoppingPlace* getStoppingPlace(const std::string& id) const;
578 :
579 : /** @brief Returns the stop of the given category close to the given position
580 : * @param[in] lane the lane of the stop to return.
581 : * @param[in] pos the position of the stop to return.
582 : * @param[in] category The type of stop
583 : * @return The stop id on the location, or "" if no such stop exists
584 : */
585 : std::string getStoppingPlaceID(const MSLane* lane, const double pos, const SumoXMLTag category) const;
586 : /// @}
587 :
588 : const NamedObjectCont<MSStoppingPlace*>& getStoppingPlaces(SumoXMLTag category) const;
589 :
590 : /// @brief write charging station output
591 : void writeChargingStationOutput() const;
592 :
593 : /// @brief write rail signal block output
594 : void writeRailSignalBlocks() const;
595 :
596 : /// @brief creates a wrapper for the given logic (see GUINet)
597 57 : virtual void createTLWrapper(MSTrafficLightLogic*) {};
598 :
599 : /// @brief write the output generated by an overhead wire segment
600 : void writeOverheadWireSegmentOutput() const;
601 :
602 : /// @brief write electrical substation output
603 : void writeSubstationOutput() const;
604 :
605 : /// @brief return wheter the given logic (or rather its wrapper) is selected in the GUI
606 0 : virtual bool isSelected(const MSTrafficLightLogic*) const {
607 0 : return false;
608 : }
609 : /// @brief update view after simulation.loadState
610 143 : virtual void updateGUI() const { }
611 :
612 : /// @brief load state from file and return new time
613 : SUMOTime loadState(const std::string& fileName, const bool catchExceptions);
614 :
615 : /// @brief reset state to the beginning without reloading the network
616 : void quickReload();
617 :
618 : /// @name Notification about vehicle state changes
619 : /// @{
620 :
621 : /// @brief Definition of a vehicle state
622 : enum class VehicleState {
623 : /// @brief The vehicle was built, but has not yet departed
624 : BUILT,
625 : /// @brief The vehicle has departed (was inserted into the network)
626 : DEPARTED,
627 : /// @brief The vehicle started to teleport
628 : STARTING_TELEPORT,
629 : /// @brief The vehicle ended being teleported
630 : ENDING_TELEPORT,
631 : /// @brief The vehicle arrived at his destination (is deleted)
632 : ARRIVED,
633 : /// @brief The vehicle got a new route
634 : NEWROUTE,
635 : /// @brief The vehicles starts to park
636 : STARTING_PARKING,
637 : /// @brief The vehicle ends to park
638 : ENDING_PARKING,
639 : /// @brief The vehicles starts to stop
640 : STARTING_STOP,
641 : /// @brief The vehicle ends to stop
642 : ENDING_STOP,
643 : /// @brief The vehicle is involved in a collision
644 : COLLISION,
645 : /// @brief The vehicle had to brake harder than permitted
646 : EMERGENCYSTOP,
647 : /// @brief Vehicle maneuvering either entering or exiting a parking space
648 : MANEUVERING
649 : };
650 :
651 :
652 : /** @class VehicleStateListener
653 : * @brief Interface for objects listening to vehicle state changes
654 : */
655 : class VehicleStateListener {
656 : public:
657 : /// @brief Constructor
658 3785 : VehicleStateListener() { }
659 :
660 : /// @brief Destructor
661 : virtual ~VehicleStateListener() { }
662 :
663 : /** @brief Called if a vehicle changes its state
664 : * @param[in] vehicle The vehicle which changed its state
665 : * @param[in] to The state the vehicle has changed to
666 : * @param[in] info Additional information on the state change
667 : */
668 : virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info = "") = 0;
669 :
670 : };
671 :
672 :
673 : /** @brief Adds a vehicle states listener
674 : * @param[in] listener The listener to add
675 : */
676 : void addVehicleStateListener(VehicleStateListener* listener);
677 :
678 :
679 : /** @brief Removes a vehicle states listener
680 : * @param[in] listener The listener to remove
681 : */
682 : void removeVehicleStateListener(VehicleStateListener* listener);
683 :
684 :
685 : /** @brief Informs all added listeners about a vehicle's state change
686 : * @param[in] vehicle The vehicle which changed its state
687 : * @param[in] to The state the vehicle has changed to
688 : * @param[in] info Information regarding the replacement
689 : * @see VehicleStateListener:vehicleStateChanged
690 : */
691 : void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info = "");
692 : /// @}
693 :
694 :
695 : /// @name Notification about transportable state changes
696 : /// @{
697 :
698 : /// @brief Definition of a transportable state
699 : enum class TransportableState {
700 : /// @brief The transportable person has departed (was inserted into the network)
701 : PERSON_DEPARTED,
702 : /// @brief The transportable person arrived at his destination (is deleted)
703 : PERSON_ARRIVED,
704 : /// @brief The transportable container has departed (was inserted into the network)
705 : CONTAINER_DEPARTED,
706 : /// @brief The transportable container arrived at his destination (is deleted)
707 : CONTAINER_ARRIVED
708 : };
709 :
710 :
711 : /** @class TransportableStateListener
712 : * @brief Interface for objects listening to transportable state changes
713 : */
714 : class TransportableStateListener {
715 : public:
716 : /// @brief Constructor
717 2551 : TransportableStateListener() { }
718 :
719 : /// @brief Destructor
720 : virtual ~TransportableStateListener() { }
721 :
722 : /** @brief Called if a transportable changes its state
723 : * @param[in] transportable The transportable which changed its state
724 : * @param[in] to The state the transportable has changed to
725 : * @param[in] info Additional information on the state change
726 : */
727 : virtual void transportableStateChanged(const MSTransportable* const transportable, TransportableState to, const std::string& info = "") = 0;
728 :
729 : };
730 :
731 :
732 : /** @brief Adds a transportable states listener
733 : * @param[in] listener The listener to add
734 : */
735 : void addTransportableStateListener(TransportableStateListener* listener);
736 :
737 :
738 : /** @brief Removes a transportable states listener
739 : * @param[in] listener The listener to remove
740 : */
741 : void removeTransportableStateListener(TransportableStateListener* listener);
742 :
743 :
744 : /** @brief Informs all added listeners about a transportable's state change
745 : * @param[in] transportable The transportable which changed its state
746 : * @param[in] to The state the transportable has changed to
747 : * @param[in] info Information regarding the replacement
748 : * @see TransportableStateListener:TransportableStateChanged
749 : */
750 : void informTransportableStateListener(const MSTransportable* const transportable, TransportableState to, const std::string& info = "");
751 : /// @}
752 :
753 :
754 : /// @brief register collision and return whether it was the first one involving these vehicles
755 : bool registerCollision(const SUMOTrafficObject* collider, const SUMOTrafficObject* victim, const std::string& collisionType, const MSLane* lane, double pos);
756 :
757 : const CollisionMap& getCollisions() const {
758 : return myCollisions;
759 : }
760 :
761 :
762 : /** @brief Returns the travel time to pass an edge
763 : * @param[in] e The edge for which the travel time to be passed shall be returned
764 : * @param[in] v The vehicle that is rerouted
765 : * @param[in] t The time for which the travel time shall be returned [s]
766 : * @return The travel time for an edge
767 : * @see DijkstraRouter_ByProxi
768 : */
769 : static double getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, double t);
770 :
771 :
772 : /** @brief Returns the effort to pass an edge
773 : * @param[in] e The edge for which the effort to be passed shall be returned
774 : * @param[in] v The vehicle that is rerouted
775 : * @param[in] t The time for which the effort shall be returned [s]
776 : * @return The effort (abstract) for an edge
777 : * @see DijkstraRouter_ByProxi
778 : */
779 : static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
780 :
781 :
782 : /* @brief get the router, initialize on first use
783 : * @param[in] prohibited The vector of forbidden edges (optional)
784 : */
785 : MSVehicleRouter& getRouterTT(int rngIndex, const Prohibitions& prohibited = {}) const;
786 : MSVehicleRouter& getRouterEffort(int rngIndex, const Prohibitions& prohibited = {}) const;
787 : MSPedestrianRouter& getPedestrianRouter(int rngIndex, const Prohibitions& prohibited = {}) const;
788 : MSTransportableRouter& getIntermodalRouter(int rngIndex, const int routingMode = 0, const Prohibitions& prohibited = {}) const;
789 :
790 : static void adaptIntermodalRouter(MSTransportableRouter& router);
791 :
792 :
793 : /// @brief return whether the network contains internal links
794 : bool hasInternalLinks() const {
795 292734 : return myHasInternalLinks;
796 : }
797 :
798 : /// @brief return whether the network was built with higher junction speeds
799 : bool hasJunctionHigherSpeeds() const {
800 20 : return myJunctionHigherSpeeds;
801 : }
802 :
803 : /// @brief return whether the network contains elevation data
804 : bool hasElevation() const {
805 1522129753 : return myHasElevation;
806 : }
807 :
808 : /// @brief return whether the network contains walkingareas and crossings
809 : bool hasPedestrianNetwork() const {
810 123846 : return myHasPedestrianNetwork;
811 :
812 : }
813 : /// @brief return whether the network contains bidirectional rail edges
814 : bool hasBidiEdges() const {
815 101987 : return myHasBidiEdges;
816 : }
817 :
818 : /// @brief return the network version
819 : MMVersion getNetworkVersion() const {
820 5408 : return myVersion;
821 : }
822 :
823 : /// @brief return whether a warning regarding the given object shall be issued
824 : bool warnOnce(const std::string& typeAndID);
825 :
826 : void interrupt() {
827 5 : myAmInterrupted = true;
828 5 : }
829 :
830 : bool isInterrupted() const {
831 5 : return myAmInterrupted;
832 : }
833 :
834 : /// @brief gui may prevent final meanData reset to keep live data visible
835 16739700 : virtual bool skipFinalReset() const {
836 16739700 : return false;
837 : }
838 :
839 : MSMapMatcher* getMapMatcher() const;
840 :
841 : /// @brief find electrical substation by its id
842 : MSTractionSubstation* findTractionSubstation(const std::string& substationId);
843 :
844 : /// @brief return whether given electrical substation exists in the network
845 : bool existTractionSubstation(const std::string& substationId);
846 :
847 : /// @brief string constants for simstep stages
848 : static const std::string STAGE_EVENTS;
849 : static const std::string STAGE_MOVEMENTS;
850 : static const std::string STAGE_LANECHANGE;
851 : static const std::string STAGE_INSERTIONS;
852 : static const std::string STAGE_REMOTECONTROL;
853 :
854 : protected:
855 : /// @brief check all lanes for elevation data
856 : bool checkElevation();
857 :
858 : /// @brief check all lanes for type walkingArea
859 : bool checkWalkingarea();
860 :
861 : /// @brief check wether bidirectional edges occur in the network
862 : bool checkBidiEdges();
863 :
864 : /// @brief remove collisions from the previous simulation step
865 : void removeOutdatedCollisions();
866 :
867 : /** @brief Performs the parts of the simulation step which happen after the move
868 : */
869 : void postMoveStep();
870 :
871 : protected:
872 : /// @brief Unique instance of MSNet
873 : static MSNet* myInstance;
874 :
875 : /// @brief Route loader for dynamic loading of routes
876 : SUMORouteLoaderControl* myRouteLoaders;
877 :
878 : /// @brief Current time step
879 : SUMOTime myStep;
880 :
881 : /// @brief whether libsumo triggered a partial step (executeMove)
882 : bool myStepCompletionMissing = false;
883 :
884 : /// @brief Maximum number of teleports.
885 : int myMaxTeleports;
886 :
887 : /// @brief whether an interrupt occurred
888 : bool myAmInterrupted;
889 :
890 :
891 :
892 : /// @name Substructures
893 : /// @{
894 :
895 : /// @brief Controls vehicle building and deletion; @see MSVehicleControl
896 : MSVehicleControl* myVehicleControl;
897 : /// @brief Controls person building and deletion; @see MSTransportableControl
898 : MSTransportableControl* myPersonControl;
899 : /// @brief Controls container building and deletion; @see MSTransportableControl
900 : MSTransportableControl* myContainerControl;
901 : /// @brief Controls edges, performs vehicle movement; @see MSEdgeControl
902 : MSEdgeControl* myEdges;
903 : /// @brief Controls junctions, realizes right-of-way rules; @see MSJunctionControl
904 : MSJunctionControl* myJunctions;
905 : /// @brief Controls tls logics, realizes waiting on tls rules; @see MSJunctionControl
906 : MSTLLogicControl* myLogics;
907 : /// @brief Controls vehicle insertion; @see MSInsertionControl
908 : MSInsertionControl* myInserter;
909 : /// @brief Controls detectors; @see MSDetectorControl
910 : MSDetectorControl* myDetectorControl;
911 : /// @brief Controls events executed at the begin of a time step; @see MSEventControl
912 : MSEventControl* myBeginOfTimestepEvents;
913 : /// @brief Controls events executed at the end of a time step; @see MSEventControl
914 : MSEventControl* myEndOfTimestepEvents;
915 : /// @brief Controls insertion events; @see MSEventControl
916 : MSEventControl* myInsertionEvents;
917 : /// @brief A container for geometrical shapes; @see ShapeContainer
918 : ShapeContainer* myShapeContainer;
919 : /// @brief The net's knowledge about edge efforts/travel times; @see MSEdgeWeightsStorage
920 : MSEdgeWeightsStorage* myEdgeWeights;
921 : /// @}
922 :
923 :
924 :
925 : /// @name data needed for computing performance values
926 : /// @{
927 :
928 : /// @brief Information whether the simulation duration shall be logged
929 : bool myLogExecutionTime;
930 :
931 : /// @brief Information whether the number of the simulation step shall be logged
932 : bool myLogStepNumber;
933 : /// @brief Period between successive step-log outputs
934 : int myLogStepPeriod;
935 :
936 : /// @brief The last simulation step duration
937 : long myTraCIStepDuration = 0, mySimStepDuration = 0;
938 :
939 : /// @brief The overall simulation duration
940 : long mySimBeginMillis;
941 :
942 : /// @brief The overall time spent waiting for traci operations including
943 : long myTraCIMillis;
944 :
945 : /// @brief The overall number of vehicle movements
946 : long long int myVehiclesMoved;
947 : long long int myPersonsMoved;
948 : //}
949 :
950 :
951 :
952 : /// @name State output variables
953 : /// @{
954 :
955 : /// @brief Times at which a state shall be written
956 : std::vector<SUMOTime> myStateDumpTimes;
957 : /// @brief The names for the state files
958 : std::vector<std::string> myStateDumpFiles;
959 : /// @brief The names of the last K periodic state files (only only K shall be kept)
960 : std::vector<std::string> myPeriodicStateFiles;
961 : /// @brief The period for writing state
962 : SUMOTime myStateDumpPeriod;
963 : /// @brief name components for periodic state
964 : std::string myStateDumpPrefix;
965 : std::string myStateDumpSuffix;
966 : /// @}
967 :
968 :
969 :
970 : /// @brief Whether the network contains edges which not all vehicles may pass
971 : bool myHavePermissions;
972 :
973 : /// @brief The vehicle class specific speed restrictions
974 : std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
975 :
976 : /// @brief Preferences for routing
977 : std::map<SUMOVehicleClass, std::map<std::string, double> > myVClassPreferences;
978 : std::map<std::string, std::map<std::string, double> > myVTypePreferences;
979 :
980 : /// @brief The edge type specific meso parameters
981 : std::map<std::string, MESegment::MesoEdgeType> myMesoEdgeTypes;
982 :
983 : /// @brief Whether the network contains internal links/lanes/edges
984 : bool myHasInternalLinks;
985 :
986 : /// @brief Whether the network was built with higher speed on junctions
987 : bool myJunctionHigherSpeeds;
988 :
989 : /// @brief Whether the network contains elevation data
990 : bool myHasElevation;
991 :
992 : /// @brief Whether the network contains pedestrian network elements
993 : bool myHasPedestrianNetwork;
994 :
995 : /// @brief Whether the network contains bidirectional rail edges
996 : bool myHasBidiEdges;
997 :
998 : /// @brief Whether the network was built for left-hand traffic
999 : bool myLefthand;
1000 :
1001 : /// @brief the network version
1002 : MMVersion myVersion;
1003 :
1004 : /// @brief end of loaded edgeData
1005 : SUMOTime myEdgeDataEndTime;
1006 :
1007 : /// @brief Dictionary of bus / container stops
1008 : std::map<SumoXMLTag, NamedObjectCont<MSStoppingPlace*> > myStoppingPlaces;
1009 :
1010 : /// @brief Dictionary of traction substations
1011 : std::vector<MSTractionSubstation*> myTractionSubstations;
1012 :
1013 : /// @brief Container for vehicle state listener
1014 : std::vector<VehicleStateListener*> myVehicleStateListeners;
1015 :
1016 : /// @brief Container for transportable state listener
1017 : std::vector<TransportableStateListener*> myTransportableStateListeners;
1018 :
1019 : /// @brief collisions in the current time step
1020 : CollisionMap myCollisions;
1021 :
1022 : #ifdef HAVE_FOX
1023 : /// @brief to avoid concurrent access to the state update function
1024 : FXMutex myVehicleStateListenerMutex;
1025 :
1026 : /// @brief to avoid concurrent access to the state update function
1027 : FXMutex myTransportableStateListenerMutex;
1028 : #endif
1029 : static const NamedObjectCont<MSStoppingPlace*> myEmptyStoppingPlaceCont;
1030 :
1031 : /// @brief container to record warnings that shall only be issued once
1032 : std::map<std::string, bool> myWarnedOnce;
1033 :
1034 : /* @brief The router instance for routing by trigger and by traci
1035 : * @note MSDevice_Routing has its own instance since it uses a different weight function
1036 : * @note we provide one member for every switchable router type
1037 : * because the class structure makes it inconvenient to use a superclass
1038 : */
1039 : mutable std::map<int, MSVehicleRouter*> myRouterTT;
1040 : mutable std::map<int, MSVehicleRouter*> myRouterEffort;
1041 : mutable std::map<int, MSPedestrianRouter*> myPedestrianRouter;
1042 : mutable std::map<int, MSTransportableRouter*> myIntermodalRouter;
1043 :
1044 : /// @brief An RTree structure holding lane IDs
1045 : mutable std::pair<bool, NamedRTree> myLanesRTree;
1046 :
1047 : /// @brief Updater for dynamic shapes that are tracking traffic objects
1048 : /// (ensures removal of shape dynamics when the objects are removed)
1049 : /// @see utils/shapes/PolygonDynamics
1050 : std::unique_ptr<MSDynamicShapeUpdater> myDynamicShapeUpdater;
1051 :
1052 : private:
1053 : /// @brief Invalidated copy constructor.
1054 : MSNet(const MSNet&);
1055 :
1056 : /// @brief Invalidated assignment operator.
1057 : MSNet& operator=(const MSNet&);
1058 :
1059 :
1060 : };
|