LCOV - code coverage report
Current view: top level - src/dfrouter - RODFRouteCont.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 64.6 % 48 31
Test Date: 2024-12-21 15:45:41 Functions: 62.5 % 8 5

            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    RODFRouteCont.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Laura Bieker
      17              : /// @author  Michael Behrisch
      18              : /// @date    Thu, 16.03.2006
      19              : ///
      20              : // A container for routes
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <fstream>
      25              : #include <cassert>
      26              : #include "RODFRouteDesc.h"
      27              : #include "RODFRouteCont.h"
      28              : #include "RODFNet.h"
      29              : #include <router/ROEdge.h>
      30              : #include <utils/common/ToString.h>
      31              : #include <utils/iodevices/OutputDevice.h>
      32              : 
      33              : 
      34              : // ===========================================================================
      35              : // method definitions
      36              : // ===========================================================================
      37         1234 : RODFRouteCont::RODFRouteCont() {}
      38              : 
      39              : 
      40         1514 : RODFRouteCont::~RODFRouteCont() {
      41         1514 : }
      42              : 
      43              : 
      44              : void
      45         2003 : RODFRouteCont::addRouteDesc(RODFRouteDesc& desc) {
      46              :     // routes may be duplicate as in-between routes may have different starting points
      47         2003 :     if (find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc)) == myRoutes.end()) {
      48              :         // compute route id
      49         2001 :         setID(desc);
      50         2001 :         myRoutes.push_back(desc);
      51              :     } else {
      52            2 :         RODFRouteDesc& prev = *find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc));
      53            2 :         prev.overallProb += desc.overallProb;
      54              :     }
      55         2003 : }
      56              : 
      57              : 
      58              : bool
      59            0 : RODFRouteCont::removeRouteDesc(RODFRouteDesc& desc) {
      60            0 :     std::vector<RODFRouteDesc>::const_iterator j = find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc));
      61            0 :     if (j == myRoutes.end()) {
      62            0 :         return false;
      63              :     }
      64              :     return true;
      65              : }
      66              : 
      67              : 
      68              : bool
      69          215 : RODFRouteCont::save(std::vector<std::string>& saved,
      70              :                     const std::string& prependix, OutputDevice& out) {
      71              :     bool haveSavedOneAtLeast = false;
      72         1029 :     for (std::vector<RODFRouteDesc>::const_iterator j = myRoutes.begin(); j != myRoutes.end(); ++j) {
      73              :         const RODFRouteDesc& desc = (*j);
      74          814 :         if (find(saved.begin(), saved.end(), desc.routename) != saved.end()) {
      75          238 :             continue;
      76              :         }
      77          576 :         saved.push_back((*j).routename);
      78              :         assert(desc.edges2Pass.size() >= 1);
      79          576 :         out.openTag(SUMO_TAG_ROUTE).writeAttr(SUMO_ATTR_ID, prependix + desc.routename);
      80          576 :         out << " edges=\"";
      81         3162 :         for (ROEdgeVector::const_iterator k = desc.edges2Pass.begin(); k != desc.edges2Pass.end(); k++) {
      82         2586 :             if (k != desc.edges2Pass.begin()) {
      83         2010 :                 out << ' ';
      84              :             }
      85         2586 :             out << (*k)->getID();
      86              :         }
      87          576 :         out << '"';
      88         1152 :         out.closeTag();
      89              :         haveSavedOneAtLeast = true;
      90              :     }
      91          215 :     return haveSavedOneAtLeast;
      92              : }
      93              : 
      94              : 
      95              : void
      96            0 : RODFRouteCont::sortByDistance() {
      97            0 :     sort(myRoutes.begin(), myRoutes.end(), by_distance_sorter());
      98            0 : }
      99              : 
     100              : 
     101              : void
     102            0 : RODFRouteCont::removeIllegal(const std::vector<ROEdgeVector >& illegals) {
     103            0 :     for (std::vector<RODFRouteDesc>::iterator i = myRoutes.begin(); i != myRoutes.end();) {
     104              :         RODFRouteDesc& desc = *i;
     105              :         bool remove = false;
     106            0 :         for (std::vector<ROEdgeVector >::const_iterator j = illegals.begin(); !remove && j != illegals.end(); ++j) {
     107              :             int noFound = 0;
     108            0 :             for (ROEdgeVector::const_iterator k = (*j).begin(); !remove && k != (*j).end(); ++k) {
     109            0 :                 if (find(desc.edges2Pass.begin(), desc.edges2Pass.end(), *k) != desc.edges2Pass.end()) {
     110            0 :                     noFound++;
     111            0 :                     if (noFound > 1) {
     112              :                         remove = true;
     113              :                     }
     114              :                 }
     115              :             }
     116              :         }
     117            0 :         if (remove) {
     118            0 :             i = myRoutes.erase(i);
     119              :         } else {
     120              :             ++i;
     121              :         }
     122              :     }
     123            0 : }
     124              : 
     125              : 
     126              : void
     127         2001 : RODFRouteCont::setID(RODFRouteDesc& desc) const {
     128              :     std::pair<ROEdge*, ROEdge*> c(desc.edges2Pass[0], desc.edges2Pass.back());
     129         6003 :     desc.routename = c.first->getID() + "_to_" + c.second->getID();
     130         2001 :     if (myConnectionOccurrences.find(c) == myConnectionOccurrences.end()) {
     131         1859 :         myConnectionOccurrences[c] = 0;
     132              :     } else {
     133          142 :         myConnectionOccurrences[c] = myConnectionOccurrences[c] + 1;
     134          284 :         desc.routename = desc.routename + "_" + toString(myConnectionOccurrences[c]);
     135              :     }
     136         2001 : }
     137              : 
     138              : 
     139              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1