LCOV - code coverage report
Current view: top level - src/microsim - MSRightOfWayJunction.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 98.7 % 77 76
Test Date: 2026-01-01 15:49:29 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-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    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              : #include <utils/common/MsgHandler.h>
      36              : 
      37              : 
      38              : // ===========================================================================
      39              : // method definitions
      40              : // ===========================================================================
      41       291225 : MSRightOfWayJunction::MSRightOfWayJunction(const std::string& id,
      42              :         SumoXMLNodeType type,
      43              :         const Position& position,
      44              :         const PositionVector& shape,
      45              :         const std::string& name,
      46              :         std::vector<MSLane*> incoming,
      47              :         std::vector<MSLane*> internal,
      48       291225 :         MSJunctionLogic* logic) : MSLogicJunction(id, type, position, shape, name, incoming, internal),
      49       291225 :     myLogic(logic) {}
      50              : 
      51              : 
      52       576336 : MSRightOfWayJunction::~MSRightOfWayJunction() {
      53       288168 :     delete myLogic;
      54       576336 : }
      55              : 
      56              : 
      57              : void
      58       290387 : MSRightOfWayJunction::postloadInit() {
      59              :     // inform links where they have to report approaching vehicles to
      60       290387 :     int requestPos = 0;
      61              :     // going through the incoming lanes...
      62              :     int maxNo = 0;
      63              :     std::vector<std::pair<const MSLane*, MSLink*> > sortedLinks;
      64      1152963 :     for (MSLane* const lane : myIncomingLanes) {
      65              :         // ... set information for every link
      66      2522109 :         for (MSLink* const link : lane->getLinkCont()) {
      67      3206030 :             if (link->getLane()->isWalkingArea() ||
      68      1580641 :                     (lane->isWalkingArea() && !link->getLane()->isCrossing())) {
      69       129891 :                 continue;
      70              :             }
      71      1529642 :             sortedLinks.emplace_back(lane, link);
      72      1529642 :             ++maxNo;
      73              :         }
      74              :     }
      75              : 
      76       290387 :     const bool hasFoes = myLogic->hasFoes();
      77      1152959 :     for (const MSLane* const lane : myIncomingLanes) {
      78              :         // ... set information for every link
      79              :         const MSLane* walkingAreaFoe = nullptr;
      80      2522105 :         for (MSLink* const link : lane->getLinkCont()) {
      81      1659533 :             if (link->getLane()->isWalkingArea()) {
      82       113036 :                 if (lane->getPermissions() != SVC_PEDESTRIAN) {
      83              :                     // vehicular lane connects to a walkingarea
      84         2230 :                     walkingAreaFoe = link->getLane();
      85              :                 }
      86       129891 :                 continue;
      87      1546497 :             } else if ((lane->isWalkingArea() && !link->getLane()->isCrossing())) {
      88        16855 :                 continue;
      89              :             }
      90      1529642 :             if (myLogic->getLogicSize() <= requestPos) {
      91           12 :                 throw ProcessError(TLF("Found invalid logic position of a link for junction '%' (%, max %) -> (network error)", getID(), toString(requestPos), toString(myLogic->getLogicSize())));
      92              :             }
      93      1529638 :             const MSLogicJunction::LinkBits& linkResponse = myLogic->getResponseFor(requestPos); // SUMO_ATTR_RESPONSE
      94      1529638 :             const MSLogicJunction::LinkBits& linkFoes = myLogic->getFoesFor(requestPos); // SUMO_ATTR_FOES
      95      1529638 :             bool cont = myLogic->getIsCont(requestPos);
      96     17474628 :             for (int c = 0; c < maxNo; ++c) {
      97     15944990 :                 if (linkResponse.test(c)) {
      98      2529140 :                     MSLink* foe = sortedLinks[c].second;
      99      2529140 :                     myLinkFoeLinks[link].push_back(foe);
     100      2529140 :                     if (MSGlobals::gUsingInternalLanes && foe->getViaLane() != nullptr) {
     101              :                         assert(foe->getViaLane()->getLinkCont().size() == 1);
     102      1035280 :                         MSLink* foeExitLink = foe->getViaLane()->getLinkCont()[0];
     103              :                         // add foe links after an internal junction
     104      1035280 :                         if (foeExitLink->getViaLane() != nullptr) {
     105       281776 :                             myLinkFoeLinks[link].push_back(foeExitLink);
     106              :                         }
     107              :                     }
     108              :                 }
     109              :             }
     110              :             std::vector<MSLink*> foes;
     111     17474628 :             for (int c = 0; c < maxNo; ++c) {
     112     15944990 :                 if (linkFoes.test(c)) {
     113      4907184 :                     MSLink* foe = sortedLinks[c].second;
     114      4907184 :                     foes.push_back(foe);
     115              :                     MSLane* l = foe->getViaLane();
     116      4907184 :                     if (l == nullptr) {
     117      2884335 :                         continue;
     118              :                     }
     119              :                     // add foe links after an internal junction
     120      4045698 :                     for (MSLink* const vLink : l->getLinkCont()) {
     121      2022849 :                         if (vLink->getViaLane() != nullptr) {
     122       639525 :                             foes.push_back(vLink);
     123              :                         }
     124              :                     }
     125              :                 }
     126              :             }
     127              : 
     128      1529638 :             if (MSGlobals::gUsingInternalLanes && myInternalLanes.size() > 0) {
     129              :                 int li = 0;
     130      7385452 :                 for (int c = 0; c < (int)sortedLinks.size(); ++c) {
     131      6731827 :                     if (sortedLinks[c].second->getLane() == nullptr) { // dead end
     132            0 :                         continue;
     133              :                     }
     134      6731827 :                     if (linkFoes.test(c)) {
     135              :                         // vehicles waiting at an internal junction can mostly be ignored. The main exceptions are:
     136              :                         // - they are on the main road and the current link is from a side road
     137              :                         // - its a tls and the current link is on a side road relative to the internal junction
     138              :                         // both cases are encoded in a positive linkResponse
     139              :                         // (case 2 only if netconvert option --tls.ignore-internal-junction-jam was not set)
     140      2122196 :                         myLinkFoeInternalLanes[link].push_back(myInternalLanes[li]);
     141      3033478 :                         if (link->getLane()->isCrossing() || linkResponse.test(c) || sortedLinks[c].second->isIndirect() ||
     142       911282 :                                 link->getLane()->getBidiLane() == sortedLinks[c].second->getLaneBefore()) {
     143      1213999 :                             const std::vector<MSLane::IncomingLaneInfo>& l = myInternalLanes[li]->getIncomingLanes();
     144      1213999 :                             if (l.size() == 1 && l[0].lane->getEdge().isInternal()) {
     145       317253 :                                 myLinkFoeInternalLanes[link].push_back(l[0].lane);
     146              :                             }
     147              :                         }
     148              :                     }
     149      6731827 :                     ++li;
     150              :                 }
     151              :             }
     152      1529638 :             link->setRequestInformation((int)requestPos, hasFoes, cont, myLinkFoeLinks[link], myLinkFoeInternalLanes[link]);
     153              :             // the exit link for a link before an internal junction is handled in MSInternalJunction
     154              :             // so we need to skip if cont=true
     155      1529638 :             if (MSGlobals::gUsingInternalLanes && link->getViaLane() != nullptr && !cont) {
     156              :                 assert(link->getViaLane()->getLinkCont().size() == 1);
     157       494330 :                 MSLink* exitLink = link->getViaLane()->getLinkCont()[0];
     158       494330 :                 exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
     159       494330 :                                                 myLinkFoeInternalLanes[link], link->getViaLane());
     160      1637838 :                 for (const auto& ili : exitLink->getLane()->getIncomingLanes()) {
     161      1148647 :                     if (ili.lane->isWalkingArea()) {
     162         5139 :                         exitLink->addWalkingAreaFoeExit(ili.lane);
     163              :                         break;
     164              :                     }
     165              :                 }
     166              :             }
     167              :             // the exit link for a crossing is needed for the pedestrian model
     168      1529638 :             if (MSGlobals::gUsingInternalLanes && link->getLane()->isCrossing()) {
     169        17289 :                 MSLink* exitLink = link->getLane()->getLinkCont()[0];
     170        17289 :                 exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
     171        17289 :                                                 myLinkFoeInternalLanes[link], link->getLane());
     172              :             }
     173      1529638 :             requestPos++;
     174      1529638 :         }
     175       862572 :         if (walkingAreaFoe != nullptr && lane->getLinkCont().size() > 1) {
     176        10028 :             for (const MSLink* const link : lane->getLinkCont()) {
     177         7826 :                 if (!link->getLane()->isWalkingArea()) {
     178         5624 :                     MSLink* exitLink = link->getViaLane()->getLinkCont()[0];
     179              :                     exitLink->addWalkingAreaFoe(walkingAreaFoe);
     180              :                 }
     181              :             }
     182              :         }
     183              :     }
     184       290387 : }
     185              : 
     186              : 
     187              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1