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