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>
60 
61 
62 // ===========================================================================
63 // class declarations
64 // ===========================================================================
65 class MSEdge;
66 class MSEdgeControl;
67 class MSJunctionControl;
68 class MSInsertionControl;
70 class MSPersonControl;
71 class MSVehicle;
72 class MSRoute;
73 class MSLane;
74 class MSTLLogicControl;
75 class MSDetectorControl;
76 class ShapeContainer;
77 class BinaryInputDevice;
79 class SUMOVehicle;
80 
81 
82 // ===========================================================================
83 // class definitions
84 // ===========================================================================
89 class MSNet {
90 public:
107  };
108 
109 
110 public:
115  static MSNet* getInstance();
116 
117 
132  MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
133  MSEventControl* endOfTimestepEvents, MSEventControl* insertionEvents,
134  ShapeContainer* shapeCont = 0);
135 
136 
138  virtual ~MSNet();
139 
140 
152  void closeBuilding(MSEdgeControl* edges, MSJunctionControl* junctions,
153  SUMORouteLoaderControl* routeLoaders, MSTLLogicControl* tlc,
154  std::vector<SUMOTime> stateDumpTimes, std::vector<std::string> stateDumpFiles);
155 
156 
160  static void clearAll();
161 
162 
170  int simulate(SUMOTime start, SUMOTime stop);
171 
172 
176  void simulationStep();
177 
178 
180  void loadRoutes();
181 
182 
190  void closeSimulation(SUMOTime start);
191 
192 
198  SimulationState simulationState(SUMOTime stopTime) const;
199 
200 
204  static std::string getStateMessage(SimulationState state);
205 
206 
211 
212 
216  void writeOutput();
217 
218 
222  bool logSimulationDuration() const;
223 
224 
225 
227 
228 
233  void preSimStepOutput() const;
234 
235 
240  void postSimStepOutput() const;
241  //}
242 
243 
244 
247 
254  return *myVehicleControl;
255  }
256 
257 
267 
268 
275  return *myEdges;
276  }
277 
278 
285  return *myInserter;
286  }
287 
288 
295  return *myDetectorControl;
296  }
297 
298 
305  return *myLogics;
306  }
307 
308 
315  return *myJunctions;
316  }
317 
318 
325  return *myBeginOfTimestepEvents;
326  }
327 
328 
335  return *myEndOfTimestepEvents;
336  }
337 
338 
345  return *myInsertionEvents;
346  }
347 
348 
355  return *myShapeContainer;
356  }
357 
358 
366 
367 
368 
371 
383  bool addBusStop(MSBusStop* busStop);
384 
385 
390  MSBusStop* getBusStop(const std::string& id) const;
391 
392 
398  std::string getBusStopID(const MSLane* lane, const SUMOReal pos) const;
400 
401 
402 
405 
428  };
429 
430 
435  public:
438 
440  virtual ~VehicleStateListener() { }
441 
446  virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to) = 0;
447 
448  };
449 
450 
454  void addVehicleStateListener(VehicleStateListener* listener);
455 
456 
460  void removeVehicleStateListener(VehicleStateListener* listener);
461 
462 
468  void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to);
470 
471 
472 
480  static SUMOReal getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
481 
482 
490  static SUMOReal getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
491 
492 
493  /* @brief get the router, initialize on first use
494  * @param[in] prohibited The vector of forbidden edges (optional)
495  */
497  const std::vector<MSEdge*>& prohibited = std::vector<MSEdge*>()) const;
499  const std::vector<MSEdge*>& prohibited = std::vector<MSEdge*>()) const;
500 
501 
505  const NamedRTree& getLanesRTree() const;
506 
507 
508 protected:
510  static MSNet* myInstance;
511 
514 
517 
518 
519 
522 
548 
549 
550 
553 
556 
559 
562 
565 
568  //}
569 
570 
571 
574 
576  std::vector<SUMOTime> myStateDumpTimes;
578  std::vector<std::string> myStateDumpFiles;
580 
581 
582 
585 
588 
590  std::vector<VehicleStateListener*> myVehicleStateListeners;
591 
592 
593  /* @brief The router instance for routing by trigger and by traci
594  * @note MSDevice_Routing has its own instance since it uses a different weight function
595  * @note we provide one member for every switchable router type
596  * because the class structure makes it inconvenient to use a superclass*/
597  mutable bool myRouterTTInitialized;
601 
602 
604  mutable std::pair<bool, NamedRTree> myLanesRTree;
605 
606 
607 private:
609  MSNet(const MSNet&);
610 
612  MSNet& operator=(const MSNet&);
613 
614 
615 };
616 
617 
618 #endif
619 
620 /****************************************************************************/
621