LCOV - code coverage report
Current view: top level - src/router - RORoute.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 59 65 90.8 %
Date: 2024-05-07 15:28:01 Functions: 11 12 91.7 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2002-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    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      680733 : RORoute::RORoute(const std::string& id, double costs, double prop,
      39             :                  const ConstROEdgeVector& route,
      40             :                  const RGBColor* const color,
      41      680733 :                  const std::vector<SUMOVehicleParameter::Stop>& stops)
      42     1361466 :     : Named(StringUtils::convertUmlaute(id)), myCosts(costs),
      43      680733 :       myProbability(prop), myRoute(route), myColor(color), myStops(stops) {}
      44             : 
      45         116 : RORoute::RORoute(const std::string& id, const ConstROEdgeVector& route)
      46         232 :     : 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     1361698 : RORoute::~RORoute() {
      59      680849 :     delete myColor;
      60     1361698 : }
      61             : 
      62             : 
      63             : void
      64      614639 : RORoute::setCosts(double costs) {
      65      614639 :     myCosts = costs;
      66      614639 : }
      67             : 
      68             : 
      69             : void
      70     1422635 : RORoute::setProbability(double prob) {
      71     1422635 :     myProbability = prob;
      72     1422635 : }
      73             : 
      74             : 
      75             : void
      76        5112 : RORoute::recheckForLoops(const ConstROEdgeVector& mandatory) {
      77        5112 :     ROHelper::recheckForLoops(myRoute, mandatory);
      78        5112 : }
      79             : 
      80             : bool
      81         952 : RORoute::isValid(const ROVehicle& veh, bool ignoreErrors) const {
      82         952 :     MsgHandler* mh = ignoreErrors ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance();
      83        3844 :     for (ConstROEdgeVector::const_iterator i = myRoute.begin() + 1; i != myRoute.end(); ++i) {
      84        2898 :         const ROEdge* prev = *(i - 1);
      85        2898 :         const ROEdge* cur = *i;
      86        2898 :         if (!prev->isConnectedTo(*cur, veh.getVClass())) {
      87          12 :             mh->informf("Edge '%' not connected to edge '%' for vehicle '%'.", prev->getID(), cur->getID(), veh.getID());
      88             :             return ignoreErrors;
      89             :         }
      90             :     }
      91             :     return true;
      92             : }
      93             : 
      94             : 
      95             : void
      96       37950 : RORoute::addProbability(double prob) {
      97       37950 :     myProbability += prob;
      98       37950 : }
      99             : 
     100             : 
     101             : ConstROEdgeVector
     102      772278 : RORoute::getNormalEdges() const {
     103             :     ConstROEdgeVector tempRoute;
     104     5534042 :     for (const ROEdge* roe : myRoute) {
     105     4761764 :         if (!roe->isInternal() && !roe->isTazConnector()) {
     106     4710096 :             tempRoute.push_back(roe);
     107             :         }
     108             :     }
     109      772278 :     return tempRoute;
     110             : }
     111             : 
     112             : 
     113             : OutputDevice&
     114      772257 : RORoute::writeXMLDefinition(OutputDevice& dev, const ROVehicle* const veh,
     115             :                             const bool withCosts,
     116             :                             const bool withProb,
     117             :                             const bool withExitTimes,
     118             :                             const bool withLength,
     119             :                             const std::string& id) const {
     120      772257 :     dev.openTag(SUMO_TAG_ROUTE);
     121      772257 :     if (id != "") {
     122             :         dev.writeAttr(SUMO_ATTR_ID, id);
     123             :     }
     124      772257 :     if (withCosts) {
     125      521819 :         dev.writeAttr(SUMO_ATTR_COST, myCosts);
     126      521819 :         dev.setPrecision(8);
     127             :     }
     128      772257 :     if (withProb) {
     129      521787 :         dev.writeAttr(SUMO_ATTR_PROB, myProbability);
     130      521787 :         dev.setPrecision();
     131             :     }
     132      772257 :     if (myColor != nullptr) {
     133             :         dev.writeAttr(SUMO_ATTR_COLOR, *myColor);
     134             :     }
     135      772257 :     dev.writeAttr(SUMO_ATTR_EDGES, getNormalEdges());
     136      772257 :     if (withExitTimes) {
     137             :         std::vector<double> exitTimes;
     138      402550 :         double time = STEPS2TIME(veh->getDepartureTime());
     139     2497330 :         for (const ROEdge* const roe : myRoute) {
     140     2094780 :             time += roe->getTravelTime(veh, time);
     141     2094780 :             if (!roe->isInternal() && !roe->isTazConnector()) {
     142     2094780 :                 exitTimes.push_back(time);
     143             :             }
     144             :         }
     145      805100 :         dev.writeAttr("exitTimes", exitTimes);
     146             :     }
     147      772257 :     if (withLength) {
     148          30 :         double length = 0.;
     149          98 :         for (const ROEdge* const roe : myRoute) {
     150          68 :             length += roe->getLength();
     151             :         }
     152          60 :         dev.writeAttr("routeLength", length);
     153             :     }
     154      772257 :     dev.closeTag();
     155      772257 :     return dev;
     156             : }
     157             : 
     158             : 
     159             : /****************************************************************************/

Generated by: LCOV version 1.14