|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A complete route definition (with all passed edges being known) 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 <deque> 00032 #include <iterator> 00033 #include "ROEdge.h" 00034 #include "RORouteDef.h" 00035 #include "RORoute.h" 00036 #include <utils/common/SUMOAbstractRouter.h> 00037 #include <utils/common/MsgHandler.h> 00038 #include <utils/common/UtilExceptions.h> 00039 #include "RORouteDef_Complete.h" 00040 #include "ROHelper.h" 00041 #include <utils/iodevices/OutputDevice.h> 00042 #include <utils/options/OptionsCont.h> 00043 00044 #ifdef CHECK_MEMORY_LEAKS 00045 #include <foreign/nvwa/debug_new.h> 00046 #endif // CHECK_MEMORY_LEAKS 00047 00048 00049 // =========================================================================== 00050 // method definitions 00051 // =========================================================================== 00052 RORouteDef_Complete::RORouteDef_Complete(const std::string& id, 00053 const RGBColor* const color, 00054 const std::vector<const ROEdge*> &edges, 00055 bool tryRepair) throw() 00056 : RORouteDef(id, color), myEdges(edges), myTryRepair(tryRepair) { 00057 } 00058 00059 00060 RORouteDef_Complete::~RORouteDef_Complete() throw() {} 00061 00062 00063 RORoute* 00064 RORouteDef_Complete::buildCurrentRoute(SUMOAbstractRouter<ROEdge,ROVehicle> &router, 00065 SUMOTime begin, const ROVehicle& veh) const { 00066 if (myTryRepair) { 00067 const std::vector<const ROEdge*> &oldEdges = myEdges; 00068 if (oldEdges.size()==0) { 00069 MsgHandler* m = OptionsCont::getOptions().getBool("ignore-errors") ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance(); 00070 m->inform("Could not repair empty route of vehicle '" + veh.getID() + "'."); 00071 return new RORoute(myID, 0, 1, std::vector<const ROEdge*>(), copyColorIfGiven()); 00072 } 00073 std::vector<const ROEdge*> newEdges; 00074 newEdges.push_back(*(oldEdges.begin())); 00075 for (std::vector<const ROEdge*>::const_iterator i=oldEdges.begin()+1; i!=oldEdges.end(); ++i) { 00076 if ((*(i-1))->isConnectedTo(*i)) { 00077 newEdges.push_back(*i); 00078 } else { 00079 std::vector<const ROEdge*> edges; 00080 router.compute(*(i-1), *i, &veh, begin, edges); 00081 if (edges.size()==0) { 00082 return 0; 00083 } 00084 std::copy(edges.begin()+1, edges.end(), back_inserter(newEdges)); 00085 } 00086 } 00087 if (myEdges!=newEdges) { 00088 WRITE_WARNING("Repaired route of vehicle '" + veh.getID() + "'."); 00089 } 00090 myEdges = newEdges; 00091 } 00092 SUMOReal costs = router.recomputeCosts(myEdges, &veh, begin); 00093 if (costs<0) { 00094 throw ProcessError("Route '" + getID() + "' (vehicle '" + veh.getID() + "') is not valid."); 00095 } 00096 return new RORoute(myID, 0, 1, myEdges, copyColorIfGiven()); 00097 } 00098 00099 00100 void 00101 RORouteDef_Complete::addAlternative(SUMOAbstractRouter<ROEdge,ROVehicle> &, 00102 const ROVehicle* const, RORoute* current, SUMOTime begin) { 00103 myStartTime = begin; 00104 myEdges = current->getEdgeVector(); 00105 delete current; 00106 } 00107 00108 00109 RORouteDef* 00110 RORouteDef_Complete::copy(const std::string& id) const { 00111 return new RORouteDef_Complete(id, copyColorIfGiven(), myEdges, myTryRepair); 00112 } 00113 00114 00115 OutputDevice& 00116 RORouteDef_Complete::writeXMLDefinition(SUMOAbstractRouter<ROEdge,ROVehicle> &router, 00117 OutputDevice& dev, const ROVehicle* const veh, 00118 bool asAlternatives, bool withExitTimes) const { 00119 // (optional) alternatives header 00120 if (asAlternatives) { 00121 dev.openTag("routeDistribution") << " last=\"0\">\n"; 00122 } 00123 // the route 00124 dev.openTag("route"); 00125 if (asAlternatives) { 00126 dev << " cost=\"" << router.recomputeCosts(myEdges, veh, veh->getDepartureTime()); 00127 dev << "\" probability=\"1.00\""; 00128 } 00129 if (myColor!=0) { 00130 dev << " color=\"" << *myColor << "\""; 00131 } 00132 dev << " edges=\"" << myEdges; 00133 if (withExitTimes) { 00134 SUMOReal time = STEPS2TIME(veh->getDepartureTime()); 00135 dev << "\" exitTimes=\""; 00136 std::vector<const ROEdge*>::const_iterator i = myEdges.begin(); 00137 for (; i!=myEdges.end(); ++i) { 00138 if (i != myEdges.begin()) { 00139 dev << " "; 00140 } 00141 time += (*i)->getTravelTime(veh, (SUMOTime) time); 00142 dev << time; 00143 } 00144 } 00145 (dev << "\"").closeTag(true); 00146 // (optional) alternatives end 00147 if (asAlternatives) { 00148 dev.closeTag(); 00149 } 00150 return dev; 00151 } 00152 00153 00154 00155 /****************************************************************************/ 00156