Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NIVissimConflictArea.cpp
Go to the documentation of this file.
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/****************************************************************************/
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>
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// ===========================================================================
38
39
40// ===========================================================================
41// method definitions
42// ===========================================================================
44 const std::string& link1,
45 const std::string& link2,
46 const std::string& status)
47 : myConflictID(id), myFirstLink(link1), mySecondLink(link2), myStatus(status) {
48}
49
50
52
53
54
55
56bool
57NIVissimConflictArea::dictionary(int id, const std::string& link1,
58 const std::string& link2,
59 const std::string& status) {
60 NIVissimConflictArea* ca = new NIVissimConflictArea(id, link1, link2, status);
61 if (!dictionary(id, ca)) {
62 delete ca;
63 return false;
64 }
65 return true;
66}
67
68
69
70bool
72 DictType::iterator i = myDict.find(id);
73 if (i == myDict.end()) {
74 myDict[id] = ca;
75 return true;
76 }
77 return false;
78}
79
80
81
84 DictType::iterator i = myDict.find(id);
85 if (i == myDict.end()) {
86 return nullptr;
87 }
88 return (*i).second;
89}
90
91
92
95 const std::string& link2) {
96 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
97 if (((*i).second->myFirstLink == link1) &&
98 ((*i).second->mySecondLink == link2)) {
99 return (*i).second;
100 }
101 }
102 return nullptr;
103}
104
105
106void
108 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
109 delete (*i).second;
110 }
111 myDict.clear();
112}
113
114
115void
117 std::map<int, NIVissimConflictArea*>::iterator it;
118 for (it = myDict.begin(); it != myDict.end(); it++) {
119 NIVissimConflictArea* const conflictArea = it->second;
122 if (firstLink == nullptr || secondLink == nullptr) {
123 continue;
124 }
125 // status == "TWOYIELDSONE"
126 NIVissimConnection* priority_conn = firstLink;
127 NIVissimConnection* subordinate_conn = secondLink;
128 if (conflictArea->getStatus() == "ONEYIELDSTWO") {
129 priority_conn = secondLink;
130 subordinate_conn = firstLink;
131 }
132 const std::string mayDriveFrom_id = toString<int>(priority_conn->getFromEdgeID());
133 const std::string mayDriveTo_id = toString<int>(priority_conn->getToEdgeID());
134 const std::string mustStopFrom_id = toString<int>(subordinate_conn->getFromEdgeID());
135 const std::string mustStopTo_id = toString<int>(subordinate_conn->getToEdgeID());
136
137 NBEdge* const mayDriveFrom = ec.retrievePossiblySplit(mayDriveFrom_id, true);
138 NBEdge* const mayDriveTo = ec.retrievePossiblySplit(mayDriveTo_id, false);
139 NBEdge* const mustStopFrom = ec.retrievePossiblySplit(mustStopFrom_id, true);
140 NBEdge* const mustStopTo = ec.retrievePossiblySplit(mustStopTo_id, false);
141
142 if (mayDriveFrom != nullptr && mayDriveTo != nullptr && mustStopFrom != nullptr && mustStopTo != nullptr) {
143 NBNode* node = mayDriveFrom->getToNode();
144 node->addSortedLinkFoes(
145 NBConnection(mayDriveFrom, mayDriveTo),
146 NBConnection(mustStopFrom, mustStopTo));
147 }
148 }
149}
150
151
152/****************************************************************************/
Storage for edges, including some functionality operating on multiple edges.
Definition NBEdgeCont.h:59
NBEdge * retrievePossiblySplit(const std::string &id, bool downstream) const
Tries to retrieve an edge, even if it is splitted.
The representation of a single edge during network building.
Definition NBEdge.h:92
NBNode * getToNode() const
Returns the destination node of the edge.
Definition NBEdge.h:546
Represents a single node (junction) during network building.
Definition NBNode.h:66
void addSortedLinkFoes(const NBConnection &mayDrive, const NBConnection &mustStop)
add shorted link FOES
Definition NBNode.cpp:1886
A temporary storage for conflict areas imported from Vissim.
std::string getStatus()
Returns the priority regulation of the conflic area.
static bool dictionary(int id, const std::string &link1, const std::string &link2, const std::string &status)
Adds the described item to the dictionary Builds the conflict area first.
static void setPriorityRegulation(NBEdgeCont &ec)
Sets the priority regulation according to the VISSIM conflict area data.
static DictType myDict
The dictionary.
std::string getSecondLink()
Returns the second link of the conflic area.
static NIVissimConflictArea * dict_findByLinks(const std::string &link1, const std::string &link2)
static void clearDict()
Clears the dictionary.
std::string getFirstLink()
Returns the first link of the conflic area.
NIVissimConflictArea(int id, const std::string &link1, const std::string &link2, const std::string &status)
Constructor.
std::map< int, NIVissimConflictArea * > DictType
Definition of the dictionary type.
static bool dictionary(int id, NIVissimConnection *o)
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...