#include <RORouteDef_Alternatives.h>

Definition at line 51 of file RORouteDef_Alternatives.h.
Public Member Functions | |
| void | addAlternative (SUMOAbstractRouter< ROEdge, ROVehicle > &router, const ROVehicle *const, RORoute *current, SUMOTime begin) |
| Adds a build alternative. | |
| virtual void | addLoadedAlternative (RORoute *alternative) |
| Adds an alternative loaded from the file An alternative may also be generated whicle DUA. | |
| RORoute * | buildCurrentRoute (SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime begin, const ROVehicle &veh) const |
| Build the next route. | |
| RORouteDef * | copy (const std::string &id) const |
| Returns a copy of the route definition. | |
| const RGBColor *const | getColor () const |
| Returns the color of the route. | |
| const std::string & | getID () const throw () |
| Returns the id. | |
| void | invalidateLast () |
| bool | isSaved () const throw () |
| Returns the information whether this item was already saved. | |
| void | markSaved () throw () |
| Marks the item as saved. | |
| void | removeLast () |
| RORouteDef_Alternatives (const std::string &id, unsigned int lastUsed, SUMOReal gawronBeta, SUMOReal gawronA, int maxRoutes) throw () | |
| Constructor. | |
| virtual OutputDevice & | writeXMLDefinition (SUMOAbstractRouter< ROEdge, ROVehicle > &router, OutputDevice &dev, const ROVehicle *const veh, bool asAlternatives, bool withExitTimes) const |
| Saves the built route / route alternatives. | |
| virtual | ~RORouteDef_Alternatives () throw () |
| Destructor. | |
Protected Member Functions | |
| const RGBColor *const | copyColorIfGiven () const throw () |
Protected Attributes | |
| const RGBColor *const | myColor |
| The color the route shall have. | |
| std::string | myID |
| The name of the object. | |
Private Types | |
| typedef std::vector< RORoute * > | AlternativesVector |
| Definition of the storage for alternatives. | |
Private Member Functions | |
| int | findRoute (RORoute *opt) const |
| Searches for the route within the list of alternatives. | |
| SUMOReal | gawronF (SUMOReal pdr, SUMOReal pds, SUMOReal x) |
| Performs the gawron - f() function From "Dynamic User Equilibria...". | |
| SUMOReal | gawronG (SUMOReal a, SUMOReal x) |
| Performs the gawron - g() function From "Dynamic User Equilibria...". | |
| RORouteDef_Alternatives & | operator= (const RORouteDef_Alternatives &src) |
| Invalidated assignment operator. | |
| RORouteDef_Alternatives (const RORouteDef_Alternatives &src) | |
| Invalidated copy constructor. | |
Private Attributes | |
| AlternativesVector | myAlternatives |
| The alternatives. | |
| SUMOReal | myGawronA |
| gawron a - value | |
| SUMOReal | myGawronBeta |
| gawron beta - value | |
| int | myLastUsed |
| Index of the route used within the last step. | |
| int | myMaxRouteNumber |
| The maximum route number. | |
| bool | myNewRoute |
| Information whether a new route was generated. | |
typedef std::vector<RORoute*> RORouteDef_Alternatives::AlternativesVector [private] |
Definition of the storage for alternatives.
Definition at line 103 of file RORouteDef_Alternatives.h.
| RORouteDef_Alternatives::RORouteDef_Alternatives | ( | const std::string & | id, | |
| unsigned int | lastUsed, | |||
| SUMOReal | gawronBeta, | |||
| SUMOReal | gawronA, | |||
| int | maxRoutes | |||
| ) | throw () |
Constructor.
Definition at line 63 of file RORouteDef_Alternatives.cpp.
Referenced by copy().
00068 : RORouteDef(id, 0), myLastUsed((int) lastUsed), 00069 myGawronBeta(gawronBeta), myGawronA(gawronA), myMaxRouteNumber(maxRoutes) { 00070 }
| RORouteDef_Alternatives::~RORouteDef_Alternatives | ( | ) | throw () [virtual] |
Destructor.
Definition at line 73 of file RORouteDef_Alternatives.cpp.
References myAlternatives.
00073 { 00074 for (AlternativesVector::iterator i=myAlternatives.begin(); i!=myAlternatives.end(); i++) { 00075 delete *i; 00076 } 00077 }
| RORouteDef_Alternatives::RORouteDef_Alternatives | ( | const RORouteDef_Alternatives & | src | ) | [private] |
Invalidated copy constructor.
| void RORouteDef_Alternatives::addAlternative | ( | SUMOAbstractRouter< ROEdge, ROVehicle > & | router, | |
| const ROVehicle * const | veh, | |||
| RORoute * | current, | |||
| SUMOTime | begin | |||
| ) | [virtual] |
Adds a build alternative.
Implements RORouteDef.
Definition at line 124 of file RORouteDef_Alternatives.cpp.
References gawronF(), RORoute::getCosts(), RORoute::getEdgeVector(), ROVehicle::getID(), Named::getID(), RORoute::getProbability(), ISNAN, MAX2(), MIN2(), myAlternatives, myGawronBeta, myLastUsed, myNewRoute, RandHelper::rand(), SUMOAbstractRouter< E, V >::recomputeCosts(), RORoute::setCosts(), RORoute::setProbability(), and SUMOReal.
00125 { 00126 // add the route when it's new 00127 if (myLastUsed<0) { 00128 myAlternatives.push_back(current); 00129 myLastUsed = (int) myAlternatives.size() - 1; 00130 } 00131 // recompute the costs and (when a new route was added) the probabilities 00132 AlternativesVector::iterator i; 00133 for (i=myAlternatives.begin(); i!=myAlternatives.end(); i++) { 00134 RORoute *alt = *i; 00135 // apply changes for old routes only 00136 // (the costs for the current were computed already) 00137 if ((*i)!=current||!myNewRoute) { 00138 // recompute the costs for old routes 00139 SUMOReal oldCosts = alt->getCosts(); 00140 SUMOReal newCosts = router.recomputeCosts(alt->getEdgeVector(), veh, begin); 00141 if (newCosts<0) { 00142 throw ProcessError("Route '" + current->getID() + "' (vehicle '" + veh->getID() + "') is not valid."); 00143 } 00144 alt->setCosts(myGawronBeta * newCosts + ((SUMOReal) 1.0 - myGawronBeta) * oldCosts); 00145 } 00146 assert(myAlternatives.size()!=0); 00147 if (myNewRoute) { 00148 if ((*i)!=current) { 00149 alt->setProbability( 00150 alt->getProbability() 00151 * SUMOReal(myAlternatives.size()-1) 00152 / SUMOReal(myAlternatives.size())); 00153 } else { 00154 alt->setProbability((SUMOReal)(1.0 / (SUMOReal) myAlternatives.size())); 00155 } 00156 } 00157 } 00158 assert(myAlternatives.size()!=0); 00159 // compute the probabilities 00160 for (i=myAlternatives.begin(); i!=myAlternatives.end()-1; i++) { 00161 RORoute *pR = *i; 00162 for (AlternativesVector::iterator j=i+1; j!=myAlternatives.end(); j++) { 00163 RORoute *pS = *j; 00164 // see [Gawron, 1998] (4.2) 00165 SUMOReal delta = 00166 (pS->getCosts() - pR->getCosts()) / 00167 (pS->getCosts() + pR->getCosts()); 00168 // see [Gawron, 1998] (4.3a, 4.3b) 00169 SUMOReal newPR = gawronF(pR->getProbability(), pS->getProbability(), delta); 00170 SUMOReal newPS = pR->getProbability() + pS->getProbability() - newPR; 00171 if (ISNAN(newPR)||ISNAN(newPS)) { 00172 newPR = pS->getCosts() > pR->getCosts() 00173 ? (SUMOReal) 1. : 0; 00174 newPS = pS->getCosts() > pR->getCosts() 00175 ? 0 : (SUMOReal) 1.; 00176 } 00177 newPR = MIN2((SUMOReal) MAX2(newPR, (SUMOReal) 0), (SUMOReal) 1); 00178 newPS = MIN2((SUMOReal) MAX2(newPS, (SUMOReal) 0), (SUMOReal) 1); 00179 pR->setProbability(newPR); 00180 pS->setProbability(newPS); 00181 } 00182 } 00183 // remove with probability of 0 (not mentioned in Gawron) 00184 for (i=myAlternatives.begin(); i!=myAlternatives.end();) { 00185 if ((*i)->getProbability()==0) { 00186 i = myAlternatives.erase(i); 00187 } else { 00188 i++; 00189 } 00190 } 00191 // find the route to use 00192 SUMOReal chosen = RandHelper::rand(); 00193 int pos = 0; 00194 for (i=myAlternatives.begin(); i!=myAlternatives.end()-1; i++, pos++) { 00195 chosen = chosen - (*i)->getProbability(); 00196 if (chosen<=0) { 00197 myLastUsed = pos; 00198 return; 00199 } 00200 } 00201 myLastUsed = pos; 00202 }
| void RORouteDef_Alternatives::addLoadedAlternative | ( | RORoute * | alternative | ) | [virtual] |
Adds an alternative loaded from the file An alternative may also be generated whicle DUA.
Definition at line 81 of file RORouteDef_Alternatives.cpp.
References myAlternatives.
Referenced by copy(), and RORDLoader_SUMOBase::myCharacters().
00081 { 00082 myAlternatives.push_back(alt); 00083 }
| RORoute * RORouteDef_Alternatives::buildCurrentRoute | ( | SUMOAbstractRouter< ROEdge, ROVehicle > & | router, | |
| SUMOTime | begin, | |||
| const ROVehicle & | veh | |||
| ) | const [virtual] |
Build the next route.
Implements RORouteDef.
Definition at line 88 of file RORouteDef_Alternatives.cpp.
References SUMOAbstractRouter< E, V >::compute(), RORouteDef::copyColorIfGiven(), findRoute(), RORoute::getEdgeVector(), myAlternatives, Named::myID, myLastUsed, myNewRoute, SUMOAbstractRouter< E, V >::recomputeCosts(), RORoute::setCosts(), and SUMOReal.
00089 { 00090 // recompute duration of the last route used 00091 // build a new route to test whether it is better 00092 std::vector<const ROEdge*> edges; 00093 router.compute(myAlternatives[0]->getFirst(), myAlternatives[0]->getLast(), &veh, begin, edges); 00094 RORoute *opt = new RORoute(myID, 0, 1, edges, copyColorIfGiven()); 00095 SUMOReal costs = router.recomputeCosts(opt->getEdgeVector(), &veh, begin); 00096 // check whether the same route was already used 00097 myLastUsed = findRoute(opt); 00098 myNewRoute = true; 00099 // delete the route when it already existed 00100 if (myLastUsed>=0) { 00101 delete opt; 00102 myNewRoute = false; 00103 myAlternatives[myLastUsed]->setCosts(costs); 00104 return myAlternatives[myLastUsed]; 00105 } 00106 // return the built route 00107 opt->setCosts(costs); 00108 return opt; 00109 }
| RORouteDef * RORouteDef_Alternatives::copy | ( | const std::string & | id | ) | const [virtual] |
Returns a copy of the route definition.
Implements RORouteDef.
Definition at line 225 of file RORouteDef_Alternatives.cpp.
References addLoadedAlternative(), myAlternatives, myGawronA, myGawronBeta, myLastUsed, myMaxRouteNumber, and RORouteDef_Alternatives().
00225 { 00226 RORouteDef_Alternatives *ret = new RORouteDef_Alternatives(id, 00227 myLastUsed, myGawronBeta, myGawronA, myMaxRouteNumber); 00228 for (std::vector<RORoute*>::const_iterator i=myAlternatives.begin(); i!=myAlternatives.end(); i++) { 00229 ret->addLoadedAlternative(new RORoute(*(*i))); 00230 } 00231 return ret; 00232 }
| const RGBColor *const RORouteDef::copyColorIfGiven | ( | ) | const throw () [protected, inherited] |
Definition at line 63 of file RORouteDef.cpp.
References RORouteDef::myColor.
Referenced by RORouteDef_OrigDest::buildCurrentRoute(), RORouteDef_Complete::buildCurrentRoute(), buildCurrentRoute(), RORouteDef_OrigDest::copy(), and RORouteDef_Complete::copy().
00063 { 00064 if (myColor==0) { 00065 return 0; 00066 } 00067 return new RGBColor(*myColor); 00068 }
| int RORouteDef_Alternatives::findRoute | ( | RORoute * | opt | ) | const [private] |
Searches for the route within the list of alternatives.
Definition at line 113 of file RORouteDef_Alternatives.cpp.
References RORoute::getEdgeVector(), and myAlternatives.
Referenced by buildCurrentRoute().
00113 { 00114 for (unsigned int i=0; i<myAlternatives.size(); i++) { 00115 if (opt->getEdgeVector() == myAlternatives[i]->getEdgeVector()) { 00116 return (int) i; 00117 } 00118 } 00119 return -1; 00120 }
| SUMOReal RORouteDef_Alternatives::gawronF | ( | SUMOReal | pdr, | |
| SUMOReal | pds, | |||
| SUMOReal | x | |||
| ) | [private] |
Performs the gawron - f() function From "Dynamic User Equilibria...".
Definition at line 206 of file RORouteDef_Alternatives.cpp.
References gawronG(), max, and myGawronA.
Referenced by addAlternative().
00206 { 00207 if (((pdr*gawronG(myGawronA, x)+pds)==0)) { 00208 return std::numeric_limits<SUMOReal>::max(); 00209 } 00210 return (pdr*(pdr+pds)*gawronG(myGawronA, x)) / 00211 (pdr*gawronG(myGawronA, x)+pds); 00212 }
| SUMOReal RORouteDef_Alternatives::gawronG | ( | SUMOReal | a, | |
| SUMOReal | x | |||
| ) | [private] |
Performs the gawron - g() function From "Dynamic User Equilibria...".
Definition at line 216 of file RORouteDef_Alternatives.cpp.
Referenced by gawronF().
00216 { 00217 if (((1.0-(x*x))==0)) { 00218 return std::numeric_limits<SUMOReal>::max(); 00219 } 00220 return (SUMOReal) exp((a*x)/(1.0-(x*x))); 00221 }
| const RGBColor* const RORouteDef::getColor | ( | ) | const [inline, inherited] |
Returns the color of the route.
Definition at line 92 of file RORouteDef.h.
References RORouteDef::myColor.
00092 { 00093 return myColor; 00094 }
| const std::string& Named::getID | ( | ) | const throw () [inline, inherited] |
Returns the id.
Definition at line 59 of file Named.h.
References Named::myID.
Referenced by addAlternative(), MSRouteProbe::addRoute(), MSEmitter::MSEmitter_FileTriggeredChild::buildAndScheduleFlowVehicle(), MSCalibrator::MSCalibrator_FileTriggeredChild::buildAndScheduleFlowVehicle(), RORouteDef_Complete::buildCurrentRoute(), ODDistrictHandler::closeDistrict(), NBTrafficLightDefinition::collectLinks(), NBTrafficLightDefinition::compute(), GUIPointOfInterest::drawGL(), MSInductLoop::enterDetectorByMove(), MSVTypeProbe::execute(), MSNet::getBusStopID(), GUITriggeredRerouter::getMicrosimID(), GUIPointOfInterest::getMicrosimID(), GUILaneSpeedTrigger::getMicrosimID(), GUIInductLoop::MyWrapper::getMicrosimID(), GUIEmitter::getMicrosimID(), GUIBusStop::getMicrosimID(), GUI_E2_ZS_Collector::MyWrapper::getMicrosimID(), traci::TraCIServer::handlePoiDomain(), RORDLoader_SUMOBase::myCharacters(), NBOwnTLDef::myCompute(), NBLoadedTLDef::myCompute(), MSTriggeredRerouter::myStartElement(), MSLaneSpeedTrigger::myStartElement(), MSEmitter::MSEmitter_FileTriggeredChild::myStartElement(), MSCalibrator::MSCalibrator_FileTriggeredChild::myStartElement(), NBLoadedTLDef::SignalGroup::patchTYellow(), TraCIServerAPI_Vehicle::processGet(), MSVehicle::replaceRoute(), MSVehicle::saveState(), NBOwnTLDef::setTLControllingInformation(), NBLoadedTLDef::setTLControllingInformation(), RORDLoader_SUMOBase::startRoute(), GUIEmitter::GUIEmitterChild_UserTriggeredChild::wrappedExecute(), NBTrafficLightLogic::writeXML(), MSRouteProbe::writeXMLOutput(), MSInductLoop::writeXMLOutput(), MSE2Collector::writeXMLOutput(), and MSVehicle::~MSVehicle().
00059 { 00060 return myID; 00061 }
| void RORouteDef_Alternatives::invalidateLast | ( | ) |
Definition at line 236 of file RORouteDef_Alternatives.cpp.
References myLastUsed.
00236 { 00237 myLastUsed = -1; 00238 }
| bool ReferencedItem::isSaved | ( | ) | const throw () [inline, inherited] |
Returns the information whether this item was already saved.
Definition at line 58 of file ReferencedItem.h.
References ReferencedItem::myWasSaved.
Referenced by RONet::computeRoute(), and ROVehicle::saveAllAsXML().
00058 { 00059 return myWasSaved; 00060 }
| void ReferencedItem::markSaved | ( | ) | throw () [inline, inherited] |
Marks the item as saved.
Definition at line 65 of file ReferencedItem.h.
References ReferencedItem::myWasSaved.
00065 { 00066 myWasSaved = true; 00067 }
| RORouteDef_Alternatives& RORouteDef_Alternatives::operator= | ( | const RORouteDef_Alternatives & | src | ) | [private] |
Invalidated assignment operator.
| void RORouteDef_Alternatives::removeLast | ( | ) |
Definition at line 242 of file RORouteDef_Alternatives.cpp.
References myAlternatives, and myLastUsed.
00242 { 00243 assert(myAlternatives.size()>=2); 00244 myAlternatives.erase(myAlternatives.end()-1); 00245 myLastUsed = (int) myAlternatives.size() - 1; 00246 // !!! recompute probabilities 00247 }
| OutputDevice & RORouteDef_Alternatives::writeXMLDefinition | ( | SUMOAbstractRouter< ROEdge, ROVehicle > & | router, | |
| OutputDevice & | dev, | |||
| const ROVehicle *const | veh, | |||
| bool | asAlternatives, | |||
| bool | withExitTimes | |||
| ) | const [virtual] |
Saves the built route / route alternatives.
Writes the route into the given stream.
| [in] | dev | The device to write the route into |
| [in] | asAlternatives | Whether the route shall be saved as route alternatives |
Implements RORouteDef.
Definition at line 251 of file RORouteDef_Alternatives.cpp.
References OutputDevice::closeTag(), RORoute::getColor(), RORoute::getCosts(), ROVehicle::getDepartureTime(), RORoute::getEdgeVector(), RORoute::getProbability(), myAlternatives, RORouteDef::myColor, myLastUsed, OutputDevice::openTag(), OutputDevice::setPrecision(), and SUMOReal.
00253 { 00254 // (optional) alternatives header 00255 if (asAlternatives) { 00256 dev.openTag("routeDistribution") << " last=\"" << myLastUsed << "\">\n"; 00257 for (size_t i=0; i!=myAlternatives.size(); i++) { 00258 const RORoute &alt = *(myAlternatives[i]); 00259 dev.openTag("route") << " cost=\"" << alt.getCosts(); 00260 dev.setPrecision(8); 00261 dev << "\" probability=\"" << alt.getProbability(); 00262 dev.setPrecision(); 00263 if (alt.getColor()!=0) { 00264 dev << "\" color=\"" << *alt.getColor(); 00265 } else if (myColor!=0) { 00266 dev << "\" color=\"" << *myColor; 00267 } 00268 dev << "\" edges=\"" << alt.getEdgeVector(); 00269 if (withExitTimes) { 00270 SUMOReal time = (SUMOReal) veh->getDepartureTime(); 00271 dev << "\" exitTimes=\""; 00272 std::vector<const ROEdge*>::const_iterator i = alt.getEdgeVector().begin(); 00273 for (; i!=alt.getEdgeVector().end(); ++i) { 00274 if (i != alt.getEdgeVector().begin()) { 00275 dev << " "; 00276 } 00277 time += (*i)->getTravelTime(veh, (SUMOTime) time); 00278 dev << time; 00279 } 00280 } 00281 (dev << "\"").closeTag(true); 00282 } 00283 dev.closeTag(); 00284 return dev; 00285 } else { 00286 return myAlternatives[myLastUsed]->writeXMLDefinition(router, dev, veh, asAlternatives, withExitTimes); 00287 } 00288 }
The alternatives.
Definition at line 106 of file RORouteDef_Alternatives.h.
Referenced by addAlternative(), addLoadedAlternative(), buildCurrentRoute(), copy(), findRoute(), removeLast(), writeXMLDefinition(), and ~RORouteDef_Alternatives().
const RGBColor* const RORouteDef::myColor [protected, inherited] |
The color the route shall have.
Definition at line 114 of file RORouteDef.h.
Referenced by RORouteDef::copyColorIfGiven(), RORouteDef::getColor(), RORouteDef_Complete::writeXMLDefinition(), writeXMLDefinition(), and RORouteDef::~RORouteDef().
SUMOReal RORouteDef_Alternatives::myGawronA [private] |
SUMOReal RORouteDef_Alternatives::myGawronBeta [private] |
gawron beta - value
Definition at line 109 of file RORouteDef_Alternatives.h.
Referenced by addAlternative(), and copy().
std::string Named::myID [protected, inherited] |
The name of the object.
Definition at line 66 of file Named.h.
Referenced by RORouteDef_OrigDest::buildCurrentRoute(), RORouteDef_Complete::buildCurrentRoute(), buildCurrentRoute(), and Named::getID().
int RORouteDef_Alternatives::myLastUsed [mutable, private] |
Index of the route used within the last step.
Definition at line 100 of file RORouteDef_Alternatives.h.
Referenced by addAlternative(), buildCurrentRoute(), copy(), invalidateLast(), removeLast(), and writeXMLDefinition().
int RORouteDef_Alternatives::myMaxRouteNumber [private] |
The maximum route number.
Definition at line 115 of file RORouteDef_Alternatives.h.
Referenced by copy().
bool RORouteDef_Alternatives::myNewRoute [mutable, private] |
Information whether a new route was generated.
Definition at line 97 of file RORouteDef_Alternatives.h.
Referenced by addAlternative(), and buildCurrentRoute().
1.5.6