SUMO - Simulation of Urban MObility
ROJTRRouter.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // Computes routes using junction turning percentages
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 <router/RONet.h>
00034 #include "ROJTRRouter.h"
00035 #include "ROJTREdge.h"
00036 #include <utils/common/MsgHandler.h>
00037 
00038 #ifdef CHECK_MEMORY_LEAKS
00039 #include <foreign/nvwa/debug_new.h>
00040 #endif // CHECK_MEMORY_LEAKS
00041 
00042 
00043 // ===========================================================================
00044 // method definitions
00045 // ===========================================================================
00046 ROJTRRouter::ROJTRRouter(RONet& net, bool unbuildIsWarningOnly, bool acceptAllDestinations,
00047                          int maxEdges, bool ignoreClasses, bool allowLoops) : 
00048     SUMOAbstractRouter<ROEdge, ROVehicle>("JTRRouter"),
00049     myNet(net), myUnbuildIsWarningOnly(unbuildIsWarningOnly),
00050     myAcceptAllDestination(acceptAllDestinations), myMaxEdges(maxEdges),
00051     myIgnoreClasses(ignoreClasses), myAllowLoops(allowLoops) 
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) const {
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 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines