RORouteDef_Complete.cpp

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

Generated on Wed May 5 00:06:36 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6