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.sourceforge.net/
16 // Copyright (C) 2001-2012 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;
76 class MSRouteLoader;
78 class SUMOVehicle;
79 #ifdef _MESSAGES
80 class MSMessageEmitter;
81 #endif
82 
83 
84 // ===========================================================================
85 // class definitions
86 // ===========================================================================
91 class MSNet {
92 public:
109  };
110 
111 
112 public:
117  static MSNet* getInstance();
118 
119 
134  MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
135  MSEventControl* endOfTimestepEvents, MSEventControl* insertionEvents,
136  ShapeContainer* shapeCont = 0);
137 
138 
140  virtual ~MSNet();
141 
142 
154  void closeBuilding(MSEdgeControl* edges, MSJunctionControl* junctions,
155  MSRouteLoaderControl* routeLoaders, MSTLLogicControl* tlc,
156  std::vector<SUMOTime> stateDumpTimes, std::vector<std::string> stateDumpFiles);
157 
158 
162  static void clearAll();
163 
164 
172  int simulate(SUMOTime start, SUMOTime stop);
173 
174 
178  void simulationStep();
179 
180 
188  void closeSimulation(SUMOTime start);
189 
190 
196  SimulationState simulationState(SUMOTime stopTime) const;
197 
198 
202  static std::string getStateMessage(SimulationState state);
203 
204 
209 
210 
214  void writeOutput();
215 
216 
220  bool logSimulationDuration() const;
221 
222 
224 
225 
230  void preSimStepOutput() const;
231 
232 
237  void postSimStepOutput() const;
238  //}
239 
240 
241 
242 #ifdef HAVE_INTERNAL
243 
244 
245 
250  void saveState(std::ostream& os);
251 
252 
257  SUMOTime loadState(BinaryInputDevice& bis);
259 #endif
260 
263 
270  return *myVehicleControl;
271  }
272 
273 
283 
284 
291  return *myEdges;
292  }
293 
294 
301  return *myInserter;
302  }
303 
304 
311  return *myDetectorControl;
312  }
313 
314 
321  return *myLogics;
322  }
323 
324 
331  return *myJunctions;
332  }
333 
334 
341  return *myBeginOfTimestepEvents;
342  }
343 
344 
351  return *myEndOfTimestepEvents;
352  }
353 
354 
361  return *myInsertionEvents;
362  }
363 
364 
371  return *myShapeContainer;
372  }
373 
374 
382 
383 
384 
387 
399  bool addBusStop(MSBusStop* busStop);
400 
401 
406  MSBusStop* getBusStop(const std::string& id) const;
407 
408 
414  std::string getBusStopID(const MSLane* lane, const SUMOReal pos) const;
416 
417 
418 
419 
420 
421 
424 
439  };
440 
441 
446  public:
449 
451  virtual ~VehicleStateListener() { }
452 
457  virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to) = 0;
458 
459  };
460 
461 
465  void addVehicleStateListener(VehicleStateListener* listener);
466 
467 
471  void removeVehicleStateListener(VehicleStateListener* listener);
472 
473 
479  void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to);
481 
482 
490  static SUMOReal getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
491 
492 
500  static SUMOReal getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
501 
502 
503  /* @brief get the router, initialize on first use
504  * @param[in] prohibited The vector of forbidden edges (optional)
505  */
507  const std::vector<MSEdge*>& prohibited = std::vector<MSEdge*>()) const;
509  const std::vector<MSEdge*>& prohibited = std::vector<MSEdge*>()) const;
510 
511 
512 #ifdef _MESSAGES
513 
514  typedef NamedObjectCont< MSMessageEmitter* > MsgEmitterDict;
515 
516  // TODO
523  MSMessageEmitter* getMsgEmitter(const std::string& whatemit);
524 
529  void createMsgEmitter(std::string& id,
530  std::string& file,
531  const std::string& base,
532  std::string& whatemit,
533  bool reverse,
534  bool table,
535  bool xy,
536  SUMOReal step);
537 #endif
538 
539 protected:
541  static MSNet* myInstance;
542 
545 
548 
549 
550 
553 
579 
580 
581 
584 
587 
590 
593 
596 
599  //}
600 
601 
602 
605 
607  std::vector<SUMOTime> myStateDumpTimes;
609  std::vector<std::string> myStateDumpFiles;
611 
612 
615 
616 
619 
621  std::vector<VehicleStateListener*> myVehicleStateListeners;
622 
623 
624 #ifdef _MESSAGES
625 
626  MsgEmitterDict myMsgEmitter;
627 
629  std::vector<MSMessageEmitter*> msgEmitVec;
630 #endif
631 
632  /* @brief The router instance for routing by trigger and by traci
633  * @note MSDevice_Routing has its own instance since it uses a different weight function
634  * @note we provide one member for every switchable router type
635  * because the class structure makes it inconvenient to use a superclass*/
636  mutable bool myRouterTTInitialized;
640 
641 
642 private:
644  MSNet(const MSNet&);
645 
647  MSNet& operator=(const MSNet&);
648 
649 
650 };
651 
652 
653 #endif
654 
655 /****************************************************************************/
656