SUMO - Simulation of Urban MObility
GUIVehicleControl.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // The class responsible for building and deletion of vehicles (gui-version)
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
34 #include "GUIVehicleControl.h"
35 #include "GUIVehicle.h"
36 #include "GUINet.h"
37 #include <gui/GUIGlobals.h>
38 
39 #ifdef CHECK_MEMORY_LEAKS
40 #include <foreign/nvwa/debug_new.h>
41 #endif // CHECK_MEMORY_LEAKS
42 
43 
44 // ===========================================================================
45 // member method definitions
46 // ===========================================================================
48  : MSVehicleControl() {}
49 
50 
52  // just to quit cleanly on a failure
53  if (myLock.locked()) {
54  myLock.unlock();
55  }
56 }
57 
58 
61  const MSRoute* route, const MSVehicleType* type) {
62  myLoadedVehNo++;
63  if (myMaxRandomDepartOffset > 0) {
64  // round to the closest usable simulation step
66  }
67  MSVehicle* built = new GUIVehicle(defs, route, type, type->computeChosenSpeedDeviation(myVehicleParamsRNG));
69  return built;
70 }
71 
72 
73 bool
74 GUIVehicleControl::addVehicle(const std::string& id, SUMOVehicle* v) {
76  return MSVehicleControl::addVehicle(id, v);
77 }
78 
79 
80 void
83  MSVehicleControl::deleteVehicle(veh, discard);
84 }
85 
86 
87 void
88 GUIVehicleControl::insertVehicleIDs(std::vector<GUIGlID>& into) {
90  into.reserve(myVehicleDict.size());
91  for (VehicleDictType::iterator i = myVehicleDict.begin(); i != myVehicleDict.end(); ++i) {
92  SUMOVehicle* veh = (*i).second;
93  if (veh->isOnRoad()) {
94  into.push_back(static_cast<GUIVehicle*>((*i).second)->getGlID());
95  }
96  }
97 }
98 
99 
100 void
102  myLock.lock();
103 }
104 
105 
106 void
108  myLock.unlock();
109 }
110 
111 
112 
113 /****************************************************************************/
114 
double rand()
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
MFXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
GUIVehicleControl()
Constructor.
void releaseVehicles()
unlock access to vehicle removal/additions for thread synchronization
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
VehicleDictType myVehicleDict
Dictionary of vehicles.
virtual bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
The car-following model and parameter.
Definition: MSVehicleType.h:74
Representation of a vehicle.
Definition: SUMOVehicle.h:64
SUMOTime depart
The vehicle's departure time.
bool addVehicle(const std::string &id, SUMOVehicle *v)
Tries to insert the vehicle into the internal vehicle container.
SUMOTime myMaxRandomDepartOffset
The maximum random offset to be added to vehicles departure times (non-negative)
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
static MTRand myVehicleParamsRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, const MSRoute *route, const MSVehicleType *type)
Builds a vehicle, increases the number of built vehicles.
SUMOReal computeChosenSpeedDeviation(MTRand &rng, const SUMOReal minDevFactor=0.2) const
Computes and returns the speed deviation.
The vehicle was built, but has not yet departed.
Definition: MSNet.h:425
void unlock()
release mutex lock
Definition: MFXMutex.cpp:96
Structure representing possible vehicle parameter.
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:71
void secureVehicles()
lock access to vehicle removal/additions for thread synchronization
void lock()
lock mutex
Definition: MFXMutex.cpp:86
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle's state change.
Definition: MSNet.cpp:693
~GUIVehicleControl()
Destructor.
void deleteVehicle(SUMOVehicle *v, bool discard=false)
Deletes the vehicle.
void insertVehicleIDs(std::vector< GUIGlID > &into)
Returns the list of all known vehicles by gl-id.
FXbool locked()
Definition: MFXMutex.h:70
#define DELTA_T
Definition: SUMOTime.h:50
The class responsible for building and deletion of vehicles.
unsigned int myLoadedVehNo
The number of build vehicles.
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:68