MSVehicleControl Class Reference

#include <MSVehicleControl.h>

Inheritance diagram for MSVehicleControl:

GUIVehicleControl

Detailed Description

The class responsible for building and deletion of vehicles.

This class is responsible for vehicle building and deletion. It stores vehicle types, vehicles and statistics about the last.

This class also realizes the tripinfos and the vehroutes - outputs, both generated when a vehicle is removed from the simulation, see scheduleVehicleRemoval.

Use this class for the pure microsim and GUIVehicleControl within the gui.

See also:
GUIVehicleControl

Definition at line 68 of file MSVehicleControl.h.


Vehicle type container

bool myDefaultVTypeMayBeDeleted
 Whether no vehicle type was loaded.
VTypeDictType myVTypeDict
 Dictionary of vehicle types.
VTypeDistDictType myVTypeDistDict
 A distribution of vehicle types (probability->vehicle type).
std::map< const MSEdge *const,
std::vector< MSVehicle * > > 
myWaiting
 the lists of waiting vehicles
typedef std::map< std::string,
MSVehicleType * > 
VTypeDictType
 Vehicle type dictionary type.
typedef std::map< std::string,
RandomDistributor
< MSVehicleType * > * > 
VTypeDistDictType
 Vehicle type distribution dictionary type.
 MSVehicleControl (const MSVehicleControl &s)
 invalidated copy constructor
MSVehicleControloperator= (const MSVehicleControl &s)
 invalidated assignment operator

Vehicle container

VehicleDictType myVehicleDict
 Dictionary of vehicles.
typedef std::map< std::string,
MSVehicle * > 
VehicleDictType
 Vehicle dictionary type.

Public Types

typedef std::map< std::string,
MSVehicle * >::const_iterator 
constVehIt
 Definition of the internal vehicles map iterator.

Public Member Functions

void addWaiting (const MSEdge *const edge, MSVehicle *vehicle) throw ()
MSVehiclegetWaitingVehicle (const MSEdge *const edge, const std::set< std::string > &lines) throw ()
 MSVehicleControl () throw ()
 Constructor.
void removeWaiting (const MSEdge *const edge, MSVehicle *vehicle) throw ()
virtual ~MSVehicleControl () throw ()
 Destructor.
Insertion, deletion and retrieal of vehicles
virtual bool addVehicle (const std::string &id, MSVehicle *v) throw ()
 Tries to insert the vehicle into the internal vehicle container.
virtual void deleteVehicle (MSVehicle *v) throw ()
 Deletes the vehicle.
virtual MSVehiclegetVehicle (const std::string &id) const throw ()
 Returns the vehicle with the given id.
constVehIt loadedVehBegin () const throw ()
 Returns the begin of the internal vehicle map.
constVehIt loadedVehEnd () const throw ()
 Returns the end of the internal vehicle map.
void scheduleVehicleRemoval (MSVehicle *v) throw ()
 Removes a vehicle after it has ended.
Insertion and retrieval of vehicle types
bool addVType (MSVehicleType *vehType) throw ()
 Adds a vehicle type.
bool addVTypeDistribution (const std::string &id, RandomDistributor< MSVehicleType * > *vehTypeDistribution) throw ()
 Adds a vehicle type distribution.
MSVehicleTypegetVType (const std::string &id=DEFAULT_VTYPE_ID) throw ()
 Returns the named vehicle type or a sample from the named distribution.
bool hasVTypeDistribution (const std::string &id) const throw ()
 Asks for a vehicle type distribution.
void insertVTypeIDs (std::vector< std::string > &into) const throw ()
 Inserts ids of all known vehicle types and vehicle type distributions to the given vector.
Vehicle creation
virtual MSVehiclebuildVehicle (SUMOVehicleParameter *defs, const MSRoute *route, const MSVehicleType *type) throw (ProcessError)
 Builds a vehicle, increases the number of built vehicles.
Retrieval of vehicle statistics (always accessable)
unsigned int getEmittedVehicleNo () const throw ()
 Returns the number of emitted vehicles.
unsigned int getEndedVehicleNo () const throw ()
 Returns the number of removed vehicles.
unsigned int getLoadedVehicleNo () const throw ()
 Returns the number of build vehicles.
unsigned int getRunningVehicleNo () const throw ()
 Returns the number of build and emitted, but not yet deleted vehicles.
bool haveAllVehiclesQuit () const throw ()
 Returns the information whether all build vehicles have been removed.
Retrieval of vehicle statistics (availability depends on simulation settings)
SUMOReal getMeanTravelTime () const throw ()
 Returns the mean travel time of vehicles (corn-dependent value).
SUMOReal getMeanWaitingTime () const throw ()
 Returns the mean waiting time of vehicles (corn-dependent value).
Setting vehicle statistics
virtual void vehicleEmitted (const MSVehicle &v) throw ()
 Informs this control about a vehicle's emission.

Protected Attributes

Vehicle statistics (availability depends on simulation settings)
SUMOTime myAbsVehTravelTime
 The aggregated time vehicles needed to aacomplish their route.
SUMOTime myAbsVehWaitingTime
 The aggregated time vehicles had to wait for departure.
Vehicle statistics (always accessable)
unsigned int myEndedVehNo
 The number of removed vehicles.
unsigned int myLoadedVehNo
 The number of build vehicles.
unsigned int myRunningVehNo
 The number of vehicles within the network (build and emitted but not removed).

Private Member Functions

bool checkVType (const std::string &id) throw ()
 Checks whether the vehicle type (distribution) may be added.

Member Typedef Documentation

typedef std::map<std::string, MSVehicle*>::const_iterator MSVehicleControl::constVehIt

Definition of the internal vehicles map iterator.

Definition at line 71 of file MSVehicleControl.h.

typedef std::map< std::string, MSVehicle* > MSVehicleControl::VehicleDictType [protected]

Vehicle dictionary type.

Definition at line 383 of file MSVehicleControl.h.

typedef std::map< std::string, MSVehicleType* > MSVehicleControl::VTypeDictType [protected]

Vehicle type dictionary type.

Definition at line 393 of file MSVehicleControl.h.

typedef std::map< std::string, RandomDistributor<MSVehicleType*>* > MSVehicleControl::VTypeDistDictType [protected]

Vehicle type distribution dictionary type.

Definition at line 398 of file MSVehicleControl.h.


Constructor & Destructor Documentation

MSVehicleControl::MSVehicleControl (  )  throw ()

Constructor.

Definition at line 55 of file MSVehicleControl.cpp.

References MSVehicleType::build(), DEFAULT_VTYPE_ID, and myVTypeDict.

MSVehicleControl::~MSVehicleControl (  )  throw () [virtual]

Destructor.

Definition at line 64 of file MSVehicleControl.cpp.

References myVehicleDict, myVTypeDict, and myVTypeDistDict.

00064                                             {
00065     // delete vehicles
00066     for (VehicleDictType::iterator i=myVehicleDict.begin(); i!=myVehicleDict.end(); ++i) {
00067         delete(*i).second;
00068     }
00069     myVehicleDict.clear();
00070     // delete vehicle type distributions
00071     for (VTypeDistDictType::iterator i=myVTypeDistDict.begin(); i!=myVTypeDistDict.end(); ++i) {
00072         delete(*i).second;
00073     }
00074     myVTypeDistDict.clear();
00075     // delete vehicle types
00076     for (VTypeDictType::iterator i=myVTypeDict.begin(); i!=myVTypeDict.end(); ++i) {
00077         delete(*i).second;
00078     }
00079     myVTypeDict.clear();
00080 }

MSVehicleControl::MSVehicleControl ( const MSVehicleControl s  )  [private]

invalidated copy constructor


Member Function Documentation

bool MSVehicleControl::addVehicle ( const std::string &  id,
MSVehicle v 
) throw () [virtual]

Tries to insert the vehicle into the internal vehicle container.

Checks whether another vehicle with the same id exists; returns false if so. Otherwise, the vehicle is added to "myVehicleDict" and true is returned.

The vehicle control gets responsible for vehicle deletion.

Parameters:
[in] id The id of the vehicle
[in] v The vehicle
Returns:
Whether the vehicle could be inserted (no other vehicle with the same id was inserted before)

Definition at line 432 of file MSVehicleControl.cpp.

References myVehicleDict.

Referenced by MSEmitControl::checkFlows(), MSEmitter::childCheckEmit(), MSCalibrator::childCheckEmit(), MSRouteHandler::closeVehicle(), and traci::TraCIServer::commandAddVehicle().

00432                                                                       {
00433     VehicleDictType::iterator it = myVehicleDict.find(id);
00434     if (it == myVehicleDict.end()) {
00435         // id not in myVehicleDict.
00436         myVehicleDict[id] = v;
00437         return true;
00438     }
00439     return false;
00440 }

bool MSVehicleControl::addVType ( MSVehicleType vehType  )  throw ()

Adds a vehicle type.

If another vehicle type (or distribution) with the same id exists, false is returned. Otherwise, the vehicle type is added to the internal vehicle type container "myVTypeDict".

This control get responsible for deletion of the added vehicle type.

Parameters:
[in] vehType The vehicle type to add
Returns:
Whether the vehicle type could be added

Definition at line 492 of file MSVehicleControl.cpp.

References checkVType(), and myVTypeDict.

00492                                                          {
00493     if (checkVType(vehType->getID())) {
00494         myVTypeDict[vehType->getID()] = vehType;
00495         return true;
00496     }
00497     return false;
00498 }

bool MSVehicleControl::addVTypeDistribution ( const std::string &  id,
RandomDistributor< MSVehicleType * > *  vehTypeDistribution 
) throw ()

Adds a vehicle type distribution.

If another vehicle type (or distribution) with the same id exists, false is returned. Otherwise, the vehicle type distribution is added to the internal vehicle type distribution container "myVTypeDistDict".

This control get responsible for deletion of the added vehicle type distribution.

Parameters:
[in] id The id of the distribution to add
[in] vehTypeDistribution The vehicle type distribution to add
Returns:
Whether the vehicle type could be added

Definition at line 502 of file MSVehicleControl.cpp.

References checkVType(), and myVTypeDistDict.

00502                                                                                                                           {
00503     if (checkVType(id)) {
00504         myVTypeDistDict[id] = vehTypeDistribution;
00505         return true;
00506     }
00507     return false;
00508 }

void MSVehicleControl::addWaiting ( const MSEdge *const   edge,
MSVehicle vehicle 
) throw ()

Definition at line 547 of file MSVehicleControl.cpp.

References myWaiting.

Referenced by MSRouteHandler::closeVehicle(), and MSVehicle::processNextStop().

00547                                                                                  {
00548     if (myWaiting.find(edge) == myWaiting.end()) {
00549         myWaiting[edge] = std::vector<MSVehicle*>();
00550     }
00551     myWaiting[edge].push_back(vehicle);
00552 }

MSVehicle * MSVehicleControl::buildVehicle ( SUMOVehicleParameter defs,
const MSRoute route,
const MSVehicleType type 
) throw (ProcessError) [virtual]

Builds a vehicle, increases the number of built vehicles.

Builds a MSVehicle instance using the given parameter. Increases the number of loaded vehicles ("myLoadedVehNo").

Parameters:
[in] id The id of the vehicle to build
[in] route The route of this vehicle
[in] departTime The departure time of this vehicle
[in] type The type of this vehicle
[in] repNo The number of repetitions
[in] repOffset The repetition offset
Returns:
The built vehicle (MSVehicle instance)

Reimplemented in GUIVehicleControl.

Definition at line 84 of file MSVehicleControl.cpp.

References MSNet::getInstance(), MSNet::informVehicleStateListener(), myLoadedVehNo, and MSNet::VEHICLE_STATE_BUILT.

Referenced by MSEmitter::MSEmitter_FileTriggeredChild::buildAndScheduleFlowVehicle(), MSCalibrator::MSCalibrator_FileTriggeredChild::buildAndScheduleFlowVehicle(), MSEmitControl::checkFlows(), MSRouteHandler::closeVehicle(), traci::TraCIServer::commandAddVehicle(), MSEmitter::MSEmitter_FileTriggeredChild::myStartElement(), MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement(), and GUIEmitter::GUIEmitterChild_UserTriggeredChild::wrappedExecute().

00086                                                                               {
00087     myLoadedVehNo++;
00088     MSVehicle *built = new MSVehicle(defs, route, type, myLoadedVehNo-1);
00089     MSNet::getInstance()->informVehicleStateListener(built, MSNet::VEHICLE_STATE_BUILT);
00090     return built;
00091 }

bool MSVehicleControl::checkVType ( const std::string &  id  )  throw () [private]

Checks whether the vehicle type (distribution) may be added.

Removed the vehicle from the internal dictionary

Parameters:
[in] id The id of the vehicle type (distribution) to add
Returns:
Whether the type (distribution) may be added

Definition at line 474 of file MSVehicleControl.cpp.

References DEFAULT_VTYPE_ID, myDefaultVTypeMayBeDeleted, myVTypeDict, and myVTypeDistDict.

Referenced by addVType(), and addVTypeDistribution().

00474                                                         {
00475     if (id == DEFAULT_VTYPE_ID) {
00476         if (myDefaultVTypeMayBeDeleted) {
00477             delete myVTypeDict[id];
00478             myVTypeDict.erase(myVTypeDict.find(id));
00479             myDefaultVTypeMayBeDeleted = false;
00480         } else {
00481             return false;
00482         }
00483     } else {
00484         if (myVTypeDict.find(id) != myVTypeDict.end() || myVTypeDistDict.find(id) != myVTypeDistDict.end()) {
00485             return false;
00486         }
00487     }
00488     return true;
00489 }

void MSVehicleControl::deleteVehicle ( MSVehicle v  )  throw () [virtual]

Deletes the vehicle.

Parameters:
[in] v The vehicle to delete
Todo:
Isn't this quite insecure?

Reimplemented in GUIVehicleControl.

Definition at line 454 of file MSVehicleControl.cpp.

References myVehicleDict.

Referenced by traci::TraCIServer::commandAddVehicle(), GUIVehicleControl::deleteVehicle(), scheduleVehicleRemoval(), and MSEmitControl::tryEmit().

00454                                                       {
00455     myEndedVehNo++;
00456     myVehicleDict.erase(veh->getID());
00457     delete veh;
00458 }

unsigned int MSVehicleControl::getEmittedVehicleNo (  )  const throw () [inline]

Returns the number of emitted vehicles.

Returns:
The number of vehicles that have entered the simulation so far

Definition at line 217 of file MSVehicleControl.h.

References myEndedVehNo, and myRunningVehNo.

Referenced by MSNet::closeSimulation(), getMeanWaitingTime(), GUINet::getParameterWindow(), MSNet::postSimStepOutput(), and MSNet::writeOutput().

00217                                                      {
00218         return myRunningVehNo + myEndedVehNo;
00219     }

unsigned int MSVehicleControl::getEndedVehicleNo (  )  const throw () [inline]

Returns the number of removed vehicles.

Returns:
The number of vehicles that have left the simulation

Definition at line 201 of file MSVehicleControl.h.

References myEndedVehNo.

Referenced by GUINet::getParameterWindow(), and MSNet::writeOutput().

00201                                                    {
00202         return myEndedVehNo;
00203     }

unsigned int MSVehicleControl::getLoadedVehicleNo (  )  const throw () [inline]

Returns the number of build vehicles.

Returns:
The number of loaded (build) vehicles

Definition at line 193 of file MSVehicleControl.h.

References myLoadedVehNo.

Referenced by GUINet::getParameterWindow(), and MSNet::writeOutput().

00193                                                     {
00194         return myLoadedVehNo;
00195     }

SUMOReal MSVehicleControl::getMeanTravelTime (  )  const throw ()

Returns the mean travel time of vehicles (corn-dependent value).

This value is only available if MSCORN::CORN_MEAN_VEH_TRAVELTIME is "wished". This is the case if the emissions-output shall be generated.

Returns:
The mean travel time of ended vehicles (-1 if no vehicle has ended, yet)
See also:
MSCORN
Todo:
Enable this for guisim?

Definition at line 247 of file MSVehicleControl.cpp.

References myAbsVehTravelTime, myEndedVehNo, and SUMOReal.

Referenced by MSNet::writeOutput().

00247                                                   {
00248     if (myEndedVehNo==0) {
00249         return -1;
00250     }
00251     return (SUMOReal) myAbsVehTravelTime / (SUMOReal) myEndedVehNo;
00252 }

SUMOReal MSVehicleControl::getMeanWaitingTime (  )  const throw ()

Returns the mean waiting time of vehicles (corn-dependent value).

This value is only available if MSCORN::CORN_MEAN_VEH_WAITINGTIME is "wished". This is the case if the emissions-output shall be generated.

Returns:
The mean time vehicles had to wait for being emitted (-1 if no vehicle was emitted, yet)
See also:
MSCORN
Todo:
Enable this for guisim?

Definition at line 238 of file MSVehicleControl.cpp.

References getEmittedVehicleNo(), myAbsVehWaitingTime, and SUMOReal.

Referenced by MSNet::writeOutput().

00238                                                    {
00239     if (getEmittedVehicleNo()==0) {
00240         return -1;
00241     }
00242     return (SUMOReal) myAbsVehWaitingTime / (SUMOReal) getEmittedVehicleNo();
00243 }

unsigned int MSVehicleControl::getRunningVehicleNo (  )  const throw () [inline]

Returns the number of build and emitted, but not yet deleted vehicles.

Returns:
The number simulated vehicles (including those in teleporter)

Definition at line 209 of file MSVehicleControl.h.

References myRunningVehNo.

Referenced by MSNet::closeSimulation(), GUINet::getParameterWindow(), MSNet::postSimStepOutput(), GUINet::setSimDuration(), MSNet::simulationState(), MSNet::simulationStep(), and MSNet::writeOutput().

00209                                                      {
00210         return myRunningVehNo;
00211     }

MSVehicle * MSVehicleControl::getVehicle ( const std::string &  id  )  const throw () [virtual]

Returns the vehicle with the given id.

If no vehicle with the given id is store din "myVehicleDict", 0 is returned.

Parameters:
[in] id The id of the vehicle to retrieve
Returns:
The vehicle with the given id, 0 if no such vehicle exists

Definition at line 444 of file MSVehicleControl.cpp.

References myVehicleDict.

Referenced by MSEmitControl::checkFlows(), traci::TraCIServer::getVehicleByExtId(), traci::TraCIServer::handleVehicleDomain(), MSEmitter::MSEmitter_FileTriggeredChild::myStartElement(), MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement(), traci::TraCIServer::postProcessSimulationStep(), TraCIServerAPI_Vehicle::processGet(), TraCIServerAPI_Vehicle::processSet(), and GUINet::vehicleExists().

00444                                                               {
00445     VehicleDictType::const_iterator it = myVehicleDict.find(id);
00446     if (it == myVehicleDict.end()) {
00447         return 0;
00448     }
00449     return it->second;
00450 }

MSVehicleType * MSVehicleControl::getVType ( const std::string &  id = DEFAULT_VTYPE_ID  )  throw ()

Returns the named vehicle type or a sample from the named distribution.

Parameters:
[in] id The id of the vehicle type to return. If left out, the default type is returned.
Returns:
The named vehicle type, or 0 if no such type exists

Definition at line 518 of file MSVehicleControl.cpp.

References DEFAULT_VTYPE_ID, myDefaultVTypeMayBeDeleted, myVTypeDict, and myVTypeDistDict.

Referenced by MSEmitter::MSEmitter_FileTriggeredChild::buildAndScheduleFlowVehicle(), MSCalibrator::MSCalibrator_FileTriggeredChild::buildAndScheduleFlowVehicle(), MSEmitControl::checkFlows(), MSRouteHandler::closeVehicle(), traci::TraCIServer::commandAddVehicle(), MSEmitter::MSEmitter_FileTriggeredChild::myStartElement(), MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement(), MSRouteHandler::openVehicleTypeDistribution(), TraCIServerAPI_VehicleType::processGet(), and GUIEmitter::GUIEmitterChild_UserTriggeredChild::wrappedExecute().

00518                                                       {
00519     VTypeDictType::iterator it = myVTypeDict.find(id);
00520     if (it == myVTypeDict.end()) {
00521         VTypeDistDictType::iterator it2 = myVTypeDistDict.find(id);
00522         if (it2 == myVTypeDistDict.end()) {
00523             return 0;
00524         }
00525         return it2->second->get();
00526     }
00527     if (id == DEFAULT_VTYPE_ID) {
00528         myDefaultVTypeMayBeDeleted = false;
00529     }
00530     return it->second;
00531 }

MSVehicle * MSVehicleControl::getWaitingVehicle ( const MSEdge *const   edge,
const std::set< std::string > &  lines 
) throw ()

Definition at line 567 of file MSVehicleControl.cpp.

References MSVehicle::getParameter(), SUMOVehicleParameter::line, and myWaiting.

Referenced by MSPerson::MSPersonStage_Driving::proceed().

00567                                                                                                     {
00568     if (myWaiting.find(edge) != myWaiting.end()) {
00569         for (std::vector<MSVehicle*>::const_iterator it = myWaiting[edge].begin(); it != myWaiting[edge].end(); ++it) {
00570             const std::string &line = (*it)->getParameter().line == "" ? (*it)->getParameter().id : (*it)->getParameter().line;
00571             if (lines.count(line)) {
00572                 return (*it);
00573             }
00574         }
00575     }
00576     return 0;
00577 }

bool MSVehicleControl::hasVTypeDistribution ( const std::string &  id  )  const throw ()

Asks for a vehicle type distribution.

If vehicle type distribution with the id exists, true is returned, false otherwise.

Parameters:
[in] id The id of the distribution
Returns:
Whether the vehicle type distribution exists

Definition at line 512 of file MSVehicleControl.cpp.

References myVTypeDistDict.

Referenced by MSEmitControl::add().

00512                                                                         {
00513     return myVTypeDistDict.find(id) != myVTypeDistDict.end();
00514 }

bool MSVehicleControl::haveAllVehiclesQuit (  )  const throw () [inline]

Returns the information whether all build vehicles have been removed.

Returns:
Whether all loaded vehicles have ended

Definition at line 225 of file MSVehicleControl.h.

References myEndedVehNo, and myLoadedVehNo.

Referenced by MSNet::simulationState().

00225                                              {
00226         return myLoadedVehNo==myEndedVehNo;
00227     }

void MSVehicleControl::insertVTypeIDs ( std::vector< std::string > &  into  )  const throw ()

Inserts ids of all known vehicle types and vehicle type distributions to the given vector.

Parameters:
[in] into The vector to fill with ids

Definition at line 535 of file MSVehicleControl.cpp.

References myVTypeDict, and myVTypeDistDict.

Referenced by TraCIServerAPI_VehicleType::processGet().

00535                                                                          {
00536     into.reserve(into.size()+myVTypeDict.size()+myVTypeDistDict.size());
00537     for (VTypeDictType::const_iterator i=myVTypeDict.begin(); i!=myVTypeDict.end(); ++i) {
00538         into.push_back((*i).first);
00539     }
00540     for (VTypeDistDictType::const_iterator i=myVTypeDistDict.begin(); i!=myVTypeDistDict.end(); ++i) {
00541         into.push_back((*i).first);
00542     }
00543 }

MSVehicleControl::constVehIt MSVehicleControl::loadedVehBegin (  )  const throw ()

Returns the begin of the internal vehicle map.

Returns:
The begin of the internal vehicle map

Definition at line 462 of file MSVehicleControl.cpp.

References myVehicleDict.

Referenced by MSVTypeProbe::execute(), traci::TraCIServer::handleVehicleDomain(), traci::TraCIServer::postProcessSimulationStep(), and TraCIServerAPI_Vehicle::processGet().

00462                                                {
00463     return myVehicleDict.begin();
00464 }

MSVehicleControl::constVehIt MSVehicleControl::loadedVehEnd (  )  const throw ()

Returns the end of the internal vehicle map.

Returns:
The end of the internal vehicle map

Definition at line 468 of file MSVehicleControl.cpp.

References myVehicleDict.

Referenced by MSVTypeProbe::execute(), traci::TraCIServer::handleVehicleDomain(), traci::TraCIServer::postProcessSimulationStep(), and TraCIServerAPI_Vehicle::processGet().

00468                                              {
00469     return myVehicleDict.end();
00470 }

MSVehicleControl& MSVehicleControl::operator= ( const MSVehicleControl s  )  [private]

invalidated assignment operator

void MSVehicleControl::removeWaiting ( const MSEdge *const   edge,
MSVehicle vehicle 
) throw ()

Definition at line 556 of file MSVehicleControl.cpp.

References myWaiting.

Referenced by MSPerson::MSPersonStage_Driving::proceed(), and MSVehicle::processNextStop().

00556                                                                                     {
00557     if (myWaiting.find(edge) != myWaiting.end()) {
00558         std::vector<MSVehicle*>::iterator it = std::find(myWaiting[edge].begin(), myWaiting[edge].end(), vehicle);
00559         if (it != myWaiting[edge].end()) {
00560             myWaiting[edge].erase(it);
00561         }
00562     }
00563 }

void MSVehicleControl::scheduleVehicleRemoval ( MSVehicle v  )  throw ()

Removes a vehicle after it has ended.

Writes output to tripinfos and vehroutes if wished; decrements the number of running vehicles and increments the number of ended vehicles. Then deletes the vehicle using "deleteVehicle".

This method should be called for each vehicle that was inserted into the network and quits its ride.

Parameters:
[in] v The vehicle to remove

Definition at line 95 of file MSVehicleControl.cpp.

References OutputDevice::closeTag(), MSCORN::CORN_MEAN_VEH_TRAVELTIME, MSCORN::CORN_OUT_OLDROUTES, MSCORN::CORN_OUT_TAZ, MSCORN::CORN_OUT_TRIPDURATIONS, MSCORN::CORN_OUT_VEHROUTES, MSCORN::CORN_P_VEH_ARRIVAL_INFO, MSCORN::CORN_P_VEH_DEPART_INFO, MSCORN::CORN_VEH_DEPART_TIME, MSCORN::CORN_VEH_NUMBERROUTE, MSCORN::CORN_VEH_VAPORIZED, MSCORN::CORN_VEH_WAITINGTIME, deleteVehicle(), MSNet::getCurrentTimeStep(), OutputDevice::getDeviceByOption(), MSLane::getID(), MSNet::getInstance(), MSLane::getLength(), MSNet::informVehicleStateListener(), MSVehicle::DepartArrivalInformation::lane, myAbsVehTravelTime, myRunningVehNo, OutputDevice::openTag(), MSVehicle::DepartArrivalInformation::pos, MSVehicle::DepartArrivalInformation::speed, SUMOReal, MSVehicle::DepartArrivalInformation::time, time2string(), MSNet::VEHICLE_STATE_ARRIVED, and MSCORN::wished().

Referenced by MSVehicleTransfer::addVeh(), MSVehicleTransfer::checkEmissions(), MSCalibrator::execute(), MSLane::push(), and MSLane::setCritical().

00095                                                              {
00096     assert(myRunningVehNo>0);
00097     // check whether to generate the information about the vehicle's trip
00098     if (MSCORN::wished(MSCORN::CORN_OUT_TRIPDURATIONS)) {
00099         OutputDevice& od = OutputDevice::getDeviceByOption("tripinfo-output");
00100         // obtain and generate vehicle's trip information
00101         MSVehicle::DepartArrivalInformation *departInfo = v->hasCORNPointerValue(MSCORN::CORN_P_VEH_DEPART_INFO)
00102                 ? (MSVehicle::DepartArrivalInformation*) v->getCORNPointerValue(MSCORN::CORN_P_VEH_DEPART_INFO)
00103                 : 0;
00104         MSVehicle::DepartArrivalInformation *arrivalInfo = v->hasCORNPointerValue(MSCORN::CORN_P_VEH_ARRIVAL_INFO)
00105                 ? (MSVehicle::DepartArrivalInformation*) v->getCORNPointerValue(MSCORN::CORN_P_VEH_ARRIVAL_INFO)
00106                 : 0;
00107         SUMOReal routeLength = v->getRoute().getLength();
00108         // write
00109         od.openTag("tripinfo") << " id=\"" << v->getID() << "\" ";
00110         SUMOTime departTime = -1;
00111         if (departInfo!=0) {
00112             routeLength -= departInfo->pos;
00113             std::string laneID = departInfo->lane!=0 ? departInfo->lane->getID() : "";
00114             od << "depart=\"" << time2string(departInfo->time) << "\" "
00115             << "departLane=\"" << laneID << "\" "
00116             << "departPos=\"" << departInfo->pos << "\" "
00117             << "departSpeed=\"" << departInfo->speed << "\" "
00118             << "departDelay=\"" << time2string(departInfo->time - v->getDesiredDepart()) << "\" ";
00119             departTime = departInfo->time;
00120         } else {
00121             if (v->hasCORNIntValue(MSCORN::CORN_VEH_DEPART_TIME)) {
00122                 departTime = v->getCORNIntValue(MSCORN::CORN_VEH_DEPART_TIME);
00123                 od << "depart=\"" << time2string(departTime) << "\" ";
00124             } else {
00125                 od << "depart=\"\" ";
00126             }
00127             od << "departLane=\"\" "
00128             << "departPos=\"\" "
00129             << "departSpeed=\"\" "
00130             << "departDelay=\"\" ";
00131         }
00132         SUMOTime arrivalTime = -1;
00133         if (arrivalInfo!=0) {
00134             std::string laneID = "";
00135             if (arrivalInfo->lane!=0) {
00136                 routeLength -= arrivalInfo->lane->getLength() - arrivalInfo->pos;
00137                 laneID = arrivalInfo->lane->getID();
00138             }
00139             od << "arrival=\"" << time2string(arrivalInfo->time) << "\" "
00140             << "arrivalLane=\"" << laneID << "\" "
00141             << "arrivalPos=\"" << arrivalInfo->pos << "\" "
00142             << "arrivalSpeed=\"" << arrivalInfo->speed << "\" ";
00143             arrivalTime = arrivalInfo->time;
00144         } else {
00145             arrivalTime = MSNet::getInstance()->getCurrentTimeStep();
00146             od << "arrival=\"" << time2string(arrivalTime) << "\" "
00147             << "arrivalLane=\"\" "
00148             << "arrivalPos=\"\" "
00149             << "arrivalSpeed=\"\" ";
00150         }
00151         if (departTime!=-1&&arrivalTime!=-1) {
00152             od << "duration=\"" << time2string(arrivalTime - departTime) << "\" ";
00153         } else {
00154             od << "duration=\"\" ";
00155         }
00156         od << "routeLength=\"" << routeLength << "\" "
00157         << "waitSteps=\"" << v->getCORNIntValue(MSCORN::CORN_VEH_WAITINGTIME) << "\" "
00158         << "rerouteNo=\"";
00159         if (v->hasCORNIntValue(MSCORN::CORN_VEH_NUMBERROUTE)) {
00160             od << v->getCORNIntValue(MSCORN::CORN_VEH_NUMBERROUTE);
00161         } else {
00162             od << '0';
00163         }
00164         // compute device id list
00165         const std::vector<MSDevice*> &devices = v->getDevices();
00166         std::string deviceIDs;
00167         if (devices.size()!=0) {
00168             std::ostringstream str;
00169             bool addSem = false;
00170             for (std::vector<MSDevice*>::const_iterator i=devices.begin(); i!=devices.end(); ++i) {
00171                 if (addSem) {
00172                     str << ' ';
00173                 }
00174                 addSem = true;
00175                 str << (*i)->getID();
00176             }
00177             deviceIDs = str.str();
00178         }
00179         //
00180         od << "\" devices=\"" << deviceIDs
00181         << "\" vtype=\"" << v->getVehicleType().getID()
00182         << "\" vaporized=\"";
00183         if (v->hasCORNIntValue(MSCORN::CORN_VEH_VAPORIZED)) {
00184             od << v->getCORNIntValue(MSCORN::CORN_VEH_VAPORIZED);
00185         }
00186         od << "\"";
00187         // write device information
00188         if (devices.size()!=0) {
00189             od << ">\n";
00190             for (std::vector<MSDevice*>::const_iterator i=devices.begin(); i!=devices.end(); ++i) {
00191                 (*i)->tripInfoOutput(od);
00192             }
00193         }
00194         od.closeTag(devices.size()==0);
00195     }
00196 
00197     // check whether to generate the information about the vehicle's routes
00198     if (MSCORN::wished(MSCORN::CORN_OUT_VEHROUTES)) {
00199         // generate vehicle's trip routes
00200         MSNet *net = MSNet::getInstance();
00201         OutputDevice& od = OutputDevice::getDeviceByOption("vehroute-output");
00202         SUMOTime realDepart = (SUMOTime) v->getCORNIntValue(MSCORN::CORN_VEH_DEPART_TIME);
00203         SUMOTime time = net->getCurrentTimeStep();
00204         od.openTag("vehicle") << " id=\"" << v->getID() << "\" depart=\""
00205         << time2string(v->getCORNIntValue(MSCORN::CORN_VEH_DEPART_TIME))
00206         << "\" arrival=\"" << time2string(MSNet::getInstance()->getCurrentTimeStep());
00207         if (MSCORN::wished(MSCORN::CORN_OUT_TAZ)) {
00208             od << "\" fromtaz=\"" << v->getParameter().fromTaz << "\" totaz=\"" << v->getParameter().toTaz;
00209         }
00210         od << "\">\n";
00211         if (MSCORN::wished(MSCORN::CORN_OUT_OLDROUTES) && v->hasCORNIntValue(MSCORN::CORN_VEH_NUMBERROUTE)) {
00212             od.openTag("routeDistribution") << ">\n";
00213             int noReroutes = v->getCORNIntValue(MSCORN::CORN_VEH_NUMBERROUTE);
00214             for (int i=0; i<noReroutes; ++i) {
00215                 v->writeXMLRoute(od, i);
00216             }
00217         }
00218         v->writeXMLRoute(od);
00219         if (MSCORN::wished(MSCORN::CORN_OUT_OLDROUTES) && v->hasCORNIntValue(MSCORN::CORN_VEH_NUMBERROUTE)) {
00220             od.closeTag();
00221         }
00222         od.closeTag();
00223         od << "\n";
00224     }
00225     // check whether to save information about the vehicle's trip
00226     if (MSCORN::wished(MSCORN::CORN_MEAN_VEH_TRAVELTIME)) {
00227         myAbsVehTravelTime +=
00228             (MSNet::getInstance()->getCurrentTimeStep()
00229              - v->getCORNIntValue(MSCORN::CORN_VEH_DEPART_TIME));
00230     }
00231     myRunningVehNo--;
00232     MSNet::getInstance()->informVehicleStateListener(v, MSNet::VEHICLE_STATE_ARRIVED);
00233     deleteVehicle(v);
00234 }

void MSVehicleControl::vehicleEmitted ( const MSVehicle v  )  throw () [virtual]

Informs this control about a vehicle's emission.

If the mean waiting time shall be computed (f.e. for emissions-output), the absolut waiting time is increased by the waiting time of the given vehicle.

Parameters:
[in] v The emitted vehicle
Todo:
Consolidate with vehiclesEmitted

Definition at line 256 of file MSVehicleControl.cpp.

References MSCORN::CORN_MEAN_VEH_WAITINGTIME, MSCORN::CORN_VEH_DEPART_TIME, MSNet::getInstance(), MSNet::informVehicleStateListener(), MAX2(), myAbsVehWaitingTime, myRunningVehNo, MSNet::VEHICLE_STATE_DEPARTED, and MSCORN::wished().

Referenced by MSVehicle::onDepart().


Field Documentation

The aggregated time vehicles needed to aacomplish their route.

Definition at line 375 of file MSVehicleControl.h.

Referenced by getMeanTravelTime(), and scheduleVehicleRemoval().

The aggregated time vehicles had to wait for departure.

Definition at line 372 of file MSVehicleControl.h.

Referenced by getMeanWaitingTime(), and vehicleEmitted().

Whether no vehicle type was loaded.

Definition at line 403 of file MSVehicleControl.h.

Referenced by checkVType(), and getVType().

unsigned int MSVehicleControl::myEndedVehNo [protected]

The number of removed vehicles.

Definition at line 364 of file MSVehicleControl.h.

Referenced by getEmittedVehicleNo(), getEndedVehicleNo(), getMeanTravelTime(), and haveAllVehiclesQuit().

unsigned int MSVehicleControl::myLoadedVehNo [protected]

The number of build vehicles.

Definition at line 358 of file MSVehicleControl.h.

Referenced by buildVehicle(), GUIVehicleControl::buildVehicle(), getLoadedVehicleNo(), and haveAllVehiclesQuit().

unsigned int MSVehicleControl::myRunningVehNo [protected]

The number of vehicles within the network (build and emitted but not removed).

Definition at line 361 of file MSVehicleControl.h.

Referenced by getEmittedVehicleNo(), getRunningVehicleNo(), scheduleVehicleRemoval(), and vehicleEmitted().

Dictionary of vehicle types.

Definition at line 395 of file MSVehicleControl.h.

Referenced by addVType(), checkVType(), getVType(), insertVTypeIDs(), MSVehicleControl(), and ~MSVehicleControl().

A distribution of vehicle types (probability->vehicle type).

Definition at line 400 of file MSVehicleControl.h.

Referenced by addVTypeDistribution(), checkVType(), getVType(), hasVTypeDistribution(), insertVTypeIDs(), and ~MSVehicleControl().

std::map<const MSEdge* const, std::vector<MSVehicle*> > MSVehicleControl::myWaiting [protected]

the lists of waiting vehicles

Definition at line 406 of file MSVehicleControl.h.

Referenced by addWaiting(), getWaitingVehicle(), and removeWaiting().


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:06:50 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6