LCOV - code coverage report
Current view: top level - src/netimport/vissim/tempstructs - NIVissimConflictArea.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 80.4 % 46 37
Test Date: 2024-11-22 15:46:21 Functions: 75.0 % 8 6

            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    NIVissimConflictArea.cpp
      15              : /// @author  Lukas Grohmann
      16              : /// @date    Aug 2015
      17              : ///
      18              : // A temporary storage for conflict areas imported from Vissim
      19              : /****************************************************************************/
      20              : #include <config.h>
      21              : 
      22              : #include <iterator>
      23              : #include <map>
      24              : #include <string>
      25              : #include <utils/common/ToString.h>
      26              : #include <utils/common/StringUtils.h>
      27              : #include "NIVissimConflictArea.h"
      28              : #include "NIVissimConnection.h"
      29              : #include <netbuild/NBEdgeCont.h>
      30              : #include <netbuild/NBEdge.h>
      31              : #include <netbuild/NBNode.h>
      32              : 
      33              : 
      34              : // ===========================================================================
      35              : // static members
      36              : // ===========================================================================
      37              : NIVissimConflictArea::DictType NIVissimConflictArea::myDict;
      38              : 
      39              : 
      40              : // ===========================================================================
      41              : // method definitions
      42              : // ===========================================================================
      43           50 : NIVissimConflictArea::NIVissimConflictArea(int id,
      44              :         const std::string& link1,
      45              :         const std::string& link2,
      46           50 :         const std::string& status)
      47          100 :     : myConflictID(id), myFirstLink(link1), mySecondLink(link2), myStatus(status) {
      48           50 : }
      49              : 
      50              : 
      51           50 : NIVissimConflictArea::~NIVissimConflictArea() {}
      52              : 
      53              : 
      54              : 
      55              : 
      56              : bool
      57           50 : NIVissimConflictArea::dictionary(int id, const std::string& link1,
      58              :                                  const std::string& link2,
      59              :                                  const std::string& status) {
      60           50 :     NIVissimConflictArea* ca = new NIVissimConflictArea(id, link1, link2, status);
      61           50 :     if (!dictionary(id, ca)) {
      62            0 :         delete ca;
      63            0 :         return false;
      64              :     }
      65              :     return true;
      66              : }
      67              : 
      68              : 
      69              : 
      70              : bool
      71           50 : NIVissimConflictArea::dictionary(int id, NIVissimConflictArea* ca) {
      72              :     DictType::iterator i = myDict.find(id);
      73           50 :     if (i == myDict.end()) {
      74           50 :         myDict[id] = ca;
      75           50 :         return true;
      76              :     }
      77              :     return false;
      78              : }
      79              : 
      80              : 
      81              : 
      82              : NIVissimConflictArea*
      83            0 : NIVissimConflictArea::dictionary(int id) {
      84              :     DictType::iterator i = myDict.find(id);
      85            0 :     if (i == myDict.end()) {
      86              :         return nullptr;
      87              :     }
      88            0 :     return (*i).second;
      89              : }
      90              : 
      91              : 
      92              : 
      93              : NIVissimConflictArea*
      94            0 : NIVissimConflictArea::dict_findByLinks(const std::string& link1,
      95              :                                        const std::string& link2) {
      96            0 :     for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
      97            0 :         if (((*i).second->myFirstLink == link1) &&
      98            0 :                 ((*i).second->mySecondLink == link2)) {
      99              :             return (*i).second;
     100              :         }
     101              :     }
     102              :     return nullptr;
     103              : }
     104              : 
     105              : 
     106              : void
     107            9 : NIVissimConflictArea::clearDict() {
     108           59 :     for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
     109           50 :         delete (*i).second;
     110              :     }
     111              :     myDict.clear();
     112            9 : }
     113              : 
     114              : 
     115              : void
     116            9 : NIVissimConflictArea::setPriorityRegulation(NBEdgeCont& ec) {
     117              :     std::map<int, NIVissimConflictArea*>::iterator it;
     118           59 :     for (it = myDict.begin(); it != myDict.end(); it++) {
     119           50 :         NIVissimConflictArea* const conflictArea = it->second;
     120          100 :         NIVissimConnection* const firstLink = NIVissimConnection::dictionary(StringUtils::toInt(conflictArea->getFirstLink()));
     121           50 :         NIVissimConnection* const secondLink = NIVissimConnection::dictionary(StringUtils::toInt(conflictArea->getSecondLink()));
     122           50 :         if (firstLink == nullptr || secondLink == nullptr) {
     123           33 :             continue;
     124              :         }
     125              :         // status == "TWOYIELDSONE"
     126              :         NIVissimConnection* priority_conn = firstLink;
     127              :         NIVissimConnection* subordinate_conn = secondLink;
     128           17 :         if (conflictArea->getStatus() == "ONEYIELDSTWO") {
     129              :             priority_conn = secondLink;
     130              :             subordinate_conn = firstLink;
     131              :         }
     132           17 :         const std::string mayDriveFrom_id = toString<int>(priority_conn->getFromEdgeID());
     133           17 :         const std::string mayDriveTo_id = toString<int>(priority_conn->getToEdgeID());
     134           17 :         const std::string mustStopFrom_id = toString<int>(subordinate_conn->getFromEdgeID());
     135           17 :         const std::string mustStopTo_id = toString<int>(subordinate_conn->getToEdgeID());
     136              : 
     137           17 :         NBEdge* const mayDriveFrom =  ec.retrievePossiblySplit(mayDriveFrom_id, true);
     138           17 :         NBEdge* const mayDriveTo =  ec.retrievePossiblySplit(mayDriveTo_id, false);
     139           17 :         NBEdge* const mustStopFrom =  ec.retrievePossiblySplit(mustStopFrom_id, true);
     140           17 :         NBEdge* const mustStopTo =  ec.retrievePossiblySplit(mustStopTo_id, false);
     141              : 
     142           17 :         if (mayDriveFrom != nullptr && mayDriveTo != nullptr && mustStopFrom != nullptr && mustStopTo != nullptr) {
     143              :             NBNode* node = mayDriveFrom->getToNode();
     144           17 :             node->addSortedLinkFoes(
     145           34 :                 NBConnection(mayDriveFrom, mayDriveTo),
     146           34 :                 NBConnection(mustStopFrom, mustStopTo));
     147              :         }
     148              :     }
     149            9 : }
     150              : 
     151              : 
     152              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1