SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSNet.h
Go to the documentation of this file.
1 /****************************************************************************/
13 // The simulated network and simulation perfomer
14 /****************************************************************************/
15 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
16 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
26 #ifndef MSNet_h
27 #define MSNet_h
28 
29 
30 // ===========================================================================
31 // included modules
32 // ===========================================================================
33 #ifdef _MSC_VER
34 #include <windows_config.h>
35 #else
36 #include <config.h>
37 #endif
38 
39 #include <typeinfo>
40 #include <vector>
41 #include <map>
42 #include <string>
43 #include <fstream>
44 #include <iostream>
45 #include <cmath>
46 #include <iomanip>
47 #include "MSVehicleControl.h"
48 #include "MSEventControl.h"
49 #include <utils/geom/Boundary.h>
50 #include <utils/geom/Position.h>
51 #include <utils/common/SUMOTime.h>
59 
60 // ===========================================================================
61 // class declarations
62 // ===========================================================================
63 class MSEdge;
64 class MSEdgeControl;
65 class MSJunctionControl;
66 class MSInsertionControl;
68 class MSPersonControl;
69 class MSVehicle;
70 class MSRoute;
71 class MSLane;
72 class MSTLLogicControl;
73 class MSDetectorControl;
74 class ShapeContainer;
75 class BinaryInputDevice;
77 class SUMOVehicle;
78 
79 
80 // ===========================================================================
81 // class definitions
82 // ===========================================================================
87 class MSNet {
88 public:
105  };
106 
107 
108 public:
113  static MSNet* getInstance();
114 
115 
130  MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
131  MSEventControl* endOfTimestepEvents, MSEventControl* insertionEvents,
132  ShapeContainer* shapeCont = 0);
133 
134 
136  virtual ~MSNet();
137 
138 
150  void closeBuilding(MSEdgeControl* edges, MSJunctionControl* junctions,
151  SUMORouteLoaderControl* routeLoaders, MSTLLogicControl* tlc,
152  std::vector<SUMOTime> stateDumpTimes, std::vector<std::string> stateDumpFiles);
153 
154 
158  static void clearAll();
159 
160 
168  int simulate(SUMOTime start, SUMOTime stop);
169 
170 
174  void simulationStep();
175 
177  void loadRoutes();
178 
179 
187  void closeSimulation(SUMOTime start);
188 
189 
195  SimulationState simulationState(SUMOTime stopTime) const;
196 
197 
201  static std::string getStateMessage(SimulationState state);
202 
203 
208 
209 
213  void writeOutput();
214 
215 
219  bool logSimulationDuration() const;
220 
221 
223 
224 
229  void preSimStepOutput() const;
230 
231 
236  void postSimStepOutput() const;
237  //}
238 
239 
242 
249  return *myVehicleControl;
250  }
251 
252 
262 
263 
270  return *myEdges;
271  }
272 
273 
280  return *myInserter;
281  }
282 
283 
290  return *myDetectorControl;
291  }
292 
293 
300  return *myLogics;
301  }
302 
303 
310  return *myJunctions;
311  }
312 
313 
320  return *myBeginOfTimestepEvents;
321  }
322 
323 
330  return *myEndOfTimestepEvents;
331  }
332 
333 
340  return *myInsertionEvents;
341  }
342 
343 
350  return *myShapeContainer;
351  }
352 
353 
361 
362 
363 
366 
378  bool addBusStop(MSBusStop* busStop);
379 
380 
385  MSBusStop* getBusStop(const std::string& id) const;
386 
387 
393  std::string getBusStopID(const MSLane* lane, const SUMOReal pos) const;
395 
396 
397 
398 
399 
400 
403 
418  };
419 
420 
425  public:
428 
430  virtual ~VehicleStateListener() { }
431 
436  virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to) = 0;
437 
438  };
439 
440 
444  void addVehicleStateListener(VehicleStateListener* listener);
445 
446 
450  void removeVehicleStateListener(VehicleStateListener* listener);
451 
452 
458  void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to);
460 
461 
469  static SUMOReal getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
470 
471 
479  static SUMOReal getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
480 
481 
482  /* @brief get the router, initialize on first use
483  * @param[in] prohibited The vector of forbidden edges (optional)
484  */
486  const std::vector<MSEdge*>& prohibited = std::vector<MSEdge*>()) const;
488  const std::vector<MSEdge*>& prohibited = std::vector<MSEdge*>()) const;
489 
490 
491 protected:
493  static MSNet* myInstance;
494 
497 
500 
501 
502 
505 
531 
532 
533 
536 
539 
542 
545 
548 
551  //}
552 
553 
554 
557 
559  std::vector<SUMOTime> myStateDumpTimes;
561  std::vector<std::string> myStateDumpFiles;
563 
564 
567 
568 
571 
573  std::vector<VehicleStateListener*> myVehicleStateListeners;
574 
575 
576  /* @brief The router instance for routing by trigger and by traci
577  * @note MSDevice_Routing has its own instance since it uses a different weight function
578  * @note we provide one member for every switchable router type
579  * because the class structure makes it inconvenient to use a superclass*/
580  mutable bool myRouterTTInitialized;
584 
585 
586 private:
588  MSNet(const MSNet&);
589 
591  MSNet& operator=(const MSNet&);
592 
593 
594 };
595 
596 
597 #endif
598 
599 /****************************************************************************/
600