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

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2025 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          112 : ROJTRRouter::ROJTRRouter(bool unbuildIsWarningOnly, bool acceptAllDestinations,
      34              :                          int maxEdges, bool ignoreClasses,
      35              :                          bool allowLoops,
      36          112 :                          bool discountSources) :
      37              :     SUMOAbstractRouter<ROEdge, ROVehicle>("JTRRouter", unbuildIsWarningOnly, &ROEdge::getTravelTimeStatic, nullptr, false, false),
      38          112 :     myUnbuildIsWarningOnly(unbuildIsWarningOnly),
      39          112 :     myAcceptAllDestination(acceptAllDestinations), myMaxEdges(maxEdges),
      40          112 :     myIgnoreClasses(ignoreClasses),
      41          112 :     myAllowLoops(allowLoops),
      42          112 :     myDiscountSources(discountSources)
      43          112 : { }
      44              : 
      45              : 
      46          112 : ROJTRRouter::~ROJTRRouter() {}
      47              : 
      48              : 
      49              : bool
      50         6147 : 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         6147 :     if (myDiscountSources && current->getSourceFlow() <= 0) {
      55              :         return true;
      56              :     }
      57         4222 :     double timeS = STEPS2TIME(time);
      58              :     std::set<const ROEdge*> avoidEdges;
      59              :     // route until a sinks has been found
      60       331307 :     while (current != nullptr && current != to &&
      61       338632 :             (!current->isSink() || current == from || current->getSourceFlow() > 0) &&
      62       328592 :             (int)into.size() < myMaxEdges) {
      63       328491 :         into.push_back(current);
      64              :         const_cast<ROJTREdge*>(current)->changeSourceFlow(-1);
      65       328491 :         if (!myAllowLoops) {
      66        30821 :             avoidEdges.insert(current);
      67              :         }
      68       328491 :         timeS += current->getTravelTime(vehicle, timeS);
      69       656686 :         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         4222 :     if (current == nullptr || (int) into.size() >= myMaxEdges) {
      74         1495 :         if (myAcceptAllDestination) {
      75              :             return true;
      76              :         } else {
      77          501 :             if (!silent) {
      78          501 :                 MsgHandler* mh = myUnbuildIsWarningOnly ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance();
      79         1503 :                 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         2727 :         into.push_back(current);
      87              :     }
      88         2727 :     return true;
      89              : }
      90              : 
      91              : 
      92              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1