|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A complete router's route 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 00020 00021 // =========================================================================== 00022 // included modules 00023 // =========================================================================== 00024 #ifdef _MSC_VER 00025 #include <windows_config.h> 00026 #else 00027 #include <config.h> 00028 #endif 00029 00030 #include <string> 00031 #include <iostream> 00032 #include <utils/common/Named.h> 00033 #include <utils/common/StringUtils.h> 00034 #include <utils/common/StdDefs.h> 00035 #include "ROEdge.h" 00036 #include "RORoute.h" 00037 #include "ROHelper.h" 00038 #include <utils/iodevices/OutputDevice.h> 00039 00040 #ifdef CHECK_MEMORY_LEAKS 00041 #include <foreign/nvwa/debug_new.h> 00042 #endif // CHECK_MEMORY_LEAKS 00043 00044 00045 // =========================================================================== 00046 // method definitions 00047 // =========================================================================== 00048 RORoute::RORoute(const std::string& id, SUMOReal costs, SUMOReal prop, 00049 const std::vector<const ROEdge*> &route, 00050 const RGBColor* const color) throw() 00051 : Named(StringUtils::convertUmlaute(id)), myCosts(costs), 00052 myProbability(prop), myRoute(route), myColor(color) {} 00053 00054 00055 RORoute::RORoute(const RORoute& src) throw() 00056 : Named(src.myID), myCosts(src.myCosts), 00057 myProbability(src.myProbability), myRoute(src.myRoute), myColor(0) { 00058 if (src.myColor!=0) { 00059 myColor = new RGBColor(*src.myColor); 00060 } 00061 } 00062 00063 00064 RORoute::~RORoute() throw() { 00065 delete myColor; 00066 } 00067 00068 00069 void 00070 RORoute::add(ROEdge* edge) throw() { 00071 myRoute.push_back(edge); 00072 } 00073 00074 00075 void 00076 RORoute::setCosts(SUMOReal costs) throw() { 00077 myCosts = costs; 00078 } 00079 00080 00081 void 00082 RORoute::setProbability(SUMOReal prob) throw() { 00083 myProbability = prob; 00084 } 00085 00086 00087 void 00088 RORoute::recheckForLoops() throw() { 00089 ROHelper::recheckForLoops(myRoute); 00090 } 00091 00092 00093 OutputDevice& 00094 RORoute::writeXMLDefinition(SUMOAbstractRouter<ROEdge,ROVehicle> &router, 00095 OutputDevice& dev, const ROVehicle* const veh, bool asAlternatives, bool withExitTimes) const { 00096 UNUSED_PARAMETER(router); 00097 // (optional) alternatives header 00098 if (asAlternatives) { 00099 dev.openTag("routeDistribution") << " last=\"0\">\n"; 00100 } 00101 // the route 00102 dev.openTag("route"); 00103 if (asAlternatives) { 00104 dev << " cost=\"" << myCosts; 00105 dev.setPrecision(8); 00106 dev << "\" probability=\"" << myProbability << "\""; 00107 dev.setPrecision(); 00108 } 00109 if (myColor!=0) { 00110 dev << " color=\"" << *myColor << "\""; 00111 } 00112 dev << " edges=\"" << myRoute; 00113 if (withExitTimes) { 00114 SUMOReal time = STEPS2TIME(veh->getDepartureTime()); 00115 dev << "\" exitTimes=\""; 00116 std::vector<const ROEdge*>::const_iterator i = myRoute.begin(); 00117 for (; i!=myRoute.end(); ++i) { 00118 if (i != myRoute.begin()) { 00119 dev << " "; 00120 } 00121 time += (*i)->getTravelTime(veh, (SUMOTime) time); 00122 dev << time; 00123 } 00124 } 00125 (dev << "\"").closeTag(true); 00126 // (optional) alternatives end 00127 if (asAlternatives) { 00128 dev.closeTag(); 00129 } 00130 return dev; 00131 } 00132 00133 00134 00135 00136 /****************************************************************************/ 00137