MSVehicleTransfer Class Reference

#include <MSVehicleTransfer.h>


Detailed Description

This object (each simulation owns exactly one) is responsible for the transfer of vehicles that got stocked within the network due to grid locks.

The method addVeh is called by a lane if a vehicle stood to long at this lane's end. After being added to this transfer object and removed from the lane, it is moved over the consecutive edges. On each edge, it is tried to insert the vehicle again. The lanes are of course chosen by examining the vehicle's real route.

This object is used as a singleton

Definition at line 59 of file MSVehicleTransfer.h.


Public Member Functions

void addVeh (MSVehicle *veh) throw ()
 Adds a vehicle to this transfer object.
void checkEmissions (SUMOTime time) throw ()
 Checks "movement" of stored vehicles.
virtual ~MSVehicleTransfer () throw ()
 Destructor.

Static Public Member Functions

static MSVehicleTransfergetInstance () throw ()
 Returns the instance of this object.

Protected Types

typedef std::vector
< VehicleInformation
VehicleInfVector
 Definition of a container for vehicle information.

Protected Attributes

unsigned int myNoTransfered
 A counter for vehicles that had to be moved virtually.
VehicleInfVector myVehicles
 The information about stored vehicles to move virtually.

Static Protected Attributes

static MSVehicleTransfermyInstance = 0
 The static singleton-instance.

Private Member Functions

 MSVehicleTransfer () throw ()
 Constructor.
bool proceedVirtualReturnWhetherEnded (MSVehicle &veh, const MSEdge *const newEdge) throw ()
 Moves the vehicle one edge further returning whether the destination is reached.

Data Structures

struct  VehicleInformation
 Holds the information needed to move the vehicle over the network. More...

Member Typedef Documentation

typedef std::vector<VehicleInformation> MSVehicleTransfer::VehicleInfVector [protected]

Definition of a container for vehicle information.

Definition at line 135 of file MSVehicleTransfer.h.


Constructor & Destructor Documentation

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

Destructor.

Definition at line 132 of file MSVehicleTransfer.cpp.

References myInstance.

00132                                               {
00133     myInstance = 0;
00134 }

MSVehicleTransfer::MSVehicleTransfer (  )  throw () [private]

Constructor.

Definition at line 128 of file MSVehicleTransfer.cpp.

Referenced by getInstance().

00129         : myNoTransfered(0) {}


Member Function Documentation

void MSVehicleTransfer::addVeh ( MSVehicle veh  )  throw ()

Adds a vehicle to this transfer object.

The vehicle is removed from the network as it would end the trip. If the vehicle's next edge is his last one, the vehicle is also removed from the vehicle control.

Parameters:
[in] veh The vehicle to add

Definition at line 54 of file MSVehicleTransfer.cpp.

References MSEdge::dictionary(), MSNet::getInstance(), MSNet::getVehicleControl(), MSNet::informVehicleStateListener(), MSVehicleControl::scheduleVehicleRemoval(), and MSNet::VEHICLE_STATE_STARTING_TELEPORT.

Referenced by MSLane::detectCollisions(), MSLane::moveCritical(), and MSLane::setCritical().

00054                                                 {
00055     // get the current edge of the vehicle
00056     MSEdge *e = MSEdge::dictionary(veh->getEdge()->getID());
00057     // let the vehicle be on the one
00058     veh->onRemovalFromNet(true);
00059     if (!veh->hasSuccEdge(1)||proceedVirtualReturnWhetherEnded(*veh, MSEdge::dictionary(veh->succEdge(1)->getID()))) {
00060         MSNet::getInstance()->getVehicleControl().scheduleVehicleRemoval(veh);
00061         return;
00062     }
00063     // mark the next one
00064     myNoTransfered++;
00065     // save information
00066     myVehicles.push_back(VehicleInformation(veh, MSNet::getInstance()->getCurrentTimeStep()));
00067     MSNet::getInstance()->informVehicleStateListener(veh, MSNet::VEHICLE_STATE_STARTING_TELEPORT);
00068 }

void MSVehicleTransfer::checkEmissions ( SUMOTime  time  )  throw ()

Checks "movement" of stored vehicles.

Checks whether one of the stored vehicles may be inserted back into the network. If not, the vehicle may ove virtually to the next lane of it's route

Parameters:
[in] time The current simulation time

Definition at line 72 of file MSVehicleTransfer.cpp.

References MSEdge::dictionary(), MSLane::freeEmit(), MSVehicle::getEdge(), MSEdge::getFreeLane(), MSEdge::getID(), MSVehicle::getID(), MSNet::getInstance(), MSEdge::getLanes(), MSLane::getLength(), MSVehicle::getMaxSpeed(), MSLane::getMaxSpeed(), MSVehicleType::getVehicleClass(), MSNet::getVehicleControl(), MSVehicle::getVehicleType(), MSNet::informVehicleStateListener(), MIN2(), MSVehicleTransfer::VehicleInformation::myProceedTime, MSVehicleTransfer::VehicleInformation::myVeh, MSVehicleControl::scheduleVehicleRemoval(), MSVehicle::succEdge(), toString(), MSNet::VEHICLE_STATE_ENDING_TELEPORT, and WRITE_WARNING.

Referenced by MSNet::simulationStep().

00072                                                        {
00073     // go through vehicles
00074     for (VehicleInfVector::iterator i=myVehicles.begin(); i!=myVehicles.end();) {
00075         // get the vehicle information
00076         VehicleInformation &desc = *i;
00077         const MSEdge *e = desc.myVeh->getEdge();
00078         MSLane *l = e->getFreeLane(desc.myVeh->getVehicleType().getVehicleClass());
00079         // check whether the vehicle may be emitted onto a following edge
00080         if (l->freeEmit(*(desc.myVeh), MIN2(l->getMaxSpeed(), desc.myVeh->getMaxSpeed()))) {
00081             // remove from this if so
00082             WRITE_WARNING("Vehicle '" + desc.myVeh->getID()+ "' ends teleporting on edge '" + e->getID()+ "', simulation time " + toString(MSNet::getInstance()->getCurrentTimeStep()) + ".");
00083             MSNet::getInstance()->informVehicleStateListener(desc.myVeh, MSNet::VEHICLE_STATE_ENDING_TELEPORT);
00084             i = myVehicles.erase(i);
00085         } else {
00086             // otherwise, check whether a consecutive edge may be used
00087             if (desc.myProceedTime<time) {
00088                 // get the lanes of the next edge (the one the vehicle wiil be
00089                 //  virtually on after all these computations)
00090                 MSLane *tmp = *(e->getLanes().begin());
00091                 // get the one beyond the one the vehicle moved to
00092                 MSEdge *nextEdge = MSEdge::dictionary(desc.myVeh->succEdge(1)->getID());
00093                 // let the vehicle move to the next edge
00094                 if (proceedVirtualReturnWhetherEnded(*desc.myVeh, nextEdge)) {
00095                     WRITE_WARNING("Vehicle '" + desc.myVeh->getID()+ "' ends teleporting on end edge '" + e->getID()+ "'.");
00096                     MSNet::getInstance()->getVehicleControl().scheduleVehicleRemoval(desc.myVeh);
00097                     i = myVehicles.erase(i);
00098                     continue;
00099                 }
00100                 // get the time the vehicle needs to pass the current edge
00101                 //  !!! maybe, the time should be compued in other ways
00102                 desc.myProceedTime = time + (SUMOTime)(tmp->getLength() / tmp->getMaxSpeed() * 2.0);
00103             }
00104             ++i;
00105         }
00106 
00107     }
00108 }

MSVehicleTransfer * MSVehicleTransfer::getInstance ( void   )  throw () [static]

Returns the instance of this object.

Returns:
The singleton instance

Definition at line 120 of file MSVehicleTransfer.cpp.

References MSVehicleTransfer(), and myInstance.

Referenced by MSNet::clearAll(), MSLane::detectCollisions(), MSLane::moveCritical(), MSLane::setCritical(), and MSNet::simulationStep().

00120                                        {
00121     if (myInstance==0) {
00122         myInstance = new MSVehicleTransfer();
00123     }
00124     return myInstance;
00125 }

bool MSVehicleTransfer::proceedVirtualReturnWhetherEnded ( MSVehicle veh,
const MSEdge *const   newEdge 
) throw () [private]

Moves the vehicle one edge further returning whether the destination is reached.

The vehicle is not inserted into the next edge, only internal variables are adapted.

Parameters:
[in,out] veh The vehicle to move
[in] newEdge The next to move the vehicle to (virually)
Returns:
Whether the vehicle has reached his destination
Todo:
The edges are compared by pointers only; this will not work if the seen edge occurs twice in the vehicle's route

Definition at line 112 of file MSVehicleTransfer.cpp.

00112                                                                                                        {
00113     veh.moveRoutePointer(newEdge);
00114     MSRouteIterator destination = veh.getRoute().end() - 1;
00115     return veh.getEdge() == *destination;
00116 }


Field Documentation

The static singleton-instance.

Definition at line 144 of file MSVehicleTransfer.h.

Referenced by getInstance(), and ~MSVehicleTransfer().

unsigned int MSVehicleTransfer::myNoTransfered [protected]

A counter for vehicles that had to be moved virtually.

Definition at line 141 of file MSVehicleTransfer.h.

The information about stored vehicles to move virtually.

Definition at line 138 of file MSVehicleTransfer.h.


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