MSDevice_Routing Class Reference

#include <MSDevice_Routing.h>

Inheritance diagram for MSDevice_Routing:

MSDevice

Detailed Description

A device that performs vehicle rerouting based on current edge speeds.

The routing-device system consists of in-vehicle devices that perform a routing and a simulation-wide (static) methods for colecting edge weights.

The edge weights container "myEdgeEfforts" is pre-initialised as soon as one device is built and is kept updated via an event that adapts it to the current mean speed on the simulated network's edges.

A device is assigned to a vehicle using the common explicite/probability - procedure.

A device computes a new route for a vehicle as soon as the vehicle is emitted (within "enterLaneAtEmit") - and, if the given period is larger than 0 - each x time steps where x is the period. This is triggered by an event that executes "wrappedRerouteCommandExecute".

Definition at line 68 of file MSDevice_Routing.h.


Public Member Functions

MSVehiclegetHolder () const throw ()
 Returns the vehicle that holds this device.
const std::string & getID () throw ()
 Returns the id of this device.
virtual void tripInfoOutput (OutputDevice &os) const throw (IOError)
 Called on writing tripinfo output.
Methods called on vehicle movement / state change, overwriting MSDevice
void enterLaneAtEmit (MSLane *enteredLane, const MSVehicle::State &state)
 Computes a new route on vehicle emission.
void onTryEmit ()
 Computes a new route on vehicle emission.
Methods called on vehicle movement / state change
virtual void enterLaneAtLaneChange (MSLane *enteredLane)
 Update of members if vehicle enters a new lane in the laneChange step.
virtual void enterLaneAtMove (MSLane *enteredLane, SUMOReal driven)
 Update if vehicle enters a new lane in the move step.
virtual void leaveLane ()
 Update of members if vehicle leaves a new lane in the lane change step.
virtual void leaveLaneAtMove (SUMOReal driven)
 Update of members if vehicle leaves a new lane in the move step.
virtual void onRemovalFromNet ()
 Called when the vehicle leaves the lane.

Static Public Member Functions

static void buildVehicleDevices (MSVehicle &v, std::vector< MSDevice * > &into) throw ()
 Build devices for the given vehicle, if needed.
static void insertOptions () throw ()
 Inserts MSDevice_Routing-options.

Protected Attributes

MSVehiclemyHolder
 The vehicle that stores the device.

Private Member Functions

SUMOReal getEffort (const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t) const
 Returns the effort to pass an edge.
 MSDevice_Routing (const MSDevice_Routing &)
 Invalidated copy constructor.
 MSDevice_Routing (MSVehicle &holder, const std::string &id, SUMOTime period, SUMOTime preEmitPeriod) throw ()
 Constructor.
MSDevice_Routingoperator= (const MSDevice_Routing &)
 Invalidated assignment operator.
SUMOTime wrappedRerouteCommandExecute (SUMOTime currentTime) throw (ProcessError)
 Performs rerouting after a period.
 ~MSDevice_Routing () throw ()
 Destructor.

Static Private Member Functions

Network state adaptation
static SUMOTime adaptEdgeEfforts (SUMOTime currentTime) throw (ProcessError)
 Adapt edge efforts by the current edge states.

Private Attributes

SUMOTime myLastPreEmitReroute
 The time step at which the last reroute was performed.
SUMOTime myPeriod
 The period with which a vehicle shall be rerouted.
SUMOTime myPreEmitPeriod
 The period with which a vehicle shall be rerouted before emission.
WrappingCommand
< MSDevice_Routing > * 
myRerouteCommand
 The (optional) command responsible for rerouting.

Static Private Attributes

static SUMOTime myAdaptationInterval
 Information which weight prior edge efforts have.
static SUMOReal myAdaptationWeight
 Information which weight prior edge efforts have.
static std::map< const MSEdge
*, SUMOReal > 
myEdgeEfforts
 The container of edge efforts.
static CommandmyEdgeWeightSettingCommand = 0
 The weights adaptation/overwriting command.
static int myVehicleIndex = 0
 A static vehicle index for computing deterministic vehicle fractions.
static bool myWithTaz
 whether taz shall be used at initial rerouting

Constructor & Destructor Documentation

MSDevice_Routing::MSDevice_Routing ( MSVehicle holder,
const std::string &  id,
SUMOTime  period,
SUMOTime  preEmitPeriod 
) throw () [private]

Constructor.

Parameters:
[in] holder The vehicle that holds this device
[in] id The ID of the device
[in] period The period with which a new route shall be searched
[in] preEmitPeriod The route search period before emit

Definition at line 149 of file MSDevice_Routing.cpp.

Referenced by buildVehicleDevices().

00151         : MSDevice(holder, id), myPeriod(period), myPreEmitPeriod(period),
00152         myLastPreEmitReroute(-1), myRerouteCommand(0) {
00153 }

MSDevice_Routing::~MSDevice_Routing (  )  throw () [private]

Destructor.

Definition at line 156 of file MSDevice_Routing.cpp.

References WrappingCommand< T >::deschedule(), and myRerouteCommand.

00156                                             {
00157     // make the rerouting command invalid if there is one
00158     if (myRerouteCommand!=0) {
00159         myRerouteCommand->deschedule();
00160     }
00161 }

MSDevice_Routing::MSDevice_Routing ( const MSDevice_Routing  )  [private]

Invalidated copy constructor.


Member Function Documentation

SUMOTime MSDevice_Routing::adaptEdgeEfforts ( SUMOTime  currentTime  )  throw (ProcessError) [static, private]

Adapt edge efforts by the current edge states.

This method is called by the event handler at the end of a simulation step. The current edge weights are combined with the previously stored.

Parameters:
[in] currentTime The current simulation time
Returns:
The offset to the next call (always 1 in this case - edge weights are updated each time step)
Todo:
Describe how the weights are adapted
See also:
MSEventHandler

StaticCommand

Definition at line 215 of file MSDevice_Routing.cpp.

References MSNet::getEdgeControl(), MSEdgeControl::getEdges(), MSNet::getInstance(), myAdaptationInterval, myAdaptationWeight, myEdgeEfforts, and SUMOReal.

Referenced by buildVehicleDevices().

00215                                                                            {
00216     SUMOReal newWeight = (SUMOReal)(1. - myAdaptationWeight);
00217     const std::vector<MSEdge*> &edges = MSNet::getInstance()->getEdgeControl().getEdges();
00218     for (std::vector<MSEdge*>::const_iterator i=edges.begin(); i!=edges.end(); ++i) {
00219         myEdgeEfforts[*i] = myEdgeEfforts[*i] * myAdaptationWeight + (*i)->getCurrentTravelTime() * newWeight;
00220     }
00221     return myAdaptationInterval;
00222 }

void MSDevice_Routing::buildVehicleDevices ( MSVehicle v,
std::vector< MSDevice * > &  into 
) throw () [static]

Build devices for the given vehicle, if needed.

The options are read and evaluated whether rerouting-devices shall be built for the given vehicle.

When the first device is built, the static container of edge weights used for routing is initialised with the mean speed the edges allow. In addition, an event is generated which updates these weights is built and added to the list of events to execute at a simulation end.

For each seen vehicle, the global vehicle index is increased.

The built device is stored in the given vector.

Parameters:
[in] v The vehicle for which a device may be built
in,filled] into The vector to store the built device in

Definition at line 95 of file MSDevice_Routing.cpp.

References MSEventControl::ADAPT_AFTER_EXECUTION, adaptEdgeEfforts(), MSEventControl::addEvent(), MSEdge::dictionary(), OptionsCont::getBool(), MSNet::getEdgeControl(), MSEdgeControl::getEdges(), MSNet::getEndOfTimestepEvents(), OptionsCont::getFloat(), MSNet::getInstance(), OptionsCont::getOptions(), OptionsCont::getString(), OptionsCont::isInStringVector(), OptionsCont::isSet(), MSDevice_Routing(), myAdaptationInterval, myAdaptationWeight, myEdgeEfforts, myEdgeWeightSettingCommand, myVehicleIndex, myWithTaz, RandHelper::rand(), string2time(), and WRITE_ERROR.

Referenced by MSVehicle::MSVehicle().

00095                                                                                       {
00096     OptionsCont &oc = OptionsCont::getOptions();
00097     if (oc.getFloat("device.routing.probability")==0&&!oc.isSet("device.routing.knownveh")) {
00098         // no route computation is modelled
00099         return;
00100     }
00101     // route computation is enabled
00102     bool haveByNumber = false;
00103     if (oc.getBool("device.routing.deterministic")) {
00104         haveByNumber = ((myVehicleIndex%1000) < (int)(oc.getFloat("device.routing.probability")*1000.));
00105     } else {
00106         haveByNumber = RandHelper::rand()<=oc.getFloat("device.routing.probability");
00107     }
00108     bool haveByName = oc.isSet("device.routing.knownveh") && OptionsCont::getOptions().isInStringVector("device.routing.knownveh", v.getID());
00109     if (haveByNumber||haveByName) {
00110         // build the device
00111         MSDevice_Routing* device = new MSDevice_Routing(v, "routing_" + v.getID(),
00112                 string2time(oc.getString("device.routing.period")),
00113                 string2time(oc.getString("device.routing.pre-period")));
00114         into.push_back(device);
00115         // initialise edge efforts if not done before
00116         if (myEdgeEfforts.size()==0) {
00117             const std::vector<MSEdge*> &edges = MSNet::getInstance()->getEdgeControl().getEdges();
00118             for (std::vector<MSEdge*>::const_iterator i=edges.begin(); i!=edges.end(); ++i) {
00119                 myEdgeEfforts[*i] = (*i)->getCurrentTravelTime();
00120             }
00121         }
00122         // make the weights be updated
00123         if (myEdgeWeightSettingCommand==0) {
00124             myEdgeWeightSettingCommand = new StaticCommand< MSDevice_Routing >(&MSDevice_Routing::adaptEdgeEfforts);
00125             MSNet::getInstance()->getEndOfTimestepEvents().addEvent(
00126                 myEdgeWeightSettingCommand, 0, MSEventControl::ADAPT_AFTER_EXECUTION);
00127             myAdaptationWeight = oc.getFloat("device.routing.adaptation-weight");
00128             myAdaptationInterval = string2time(oc.getString("device.routing.adaptation-interval"));
00129         }
00130         myWithTaz = oc.getBool("device.routing.with-taz");
00131         if (myWithTaz) {
00132             if (MSEdge::dictionary(v.getParameter().fromTaz+"-source") == 0) {
00133                 WRITE_ERROR("Source district '" + v.getParameter().fromTaz + "' not known when rerouting '" + v.getID() + "'!");
00134                 return;
00135             }
00136             if (MSEdge::dictionary(v.getParameter().toTaz) == 0) {
00137                 WRITE_ERROR("Destination district '" + v.getParameter().toTaz + "' not known when rerouting '" + v.getID() + "'!");
00138                 return;
00139             }
00140         }
00141     }
00142     myVehicleIndex++;
00143 }

void MSDevice_Routing::enterLaneAtEmit ( MSLane enteredLane,
const MSVehicle::State state 
) [virtual]

Computes a new route on vehicle emission.

A new route is computed by calling the vehicle's "reroute" method, supplying "getEffort" as the edge effort retrieval method.

If the reroute period is larger than 0, an event is generated and added to the list of simulation step begin events which executes "wrappedRerouteCommandExecute".

Parameters:
[in] enteredLane The lane the vehicle enters
[in] state The vehicle's state during the emission
See also:
MSVehicle::reroute

MSEventHandler

WrappingCommand

Reimplemented from MSDevice.

Definition at line 180 of file MSDevice_Routing.cpp.

References MSEventControl::ADAPT_AFTER_EXECUTION, MSEventControl::addEvent(), MSEdge::dictSize(), MSNet::getBeginOfTimestepEvents(), getEffort(), MSNet::getInstance(), MSDevice::myHolder, myLastPreEmitReroute, myPeriod, myRerouteCommand, MSVehicle::reroute(), and wrappedRerouteCommandExecute().

00180                                                                  {
00181     if (myLastPreEmitReroute == -1) {
00182         DijkstraRouterTT_ByProxi<MSEdge, SUMOVehicle, prohibited_withRestrictions<MSEdge, SUMOVehicle>, MSDevice_Routing>
00183         router(MSEdge::dictSize(), true, this, &MSDevice_Routing::getEffort);
00184         myHolder.reroute(MSNet::getInstance()->getCurrentTimeStep(), router);
00185     }
00186     // build repetition trigger if routing shall be done more often
00187     if (myPeriod>0&&myRerouteCommand==0) {
00188         myRerouteCommand = new WrappingCommand< MSDevice_Routing >(this, &MSDevice_Routing::wrappedRerouteCommandExecute);
00189         MSNet::getInstance()->getBeginOfTimestepEvents().addEvent(
00190             myRerouteCommand, myPeriod+MSNet::getInstance()->getCurrentTimeStep(),
00191             MSEventControl::ADAPT_AFTER_EXECUTION);
00192     }
00193 }

virtual void MSDevice::enterLaneAtLaneChange ( MSLane enteredLane  )  [inline, virtual, inherited]

Update of members if vehicle enters a new lane in the laneChange step.

Parameters:
[in] enteredLane The lane the vehicle enters

Definition at line 121 of file MSDevice.h.

00121 { }

virtual void MSDevice::enterLaneAtMove ( MSLane enteredLane,
SUMOReal  driven 
) [inline, virtual, inherited]

Update if vehicle enters a new lane in the move step.

Parameters:
[in] enteredLane The lane the vehicle enters
[in] driven The distance driven by the vehicle within this time step

Definition at line 106 of file MSDevice.h.

00106 { }

SUMOReal MSDevice_Routing::getEffort ( const MSEdge *const   e,
const SUMOVehicle *const   v,
SUMOReal  t 
) const [private]

Returns the effort to pass an edge.

This method is given to the used router in order to obtain the efforts to pass an edge from the internal edge weights container.

The time is not used, here, as the current simulation state is used in an aggregated way.

Parameters:
[in] e The edge for which the effort to be passed shall be returned
[in] v The vehicle that is rerouted
[in] t The time for which the effort shall be returned
Returns:
The effort (time to pass in this case) for an edge
See also:
DijkstraRouterTT_ByProxi

Definition at line 206 of file MSDevice_Routing.cpp.

References MSEdge::getLanes(), SUMOVehicle::getMaxSpeed(), MAX2(), and myEdgeEfforts.

Referenced by enterLaneAtEmit(), onTryEmit(), and wrappedRerouteCommandExecute().

00206                                                                                                {
00207     if (myEdgeEfforts.find(e) != myEdgeEfforts.end()) {
00208         return MAX2(myEdgeEfforts.find(e)->second, e->getLanes()[0]->getLength()/v->getMaxSpeed());
00209     }
00210     return 0;
00211 }

MSVehicle& MSDevice::getHolder (  )  const throw () [inline, inherited]

Returns the vehicle that holds this device.

Returns:
The vehicle that holds this device

Definition at line 81 of file MSDevice.h.

References MSDevice::myHolder.

Referenced by MSDevice_HBEFA::wrappedComputeCommandExecute().

00081                                          {
00082         return myHolder;
00083     }

const std::string& MSDevice::getID (  )  throw () [inline, inherited]

Returns the id of this device.

Returns:
The device's ID

Definition at line 89 of file MSDevice.h.

References MSDevice::myID.

00089                                      {
00090         return myID;
00091     }

void MSDevice_Routing::insertOptions (  )  throw () [static]

Inserts MSDevice_Routing-options.

Definition at line 60 of file MSDevice_Routing.cpp.

References OptionsCont::addDescription(), OptionsCont::addOptionSubTopic(), OptionsCont::doRegister(), OptionsCont::getOptions(), myEdgeEfforts, myEdgeWeightSettingCommand, and myVehicleIndex.

Referenced by MSFrame::fillOptions().

00060                                         {
00061     OptionsCont &oc = OptionsCont::getOptions();
00062     oc.addOptionSubTopic("Routing");
00063 
00064     oc.doRegister("device.routing.probability", new Option_Float(0.));
00065     oc.addDescription("device.routing.probability", "Routing", "The probability for a vehicle to have a routing device");
00066 
00067     oc.doRegister("device.routing.knownveh", new Option_String());
00068     oc.addDescription("device.routing.knownveh", "Routing", "Assign a device to named vehicles");
00069 
00070     oc.doRegister("device.routing.deterministic", new Option_Bool(false));
00071     oc.addDescription("device.routing.deterministic", "Routing", "The devices are set deterministic using a fraction of 1000");
00072 
00073     oc.doRegister("device.routing.period", new Option_String("0"));
00074     oc.addDescription("device.routing.period", "Routing", "The period with which the vehicle shall be rerouted");
00075 
00076     oc.doRegister("device.routing.pre-period", new Option_String("0"));
00077     oc.addDescription("device.routing.pre-period", "Routing", "The rerouting period before emit");
00078 
00079     oc.doRegister("device.routing.adaptation-weight", new Option_Float(.5));
00080     oc.addDescription("device.routing.adaptation-weight", "Routing", "The weight of prior edge weights.");
00081 
00082     oc.doRegister("device.routing.adaptation-interval", new Option_String("1"));
00083     oc.addDescription("device.routing.adaptation-interval", "Routing", "The interval for updating the edge weights.");
00084 
00085     oc.doRegister("device.routing.with-taz", new Option_Bool(false));
00086     oc.addDescription("device.routing.with-taz", "Routing", "Use zones (districts) as routing end points");
00087 
00088     myVehicleIndex = 0;
00089     myEdgeWeightSettingCommand = 0;
00090     myEdgeEfforts.clear();
00091 }

virtual void MSDevice::leaveLane (  )  [inline, virtual, inherited]

Update of members if vehicle leaves a new lane in the lane change step.

Definition at line 132 of file MSDevice.h.

00132 { }

virtual void MSDevice::leaveLaneAtMove ( SUMOReal  driven  )  [inline, virtual, inherited]

Update of members if vehicle leaves a new lane in the move step.

Parameters:
[in] driven The distance driven by the vehicle within this time step

Definition at line 128 of file MSDevice.h.

00128 { }

virtual void MSDevice::onRemovalFromNet (  )  [inline, virtual, inherited]

Called when the vehicle leaves the lane.

Definition at line 136 of file MSDevice.h.

00136 { }

void MSDevice_Routing::onTryEmit (  )  [virtual]

Computes a new route on vehicle emission.

A new route is computed by calling the vehicle's "reroute" method, supplying "getEffort" as the edge effort retrieval method.

If the reroute period is larger than 0, an event is generated and added to the list of simulation step begin events which executes "wrappedRerouteCommandExecute".

See also:
MSVehicle::reroute

MSEventHandler

WrappingCommand

Reimplemented from MSDevice.

Definition at line 165 of file MSDevice_Routing.cpp.

References MSEdge::dictSize(), MSNet::getCurrentTimeStep(), getEffort(), MSNet::getInstance(), MSDevice::myHolder, myLastPreEmitReroute, myPreEmitPeriod, myWithTaz, and MSVehicle::reroute().

00165                             {
00166     if (myWithTaz) {
00167         const SUMOTime now = MSNet::getInstance()->getCurrentTimeStep();
00168         if (myLastPreEmitReroute == -1 ||
00169                 (myPreEmitPeriod > 0 && myLastPreEmitReroute + myPreEmitPeriod <= now)) {
00170             DijkstraRouterTT_ByProxi<MSEdge, SUMOVehicle, prohibited_withRestrictions<MSEdge, SUMOVehicle>, MSDevice_Routing>
00171             router(MSEdge::dictSize(), true, this, &MSDevice_Routing::getEffort);
00172             myHolder.reroute(MSNet::getInstance()->getCurrentTimeStep(), router, true);
00173             myLastPreEmitReroute = now;
00174         }
00175     }
00176 }

MSDevice_Routing& MSDevice_Routing::operator= ( const MSDevice_Routing  )  [private]

Invalidated assignment operator.

virtual void MSDevice::tripInfoOutput ( OutputDevice os  )  const throw (IOError) [inline, virtual, inherited]

Called on writing tripinfo output.

The device may write some statistics into the tripinfo output. It is assumed that the written information is a valid xml-snipplet, which will be embedded within the vehicle's information.

The device should use the openTag / closeTag methods of the OutputDevice for correct indentation.

Parameters:
[in] os The stream to write the information into
Exceptions:
IOError not yet implemented

Reimplemented in MSDevice_HBEFA.

Definition at line 152 of file MSDevice.h.

00152                                                                        {
00153     }

SUMOTime MSDevice_Routing::wrappedRerouteCommandExecute ( SUMOTime  currentTime  )  throw (ProcessError) [private]

Performs rerouting after a period.

A new route is computed by calling the vehicle's "reroute" method, supplying "getEffort" as the edge effort retrieval method.

This method is called from the event handler at the begin of a simulation step after the rerouting period is over. The reroute period is returned.

Parameters:
[in] currentTime The current simulation time
Returns:
The offset to the next call (the rerouting period "myPeriod")
See also:
MSVehicle::reroute

MSEventHandler

WrappingCommand

Definition at line 197 of file MSDevice_Routing.cpp.

References MSEdge::dictSize(), getEffort(), MSDevice::myHolder, myPeriod, and MSVehicle::reroute().

Referenced by enterLaneAtEmit().


Field Documentation

Information which weight prior edge efforts have.

Definition at line 227 of file MSDevice_Routing.h.

Referenced by adaptEdgeEfforts(), and buildVehicleDevices().

SUMOReal MSDevice_Routing::myAdaptationWeight [static, private]

Information which weight prior edge efforts have.

Definition at line 224 of file MSDevice_Routing.h.

Referenced by adaptEdgeEfforts(), and buildVehicleDevices().

std::map< const MSEdge *, SUMOReal > MSDevice_Routing::myEdgeEfforts [static, private]

The container of edge efforts.

Definition at line 221 of file MSDevice_Routing.h.

Referenced by adaptEdgeEfforts(), buildVehicleDevices(), getEffort(), and insertOptions().

The weights adaptation/overwriting command.

Definition at line 218 of file MSDevice_Routing.h.

Referenced by buildVehicleDevices(), and insertOptions().

MSVehicle& MSDevice::myHolder [protected, inherited]

The vehicle that stores the device.

Definition at line 158 of file MSDevice.h.

Referenced by enterLaneAtEmit(), MSDevice::getHolder(), onTryEmit(), and wrappedRerouteCommandExecute().

The time step at which the last reroute was performed.

Definition at line 209 of file MSDevice_Routing.h.

Referenced by enterLaneAtEmit(), and onTryEmit().

The period with which a vehicle shall be rerouted.

Definition at line 203 of file MSDevice_Routing.h.

Referenced by enterLaneAtEmit(), and wrappedRerouteCommandExecute().

The period with which a vehicle shall be rerouted before emission.

Definition at line 206 of file MSDevice_Routing.h.

Referenced by onTryEmit().

The (optional) command responsible for rerouting.

Definition at line 215 of file MSDevice_Routing.h.

Referenced by enterLaneAtEmit(), and ~MSDevice_Routing().

int MSDevice_Routing::myVehicleIndex = 0 [static, private]

A static vehicle index for computing deterministic vehicle fractions.

Definition at line 212 of file MSDevice_Routing.h.

Referenced by buildVehicleDevices(), and insertOptions().

bool MSDevice_Routing::myWithTaz [static, private]

whether taz shall be used at initial rerouting

Definition at line 230 of file MSDevice_Routing.h.

Referenced by buildVehicleDevices(), and onTryEmit().


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

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