ROJTRRouter.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The junction-percentage router
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 <router/RONet.h>
00031 #include "ROJTRRouter.h"
00032 #include "ROJTREdge.h"
00033 #include <utils/common/MsgHandler.h>
00034 #include <utils/options/OptionsCont.h>
00035 
00036 #ifdef CHECK_MEMORY_LEAKS
00037 #include <foreign/nvwa/debug_new.h>
00038 #endif // CHECK_MEMORY_LEAKS
00039 
00040 
00041 // ===========================================================================
00042 // method definitions
00043 // ===========================================================================
00044 ROJTRRouter::ROJTRRouter(RONet &net, bool unbuildIsWarningOnly,
00045                          bool acceptAllDestinations)
00046         : myNet(net), myUnbuildIsWarningOnly(unbuildIsWarningOnly),
00047         myAcceptAllDestination(acceptAllDestinations) {
00048     myMaxEdges = (int)(
00049                      ((SUMOReal) net.getEdgeNo()) *
00050                      OptionsCont::getOptions().getFloat("max-edges-factor"));
00051     myIgnoreClasses = OptionsCont::getOptions().getBool("ignore-classes");
00052 }
00053 
00054 
00055 ROJTRRouter::~ROJTRRouter() {}
00056 
00057 
00058 void
00059 ROJTRRouter::compute(const ROEdge *from, const ROEdge * /*to*/,
00060                      const ROVehicle * const vehicle,
00061                      SUMOTime time, std::vector<const ROEdge*> &into) {
00062     const ROJTREdge *current = static_cast<const ROJTREdge*>(from);
00063     // route until a sinks has been found
00064     while (current!=0
00065             &&
00066             current->getType()!=ROEdge::ET_SINK
00067             &&
00068             (int) into.size()<myMaxEdges) {
00069 
00070         into.push_back(current);
00071         time += (SUMOTime) current->getTravelTime(vehicle, time);
00072         current = current->chooseNext(myIgnoreClasses ? 0 : vehicle, time);
00073         assert(myIgnoreClasses||current==0||!current->prohibits(vehicle));
00074     }
00075     // check whether no valid ending edge was found
00076     if ((int) into.size()>=myMaxEdges) {
00077         if (myAcceptAllDestination) {
00078             return;
00079         } else {
00080             MsgHandler *mh = 0;
00081             if (myUnbuildIsWarningOnly) {
00082                 mh = MsgHandler::getWarningInstance();
00083             } else {
00084                 mh = MsgHandler::getErrorInstance();
00085             }
00086             mh->inform("The route starting at edge '" + from->getID() + "' could not be closed.");
00087         }
00088     }
00089     // append the sink
00090     if (current!=0) {
00091         into.push_back(current);
00092     }
00093 }
00094 
00095 
00096 SUMOReal
00097 ROJTRRouter::recomputeCosts(const std::vector<const ROEdge*> &edges, const ROVehicle * const v, SUMOTime time) throw() {
00098     SUMOReal costs = 0;
00099     for (std::vector<const ROEdge*>::const_iterator i=edges.begin(); i!=edges.end(); i++) {
00100         /*
00101         if (PF::operator()(*i, v)) {
00102             return -1;
00103         }
00104         */
00105         costs += (*i)->getTravelTime(v, time);
00106     }
00107     return costs;
00108 }
00109 
00110 
00111 
00112 /****************************************************************************/
00113 

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