LCOV - code coverage report
Current view: top level - src/microsim - MSRightOfWayJunction.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 98.7 % 75 74
Test Date: 2024-10-24 15:46:30 Functions: 100.0 % 4 4

            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    MSRightOfWayJunction.cpp
      15              : /// @author  Christian Roessel
      16              : /// @author  Daniel Krajzewicz
      17              : /// @author  Michael Behrisch
      18              : /// @author  Jakob Erdmann
      19              : /// @date    Wed, 12 Dez 2001
      20              : ///
      21              : // junction.
      22              : /****************************************************************************/
      23              : #include <config.h>
      24              : 
      25              : #include <algorithm>
      26              : #include <cassert>
      27              : #include <cmath>
      28              : #include <utils/common/RandHelper.h>
      29              : #include "MSEdge.h"
      30              : #include "MSJunctionLogic.h"
      31              : #include "MSGlobals.h"
      32              : #include "MSLane.h"
      33              : #include "MSLink.h"
      34              : #include "MSRightOfWayJunction.h"
      35              : 
      36              : 
      37              : // ===========================================================================
      38              : // method definitions
      39              : // ===========================================================================
      40       317555 : MSRightOfWayJunction::MSRightOfWayJunction(const std::string& id,
      41              :         SumoXMLNodeType type,
      42              :         const Position& position,
      43              :         const PositionVector& shape,
      44              :         const std::string& name,
      45              :         std::vector<MSLane*> incoming,
      46              :         std::vector<MSLane*> internal,
      47       317555 :         MSJunctionLogic* logic) : MSLogicJunction(id, type, position, shape, name, incoming, internal),
      48       317555 :     myLogic(logic) {}
      49              : 
      50              : 
      51       584520 : MSRightOfWayJunction::~MSRightOfWayJunction() {
      52       292260 :     delete myLogic;
      53       584520 : }
      54              : 
      55              : 
      56              : void
      57       316715 : MSRightOfWayJunction::postloadInit() {
      58              :     // inform links where they have to report approaching vehicles to
      59       316715 :     int requestPos = 0;
      60              :     // going through the incoming lanes...
      61              :     int maxNo = 0;
      62              :     std::vector<std::pair<const MSLane*, MSLink*> > sortedLinks;
      63      1236883 :     for (MSLane* const lane : myIncomingLanes) {
      64              :         // ... set information for every link
      65      2636057 :         for (MSLink* const link : lane->getLinkCont()) {
      66      1715889 :             if (link->getLane()->getEdge().isWalkingArea() ||
      67        30638 :                     (lane->getEdge().isWalkingArea() && !link->getLane()->getEdge().isCrossing())) {
      68       109572 :                 continue;
      69              :             }
      70      1606317 :             sortedLinks.emplace_back(lane, link);
      71      1606317 :             ++maxNo;
      72              :         }
      73              :     }
      74              : 
      75       316715 :     const bool hasFoes = myLogic->hasFoes();
      76      1236879 :     for (const MSLane* const lane : myIncomingLanes) {
      77              :         // ... set information for every link
      78              :         const MSLane* walkingAreaFoe = nullptr;
      79      2636053 :         for (MSLink* const link : lane->getLinkCont()) {
      80      1715889 :             if (link->getLane()->getEdge().isWalkingArea()) {
      81        94508 :                 if (lane->getPermissions() != SVC_PEDESTRIAN) {
      82              :                     // vehicular lane connects to a walkingarea
      83              :                     walkingAreaFoe = link->getLane();
      84              :                 }
      85       109572 :                 continue;
      86      1621381 :             } else if ((lane->getEdge().isWalkingArea() && !link->getLane()->getEdge().isCrossing())) {
      87        15064 :                 continue;
      88              :             }
      89      1606317 :             if (myLogic->getLogicSize() <= requestPos) {
      90           16 :                 throw ProcessError("Found invalid logic position of a link for junction '" + getID() + "' (" + toString(requestPos) + ", max " + toString(myLogic->getLogicSize()) + ") -> (network error)");
      91              :             }
      92      1606313 :             const MSLogicJunction::LinkBits& linkResponse = myLogic->getResponseFor(requestPos); // SUMO_ATTR_RESPONSE
      93      1606313 :             const MSLogicJunction::LinkBits& linkFoes = myLogic->getFoesFor(requestPos); // SUMO_ATTR_FOES
      94      1606313 :             bool cont = myLogic->getIsCont(requestPos);
      95     18262690 :             for (int c = 0; c < maxNo; ++c) {
      96     16656377 :                 if (linkResponse.test(c)) {
      97      2596416 :                     MSLink* foe = sortedLinks[c].second;
      98      2596416 :                     myLinkFoeLinks[link].push_back(foe);
      99      2596416 :                     if (MSGlobals::gUsingInternalLanes && foe->getViaLane() != nullptr) {
     100              :                         assert(foe->getViaLane()->getLinkCont().size() == 1);
     101      1185398 :                         MSLink* foeExitLink = foe->getViaLane()->getLinkCont()[0];
     102              :                         // add foe links after an internal junction
     103      1185398 :                         if (foeExitLink->getViaLane() != nullptr) {
     104       316164 :                             myLinkFoeLinks[link].push_back(foeExitLink);
     105              :                         }
     106              :                     }
     107              :                 }
     108              :             }
     109              :             std::vector<MSLink*> foes;
     110     18262690 :             for (int c = 0; c < maxNo; ++c) {
     111     16656377 :                 if (linkFoes.test(c)) {
     112      5060834 :                     MSLink* foe = sortedLinks[c].second;
     113      5060834 :                     foes.push_back(foe);
     114              :                     MSLane* l = foe->getViaLane();
     115      5060834 :                     if (l == nullptr) {
     116      2735405 :                         continue;
     117              :                     }
     118              :                     // add foe links after an internal junction
     119      4650858 :                     for (MSLink* const vLink : l->getLinkCont()) {
     120      2325429 :                         if (vLink->getViaLane() != nullptr) {
     121       703004 :                             foes.push_back(vLink);
     122              :                         }
     123              :                     }
     124              :                 }
     125              :             }
     126              : 
     127      1606313 :             if (MSGlobals::gUsingInternalLanes && myInternalLanes.size() > 0) {
     128              :                 int li = 0;
     129      8678976 :                 for (int c = 0; c < (int)sortedLinks.size(); ++c) {
     130      7902539 :                     if (sortedLinks[c].second->getLane() == nullptr) { // dead end
     131            0 :                         continue;
     132              :                     }
     133      7902539 :                     if (linkFoes.test(c)) {
     134      2416786 :                         myLinkFoeInternalLanes[link].push_back(myInternalLanes[li]);
     135      3570286 :                         if (linkResponse.test(c) || sortedLinks[c].second->isIndirect() ||
     136      1153500 :                                 link->getLane()->getBidiLane() == sortedLinks[c].second->getLaneBefore()) {
     137      1266285 :                             const std::vector<MSLane::IncomingLaneInfo>& l = myInternalLanes[li]->getIncomingLanes();
     138      1266285 :                             if (l.size() == 1 && l[0].lane->getEdge().isInternal()) {
     139       316381 :                                 myLinkFoeInternalLanes[link].push_back(l[0].lane);
     140              :                             }
     141              :                         }
     142              :                     }
     143      7902539 :                     ++li;
     144              :                 }
     145              :             }
     146      1606313 :             link->setRequestInformation((int)requestPos, hasFoes, cont, myLinkFoeLinks[link], myLinkFoeInternalLanes[link]);
     147              :             // the exit link for a link before an internal junction is handled in MSInternalJunction
     148              :             // so we need to skip if cont=true
     149      1606313 :             if (MSGlobals::gUsingInternalLanes && link->getViaLane() != nullptr && !cont) {
     150              :                 assert(link->getViaLane()->getLinkCont().size() == 1);
     151       608496 :                 MSLink* exitLink = link->getViaLane()->getLinkCont()[0];
     152       608496 :                 exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
     153       608496 :                                                 myLinkFoeInternalLanes[link], link->getViaLane());
     154      2023930 :                 for (const auto& ili : exitLink->getLane()->getIncomingLanes()) {
     155      1421417 :                     if (ili.lane->getEdge().isWalkingArea()) {
     156              :                         exitLink->addWalkingAreaFoeExit(ili.lane);
     157              :                         break;
     158              :                     }
     159              :                 }
     160              :             }
     161              :             // the exit link for a crossing is needed for the pedestrian model
     162      1606313 :             if (MSGlobals::gUsingInternalLanes && link->getLane()->getEdge().isCrossing()) {
     163        15574 :                 MSLink* exitLink = link->getLane()->getLinkCont()[0];
     164        15574 :                 exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
     165        15574 :                                                 myLinkFoeInternalLanes[link], link->getLane());
     166              :             }
     167      1606313 :             requestPos++;
     168      1606313 :         }
     169       920164 :         if (walkingAreaFoe != nullptr && lane->getLinkCont().size() > 1) {
     170        11780 :             for (const MSLink* const link : lane->getLinkCont()) {
     171         9187 :                 if (!link->getLane()->getEdge().isWalkingArea()) {
     172         6594 :                     MSLink* exitLink = link->getViaLane()->getLinkCont()[0];
     173              :                     exitLink->addWalkingAreaFoe(walkingAreaFoe);
     174              :                 }
     175              :             }
     176              :         }
     177              :     }
     178       316715 : }
     179              : 
     180              : 
     181              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1