|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // A complete route definition (with all passed edges being known) 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 00023 00024 // =========================================================================== 00025 // included modules 00026 // =========================================================================== 00027 #ifdef _MSC_VER 00028 #include <windows_config.h> 00029 #else 00030 #include <config.h> 00031 #endif 00032 00033 #include <string> 00034 #include <deque> 00035 #include <iterator> 00036 #include "ROEdge.h" 00037 #include "RORouteDef.h" 00038 #include "RORoute.h" 00039 #include <utils/common/SUMOAbstractRouter.h> 00040 #include <utils/common/MsgHandler.h> 00041 #include <utils/common/UtilExceptions.h> 00042 #include "RORouteDef_Complete.h" 00043 #include "ROHelper.h" 00044 #include <utils/iodevices/OutputDevice.h> 00045 #include <utils/options/OptionsCont.h> 00046 00047 #ifdef CHECK_MEMORY_LEAKS 00048 #include <foreign/nvwa/debug_new.h> 00049 #endif // CHECK_MEMORY_LEAKS 00050 00051 00052 // =========================================================================== 00053 // method definitions 00054 // =========================================================================== 00055 RORouteDef_Complete::RORouteDef_Complete(const std::string& id, 00056 const RGBColor* const color, 00057 const std::vector<const ROEdge*> &edges, 00058 bool tryRepair) 00059 : RORouteDef(id, color), myEdges(edges), myTryRepair(tryRepair) { 00060 } 00061 00062 00063 RORouteDef_Complete::~RORouteDef_Complete() {} 00064 00065 00066 RORoute* 00067 RORouteDef_Complete::buildCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle> &router, 00068 SUMOTime begin, const ROVehicle& veh) const { 00069 if (myTryRepair) { 00070 const std::vector<const ROEdge*> &oldEdges = myEdges; 00071 if (oldEdges.size() == 0) { 00072 MsgHandler* m = OptionsCont::getOptions().getBool("ignore-errors") ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance(); 00073 m->inform("Could not repair empty route of vehicle '" + veh.getID() + "'."); 00074 return new RORoute(myID, 0, 1, std::vector<const ROEdge*>(), copyColorIfGiven()); 00075 } 00076 std::vector<const ROEdge*> newEdges; 00077 newEdges.push_back(*(oldEdges.begin())); 00078 for (std::vector<const ROEdge*>::const_iterator i = oldEdges.begin() + 1; i != oldEdges.end(); ++i) { 00079 if ((*(i - 1))->isConnectedTo(*i)) { 00080 newEdges.push_back(*i); 00081 } else { 00082 std::vector<const ROEdge*> edges; 00083 router.compute(*(i - 1), *i, &veh, begin, edges); 00084 if (edges.size() == 0) { 00085 return 0; 00086 } 00087 std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges)); 00088 } 00089 } 00090 if (myEdges != newEdges) { 00091 WRITE_WARNING("Repaired route of vehicle '" + veh.getID() + "'."); 00092 } 00093 myEdges = newEdges; 00094 } 00095 SUMOReal costs = router.recomputeCosts(myEdges, &veh, begin); 00096 if (costs < 0) { 00097 throw ProcessError("Route '" + getID() + "' (vehicle '" + veh.getID() + "') is not valid."); 00098 } 00099 return new RORoute(myID, 0, 1, myEdges, copyColorIfGiven()); 00100 } 00101 00102 00103 void 00104 RORouteDef_Complete::addAlternative(SUMOAbstractRouter<ROEdge, ROVehicle> &, 00105 const ROVehicle* const, RORoute* current, SUMOTime begin) { 00106 myStartTime = begin; 00107 myEdges = current->getEdgeVector(); 00108 delete current; 00109 } 00110 00111 00112 RORouteDef* 00113 RORouteDef_Complete::copy(const std::string& id) const { 00114 return new RORouteDef_Complete(id, copyColorIfGiven(), myEdges, myTryRepair); 00115 } 00116 00117 00118 OutputDevice& 00119 RORouteDef_Complete::writeXMLDefinition(SUMOAbstractRouter<ROEdge, ROVehicle> &router, 00120 OutputDevice& dev, const ROVehicle* const veh, 00121 bool asAlternatives, bool withExitTimes) const { 00122 // (optional) alternatives header 00123 if (asAlternatives) { 00124 dev.openTag("routeDistribution") << " last=\"0\">\n"; 00125 } 00126 // the route 00127 dev.openTag("route"); 00128 if (asAlternatives) { 00129 dev << " cost=\"" << router.recomputeCosts(myEdges, veh, veh->getDepartureTime()); 00130 dev << "\" probability=\"1.00\""; 00131 } 00132 if (myColor != 0) { 00133 dev << " color=\"" << *myColor << "\""; 00134 } 00135 dev << " edges=\"" << myEdges; 00136 if (withExitTimes) { 00137 SUMOReal time = STEPS2TIME(veh->getDepartureTime()); 00138 dev << "\" exitTimes=\""; 00139 std::vector<const ROEdge*>::const_iterator i = myEdges.begin(); 00140 for (; i != myEdges.end(); ++i) { 00141 if (i != myEdges.begin()) { 00142 dev << " "; 00143 } 00144 time += (*i)->getTravelTime(veh, (SUMOTime) time); 00145 dev << time; 00146 } 00147 } 00148 (dev << "\"").closeTag(true); 00149 // (optional) alternatives end 00150 if (asAlternatives) { 00151 dev.closeTag(); 00152 } 00153 return dev; 00154 } 00155 00156 00157 00158 /****************************************************************************/ 00159