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>
55 
56 // ===========================================================================
57 // class declarations
58 // ===========================================================================
59 class MSEdge;
60 class MSEdgeControl;
61 class MSJunctionControl;
62 class MSInsertionControl;
64 class MSPersonControl;
65 class MSVehicle;
66 class MSRoute;
67 class MSLane;
68 class MSTLLogicControl;
69 class MSDetectorControl;
70 class ShapeContainer;
71 class BinaryInputDevice;
72 class MSRouteLoader;
74 class SUMOVehicle;
75 #ifdef _MESSAGES
76 class MSMessageEmitter;
77 #endif
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  MSRouteLoaderControl* 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 
176 
184  void closeSimulation(SUMOTime start);
185 
186 
192  SimulationState simulationState(SUMOTime stopTime) const ;
193 
194 
198  static std::string getStateMessage(SimulationState state) ;
199 
200 
205 
206 
210  void writeOutput();
211 
212 
216  bool logSimulationDuration() const ;
217 
218 
220 
221 
226  void preSimStepOutput() const ;
227 
228 
233  void postSimStepOutput() const ;
234  //}
235 
236 
237 
238 #ifdef HAVE_MESOSIM
239 
240 
241 
246  void saveState(std::ostream& os) ;
247 
248 
253  unsigned int loadState(BinaryInputDevice& bis) ;
255 #endif
256 
259 
266  return *myVehicleControl;
267  }
268 
269 
279 
280 
287  return *myEdges;
288  }
289 
290 
297  return *myInserter;
298  }
299 
300 
307  return *myDetectorControl;
308  }
309 
310 
317  return *myLogics;
318  }
319 
320 
327  return *myJunctions;
328  }
329 
330 
337  return *myBeginOfTimestepEvents;
338  }
339 
340 
347  return *myEndOfTimestepEvents;
348  }
349 
350 
357  return *myInsertionEvents;
358  }
359 
360 
367  return *myShapeContainer;
368  }
369 
370 
378 
379 
380 
383 
395  bool addBusStop(MSBusStop* busStop);
396 
397 
402  MSBusStop* getBusStop(const std::string& id) const;
403 
404 
410  std::string getBusStopID(const MSLane* lane, const SUMOReal pos) const;
412 
413 
414 
415 
416 
417 
420 
435  };
436 
437 
442  public:
445 
447  virtual ~VehicleStateListener() { }
448 
453  virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to) = 0;
454 
455  };
456 
457 
461  void addVehicleStateListener(VehicleStateListener* listener) ;
462 
463 
467  void removeVehicleStateListener(VehicleStateListener* listener) ;
468 
469 
475  void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to) ;
477 
478 
489  public:
495  const MSEdgeWeightsStorage& netKnowledge)
496  : myVehicleKnowledge(vehKnowledge), myNetKnowledge(netKnowledge) {}
497 
498 
501 
502 
510  SUMOReal getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) const;
511 
512 
520  SUMOReal getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) const;
521 
522  private:
523  EdgeWeightsProxi& operator=(const EdgeWeightsProxi&); // just to avoid a compiler warning
524 
525  private:
528 
531 
532  };
533 
534 
535 #ifdef _MESSAGES
536 
537  typedef NamedObjectCont< MSMessageEmitter* > MsgEmitterDict;
538 
539  // TODO
546  MSMessageEmitter* getMsgEmitter(const std::string& whatemit);
547 
552  void createMsgEmitter(std::string& id,
553  std::string& file,
554  const std::string& base,
555  std::string& whatemit,
556  bool reverse,
557  bool table,
558  bool xy,
559  SUMOReal step);
560 #endif
561 
562 protected:
564  static MSNet* myInstance;
565 
568 
571 
572 
573 
576 
602 
603 
604 
607 
610 
613 
616 
619 
622  //}
623 
624 
625 
628 
630  std::vector<SUMOTime> myStateDumpTimes;
632  std::vector<std::string> myStateDumpFiles;
634 
635 
638 
639 
642 
644  std::vector<VehicleStateListener*> myVehicleStateListeners;
645 
646 
647 #ifdef _MESSAGES
648 
649  MsgEmitterDict myMsgEmitter;
650 
652  std::vector<MSMessageEmitter*> msgEmitVec;
653 #endif
654 
655 
656 private:
658  MSNet(const MSNet&);
659 
661  MSNet& operator=(const MSNet&);
662 
663 
664 };
665 
666 
667 #endif
668 
669 /****************************************************************************/
670