LCOV - code coverage report
Current view: top level - src/router - ROCCHMetrics.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 19 19
Test Date: 2026-09-23 15:43:02 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2026 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    ROCCHMetrics.cpp
      15              : /// @author  Pranav Sateesh
      16              : /// @date    2026
      17              : ///
      18              : // The CCH metric store of the router applications (see ROCCHMetrics.h).
      19              : /****************************************************************************/
      20              : #include <config.h>
      21              : 
      22              : #include "ROCCHMetrics.h"
      23              : 
      24              : #include "ROEdge.h"
      25              : #include "ROVehicle.h"
      26              : 
      27              : // ===========================================================================
      28              : // static member definitions
      29              : // ===========================================================================
      30              : ROCCHMetricFamily* ROCCHMetrics::myFamily = nullptr;
      31              : 
      32              : 
      33              : // ===========================================================================
      34              : // ROCCHMetrics method definitions
      35              : // ===========================================================================
      36              : void
      37          547 : ROCCHMetrics::init(const ROCCHGraph* graph, ROCCHGraph::EffortOperation effort,
      38              :                    SUMOTime begin, SUMOTime weightPeriod) {
      39          547 :     delete myFamily;
      40              :     // no reference-vehicle factory: each (type, period) pair is customized
      41              :     // exactly once per fill, so the first querying vehicle of a type is that
      42              :     // type's effort reference
      43          547 :     myFamily = new ROCCHMetricFamily(graph, effort, begin, weightPeriod,
      44          547 :                                      nullptr, &ROCCHMetrics::patchRestrictions);
      45          547 : }
      46              : 
      47              : 
      48              : const RoutingKit::CustomizableContractionHierarchyMetric*
      49         4808 : ROCCHMetrics::get(SUMOVehicleClass vClass, SUMOTime time, const ROVehicle* veh) {
      50         4808 :     if (myFamily == nullptr) {
      51              :         return nullptr;  // not initialised -> caller falls back to A*
      52              :     }
      53              :     // keyed by the TYPE (nullptr covers vehicle-less queries): everything the
      54              :     // effort function reads from the type is exact per metric -- see
      55              :     // CCHMetricFamily.h
      56         9616 :     return myFamily->get(veh == nullptr ? nullptr : veh->getType(), vClass, time, veh);
      57              : }
      58              : 
      59              : 
      60              : SUMOTime
      61          788 : ROCCHMetrics::periodEnd(SUMOTime time) {
      62          788 :     return myFamily == nullptr ? SUMOTime_MAX : myFamily->periodEnd(time);
      63              : }
      64              : 
      65              : 
      66              : void
      67           48 : ROCCHMetrics::reset(const ROVehicle* /* veh */) {
      68           48 :     if (myFamily != nullptr) {
      69              :         myFamily->flagStale();
      70              :     }
      71           48 : }
      72              : 
      73              : 
      74              : void
      75          414 : ROCCHMetrics::patchRestrictions(const ROCCHGraph* graph, const ROVehicle* veh,
      76              :                                 std::vector<unsigned>& weights) {
      77          414 :     if (veh == nullptr || veh->getType()->paramRestrictions.empty()) {
      78              :         return;
      79              :     }
      80              :     // mask the edges that restrict this type (restricts() depends only on
      81              :     // the type's paramRestrictions vector). arcsOfEdge of a real edge is
      82              :     // exactly the arcs headed by it -- via chains hold internal edges only --
      83              :     // matching what the exact routers check per relaxation.
      84           64 :     for (const ROEdge* const e : ROEdge::getAllEdges()) {
      85           88 :         if (!e->isInternal() && !e->isTazConnector() && e->restricts(veh)) {
      86            6 :             for (const unsigned a : graph->arcsOfEdge(e)) {
      87            3 :                 weights[a] = RoutingKit::inf_weight;
      88              :             }
      89              :         }
      90              :     }
      91              : }
        

Generated by: LCOV version 2.0-1