LCOV - code coverage report
Current view: top level - src/router - RORoute.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 90.9 % 77 70
Test Date: 2025-11-14 15:59:05 Functions: 92.3 % 13 12

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2002-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    RORoute.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @author  Yun-Pang Floetteroed
      18              : /// @date    Sept 2002
      19              : ///
      20              : // A complete router's route
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <string>
      25              : #include <iostream>
      26              : #include <utils/common/Named.h>
      27              : #include <utils/common/StringUtils.h>
      28              : #include <utils/common/StdDefs.h>
      29              : #include "ROEdge.h"
      30              : #include "RORoute.h"
      31              : #include "ROHelper.h"
      32              : #include <utils/iodevices/OutputDevice.h>
      33              : 
      34              : 
      35              : // ===========================================================================
      36              : // method definitions
      37              : // ===========================================================================
      38       617883 : RORoute::RORoute(const std::string& id, double costs, double prop,
      39              :                  const ConstROEdgeVector& route,
      40              :                  const RGBColor* const color,
      41       617883 :                  const StopParVector& stops)
      42       617883 :     : Named(StringUtils::convertUmlaute(id)), myCosts(costs),
      43       617883 :       myProbability(prop), myRoute(route), myColor(color), myStops(stops) {}
      44              : 
      45          116 : RORoute::RORoute(const std::string& id, const ConstROEdgeVector& route)
      46          116 :     : Named(StringUtils::convertUmlaute(id)), myCosts(0.0),
      47          116 :       myProbability(0.0), myRoute(route), myColor(nullptr), myStops() {}
      48              : 
      49            0 : RORoute::RORoute(const RORoute& src)
      50            0 :     : Named(src.myID), myCosts(src.myCosts),
      51            0 :       myProbability(src.myProbability), myRoute(src.myRoute), myColor(nullptr) {
      52            0 :     if (src.myColor != nullptr) {
      53            0 :         myColor = new RGBColor(*src.myColor);
      54              :     }
      55            0 : }
      56              : 
      57              : 
      58      1235964 : RORoute::~RORoute() {
      59       617982 :     delete myColor;
      60      1235964 : }
      61              : 
      62              : 
      63              : void
      64       455024 : RORoute::setCosts(double costs) {
      65       455024 :     myCosts = costs;
      66       455024 : }
      67              : 
      68              : 
      69              : void
      70       726446 : RORoute::setProbability(double prob) {
      71       726446 :     myProbability = prob;
      72       726446 : }
      73              : 
      74              : 
      75              : void
      76         5218 : RORoute::recheckForLoops(const ConstROEdgeVector& mandatory) {
      77         5218 :     ROHelper::recheckForLoops(myRoute, mandatory);
      78         5218 : }
      79              : 
      80              : bool
      81          952 : RORoute::isValid(const ROVehicle& veh, bool ignoreErrors, MsgHandler* mh) const {
      82          952 :     if (mh == nullptr) {
      83          952 :         mh = ignoreErrors ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance();
      84              :     }
      85         3844 :     for (ConstROEdgeVector::const_iterator i = myRoute.begin() + 1; i != myRoute.end(); ++i) {
      86         2898 :         const ROEdge* prev = *(i - 1);
      87         2898 :         const ROEdge* cur = *i;
      88         2898 :         if (!prev->isConnectedTo(*cur, veh.getVClass())) {
      89           12 :             mh->informf("Edge '%' not connected to edge '%' for vehicle '%'.", prev->getID(), cur->getID(), veh.getID());
      90              :             return ignoreErrors;
      91              :         }
      92              :     }
      93              :     return true;
      94              : }
      95              : 
      96              : 
      97              : bool
      98       236768 : RORoute::isPermitted(const ROVehicle* veh, MsgHandler* mh) const {
      99       236768 :     const bool hasRestrictions = RONet::getInstance()->hasRestrictions();
     100       236768 :     const bool hasPermissions = RONet::getInstance()->hasPermissions();
     101       236768 :     if (hasRestrictions || hasPermissions) {
     102        82884 :         for (const ROEdge* e: myRoute) {
     103       137078 :             if ((hasPermissions && e->prohibits(veh)) || (hasRestrictions && e->restricts(veh))) {
     104           38 :                 mh->informf("Vehicle '%' is not permitted on Edge '%'", veh->getID(), e->getID());
     105              :                 return false;
     106              :             }
     107              :         }
     108              :     }
     109              :     return true;
     110              : }
     111              : 
     112              : 
     113              : void
     114        38114 : RORoute::addProbability(double prob) {
     115        38114 :     myProbability += prob;
     116        38114 : }
     117              : 
     118              : 
     119              : ConstROEdgeVector
     120       473535 : RORoute::getNormalEdges() const {
     121              :     ConstROEdgeVector tempRoute;
     122      3210558 :     for (const ROEdge* roe : myRoute) {
     123      2737023 :         if (!roe->isInternal() && !roe->isTazConnector()) {
     124      2712757 :             tempRoute.push_back(roe);
     125              :         }
     126              :     }
     127       473535 :     return tempRoute;
     128            0 : }
     129              : 
     130              : 
     131              : OutputDevice&
     132       473514 : RORoute::writeXMLDefinition(OutputDevice& dev, const ROVehicle* const veh,
     133              :                             const bool withCosts,
     134              :                             const bool asAlternatives,
     135              :                             const bool withExitTimes,
     136              :                             const bool withLength,
     137              :                             const std::string& id) const {
     138       473514 :     dev.openTag(SUMO_TAG_ROUTE);
     139       473514 :     if (id != "") {
     140            7 :         dev.writeAttr(SUMO_ATTR_ID, id);
     141              :     }
     142       473514 :     if (withCosts) {
     143       275249 :         dev.writeAttr(SUMO_ATTR_COST, myCosts);
     144              :     }
     145       473514 :     if (asAlternatives) {
     146       275201 :         dev.setPrecision(8);
     147       275201 :         dev.writeAttr(SUMO_ATTR_PROB, myProbability);
     148       275201 :         dev.setPrecision();
     149              :     }
     150       473514 :     if (myColor != nullptr) {
     151           68 :         dev.writeAttr(SUMO_ATTR_COLOR, *myColor);
     152              :     }
     153       473514 :     dev.writeAttr(SUMO_ATTR_EDGES, getNormalEdges());
     154       473514 :     if (withExitTimes) {
     155              :         std::vector<double> exitTimes;
     156       201417 :         double time = STEPS2TIME(veh->getDepartureTime());
     157      1249251 :         for (const ROEdge* const roe : myRoute) {
     158      1047834 :             time += roe->getTravelTime(veh, time);
     159      1047834 :             if (!roe->isInternal() && !roe->isTazConnector()) {
     160      1047834 :                 exitTimes.push_back(time);
     161              :             }
     162              :         }
     163       201417 :         dev.writeAttr("exitTimes", exitTimes);
     164       201417 :     }
     165       473514 :     if (withLength) {
     166           97 :         double length = 0.;
     167          323 :         for (const ROEdge* const roe : myRoute) {
     168          226 :             length += roe->getLength();
     169              :         }
     170          194 :         dev.writeAttr("routeLength", length);
     171              :     }
     172       473514 :     dev.closeTag();
     173       473514 :     return dev;
     174              : }
     175              : 
     176              : 
     177              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1