Path: blob/main/src/netimport/vissim/tempstructs/NIVissimConflictArea.cpp
169684 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file NIVissimConflictArea.cpp14/// @author Lukas Grohmann15/// @date Aug 201516///17// A temporary storage for conflict areas imported from Vissim18/****************************************************************************/19#include <config.h>2021#include <iterator>22#include <map>23#include <string>24#include <utils/common/ToString.h>25#include <utils/common/StringUtils.h>26#include "NIVissimConflictArea.h"27#include "NIVissimConnection.h"28#include <netbuild/NBEdgeCont.h>29#include <netbuild/NBEdge.h>30#include <netbuild/NBNode.h>313233// ===========================================================================34// static members35// ===========================================================================36NIVissimConflictArea::DictType NIVissimConflictArea::myDict;373839// ===========================================================================40// method definitions41// ===========================================================================42NIVissimConflictArea::NIVissimConflictArea(int id,43const std::string& link1,44const std::string& link2,45const std::string& status)46: myConflictID(id), myFirstLink(link1), mySecondLink(link2), myStatus(status) {47}484950NIVissimConflictArea::~NIVissimConflictArea() {}5152535455bool56NIVissimConflictArea::dictionary(int id, const std::string& link1,57const std::string& link2,58const std::string& status) {59NIVissimConflictArea* ca = new NIVissimConflictArea(id, link1, link2, status);60if (!dictionary(id, ca)) {61delete ca;62return false;63}64return true;65}66676869bool70NIVissimConflictArea::dictionary(int id, NIVissimConflictArea* ca) {71DictType::iterator i = myDict.find(id);72if (i == myDict.end()) {73myDict[id] = ca;74return true;75}76return false;77}78798081NIVissimConflictArea*82NIVissimConflictArea::dictionary(int id) {83DictType::iterator i = myDict.find(id);84if (i == myDict.end()) {85return nullptr;86}87return (*i).second;88}89909192NIVissimConflictArea*93NIVissimConflictArea::dict_findByLinks(const std::string& link1,94const std::string& link2) {95for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {96if (((*i).second->myFirstLink == link1) &&97((*i).second->mySecondLink == link2)) {98return (*i).second;99}100}101return nullptr;102}103104105void106NIVissimConflictArea::clearDict() {107for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {108delete (*i).second;109}110myDict.clear();111}112113114void115NIVissimConflictArea::setPriorityRegulation(NBEdgeCont& ec) {116std::map<int, NIVissimConflictArea*>::iterator it;117for (it = myDict.begin(); it != myDict.end(); it++) {118NIVissimConflictArea* const conflictArea = it->second;119NIVissimConnection* const firstLink = NIVissimConnection::dictionary(StringUtils::toInt(conflictArea->getFirstLink()));120NIVissimConnection* const secondLink = NIVissimConnection::dictionary(StringUtils::toInt(conflictArea->getSecondLink()));121if (firstLink == nullptr || secondLink == nullptr) {122continue;123}124// status == "TWOYIELDSONE"125NIVissimConnection* priority_conn = firstLink;126NIVissimConnection* subordinate_conn = secondLink;127if (conflictArea->getStatus() == "ONEYIELDSTWO") {128priority_conn = secondLink;129subordinate_conn = firstLink;130}131const std::string mayDriveFrom_id = toString<int>(priority_conn->getFromEdgeID());132const std::string mayDriveTo_id = toString<int>(priority_conn->getToEdgeID());133const std::string mustStopFrom_id = toString<int>(subordinate_conn->getFromEdgeID());134const std::string mustStopTo_id = toString<int>(subordinate_conn->getToEdgeID());135136NBEdge* const mayDriveFrom = ec.retrievePossiblySplit(mayDriveFrom_id, true);137NBEdge* const mayDriveTo = ec.retrievePossiblySplit(mayDriveTo_id, false);138NBEdge* const mustStopFrom = ec.retrievePossiblySplit(mustStopFrom_id, true);139NBEdge* const mustStopTo = ec.retrievePossiblySplit(mustStopTo_id, false);140141if (mayDriveFrom != nullptr && mayDriveTo != nullptr && mustStopFrom != nullptr && mustStopTo != nullptr) {142NBNode* node = mayDriveFrom->getToNode();143node->addSortedLinkFoes(144NBConnection(mayDriveFrom, mayDriveTo),145NBConnection(mustStopFrom, mustStopTo));146}147}148}149150151/****************************************************************************/152153154