RORoute.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A complete router's route
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 <iostream>
00032 #include <utils/common/Named.h>
00033 #include <utils/common/StringUtils.h>
00034 #include "ROEdge.h"
00035 #include "RORoute.h"
00036 #include "ROHelper.h"
00037 #include <utils/iodevices/OutputDevice.h>
00038 
00039 #ifdef CHECK_MEMORY_LEAKS
00040 #include <foreign/nvwa/debug_new.h>
00041 #endif // CHECK_MEMORY_LEAKS
00042 
00043 
00044 // ===========================================================================
00045 // method definitions
00046 // ===========================================================================
00047 RORoute::RORoute(const std::string &id, SUMOReal costs, SUMOReal prop,
00048                  const std::vector<const ROEdge*> &route,
00049                  const RGBColor * const color) throw()
00050         : Named(StringUtils::convertUmlaute(id)), myCosts(costs),
00051         myProbability(prop), myRoute(route), myColor(color) {}
00052 
00053 
00054 RORoute::RORoute(const RORoute &src) throw()
00055         : Named(src.myID), myCosts(src.myCosts),
00056         myProbability(src.myProbability), myRoute(src.myRoute), myColor(0) {
00057     if (src.myColor!=0) {
00058         myColor = new RGBColor(*src.myColor);
00059     }
00060 }
00061 
00062 
00063 RORoute::~RORoute() throw() {
00064     delete myColor;
00065 }
00066 
00067 
00068 void
00069 RORoute::add(ROEdge *edge) throw() {
00070     myRoute.push_back(edge);
00071 }
00072 
00073 
00074 void
00075 RORoute::setCosts(SUMOReal costs) throw() {
00076     myCosts = costs;
00077 }
00078 
00079 
00080 void
00081 RORoute::setProbability(SUMOReal prob) throw() {
00082     myProbability = prob;
00083 }
00084 
00085 
00086 void
00087 RORoute::recheckForLoops() throw() {
00088     ROHelper::recheckForLoops(myRoute);
00089 }
00090 
00091 
00092 OutputDevice &
00093 RORoute::writeXMLDefinition(SUMOAbstractRouter<ROEdge,ROVehicle> &router,
00094                             OutputDevice &dev, const ROVehicle * const veh, bool asAlternatives, bool withExitTimes) const {
00095     // (optional) alternatives header
00096     if (asAlternatives) {
00097         dev.openTag("routeDistribution") << " last=\"0\">\n";
00098     }
00099     // the route
00100     dev.openTag("route");
00101     if (asAlternatives) {
00102         dev << " cost=\"" << myCosts;
00103         dev.setPrecision(8);
00104         dev << "\" probability=\"" << myProbability << "\"";
00105         dev.setPrecision();
00106     }
00107     if (myColor!=0) {
00108         dev << " color=\"" << *myColor << "\"";
00109     }
00110     dev << " edges=\"" << myRoute;
00111     if (withExitTimes) {
00112         SUMOReal time = (SUMOReal) veh->getDepartureTime() / 1000.;
00113         dev << "\" exitTimes=\"";
00114         std::vector<const ROEdge*>::const_iterator i = myRoute.begin();
00115         for (; i!=myRoute.end(); ++i) {
00116             if (i != myRoute.begin()) {
00117                 dev << " ";
00118             }
00119             time += (*i)->getTravelTime(veh, (SUMOTime) time);
00120             dev << time;
00121         }
00122     }
00123     (dev << "\"").closeTag(true);
00124     // (optional) alternatives end
00125     if (asAlternatives) {
00126         dev.closeTag();
00127     }
00128     return dev;
00129 }
00130 
00131 
00132 
00133 
00134 /****************************************************************************/
00135 

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