LCOV - code coverage report
Current view: top level - src/jtrrouter - ROJTRRouter.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 28 28 100.0 %
Date: 2024-05-06 15:32:35 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4             : // This program and the accompanying materials are made available under the
       5             : // terms of the Eclipse Public License 2.0 which is available at
       6             : // https://www.eclipse.org/legal/epl-2.0/
       7             : // This Source Code may also be made available under the following Secondary
       8             : // Licenses when the conditions for such availability set forth in the Eclipse
       9             : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10             : // or later which is available at
      11             : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12             : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13             : /****************************************************************************/
      14             : /// @file    ROJTRRouter.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Jakob Erdmann
      17             : /// @author  Michael Behrisch
      18             : /// @date    Tue, 20 Jan 2004
      19             : ///
      20             : // Computes routes using junction turning percentages
      21             : /****************************************************************************/
      22             : #include <config.h>
      23             : 
      24             : #include <router/RONet.h>
      25             : #include "ROJTRRouter.h"
      26             : #include "ROJTREdge.h"
      27             : #include <utils/common/MsgHandler.h>
      28             : 
      29             : 
      30             : // ===========================================================================
      31             : // method definitions
      32             : // ===========================================================================
      33         162 : ROJTRRouter::ROJTRRouter(bool unbuildIsWarningOnly, bool acceptAllDestinations,
      34             :                          int maxEdges, bool ignoreClasses,
      35             :                          bool allowLoops,
      36         162 :                          bool discountSources) :
      37             :     SUMOAbstractRouter<ROEdge, ROVehicle>("JTRRouter", unbuildIsWarningOnly, &ROEdge::getTravelTimeStatic, nullptr, false, false),
      38         162 :     myUnbuildIsWarningOnly(unbuildIsWarningOnly),
      39         162 :     myAcceptAllDestination(acceptAllDestinations), myMaxEdges(maxEdges),
      40         162 :     myIgnoreClasses(ignoreClasses),
      41         162 :     myAllowLoops(allowLoops),
      42         162 :     myDiscountSources(discountSources)
      43         162 : { }
      44             : 
      45             : 
      46         162 : ROJTRRouter::~ROJTRRouter() {}
      47             : 
      48             : 
      49             : bool
      50        8520 : ROJTRRouter::compute(const ROEdge* from, const ROEdge* to,
      51             :                      const ROVehicle* const vehicle,
      52             :                      SUMOTime time, ConstROEdgeVector& into, bool silent) {
      53             :     const ROJTREdge* current = static_cast<const ROJTREdge*>(from);
      54        8520 :     if (myDiscountSources && current->getSourceFlow() <= 0) {
      55             :         return true;
      56             :     }
      57        5970 :     double timeS = STEPS2TIME(time);
      58             :     std::set<const ROEdge*> avoidEdges;
      59             :     // route until a sinks has been found
      60      649303 :     while (current != nullptr && current != to &&
      61      659778 :             (!current->isSink() || current == from || current->getSourceFlow() > 0) &&
      62      645706 :             (int)into.size() < myMaxEdges) {
      63      645505 :         into.push_back(current);
      64             :         const_cast<ROJTREdge*>(current)->changeSourceFlow(-1);
      65      645505 :         if (!myAllowLoops) {
      66       50235 :             avoidEdges.insert(current);
      67             :         }
      68      645505 :         timeS += current->getTravelTime(vehicle, timeS);
      69     1290714 :         current = current->chooseNext(myIgnoreClasses ? nullptr : vehicle, timeS, avoidEdges);
      70             :         assert(myIgnoreClasses || current == 0 || !current->prohibits(vehicle));
      71             :     }
      72             :     // check whether no valid ending edge was found
      73        5970 :     if (current == nullptr || (int) into.size() >= myMaxEdges) {
      74        2361 :         if (myAcceptAllDestination) {
      75             :             return true;
      76             :         } else {
      77         501 :             if (!silent) {
      78         501 :                 MsgHandler* mh = myUnbuildIsWarningOnly ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance();
      79        1002 :                 mh->inform("The route starting at edge '" + from->getID() + "' could not be closed.");
      80             :             }
      81         501 :             return false;
      82             :         }
      83             :     }
      84             :     // append the sink
      85             :     if (current != nullptr) {
      86        3609 :         into.push_back(current);
      87             :     }
      88        3609 :     return true;
      89             : }
      90             : 
      91             : 
      92             : /****************************************************************************/

Generated by: LCOV version 1.14