Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netimport/vissim/tempstructs/NIVissimConflictArea.cpp
169684 views
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 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
NIVissimConflictArea::NIVissimConflictArea(int id,
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
51
NIVissimConflictArea::~NIVissimConflictArea() {}
52
53
54
55
56
bool
57
NIVissimConflictArea::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
70
bool
71
NIVissimConflictArea::dictionary(int id, NIVissimConflictArea* ca) {
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
82
NIVissimConflictArea*
83
NIVissimConflictArea::dictionary(int id) {
84
DictType::iterator i = myDict.find(id);
85
if (i == myDict.end()) {
86
return nullptr;
87
}
88
return (*i).second;
89
}
90
91
92
93
NIVissimConflictArea*
94
NIVissimConflictArea::dict_findByLinks(const std::string& link1,
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
106
void
107
NIVissimConflictArea::clearDict() {
108
for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
109
delete (*i).second;
110
}
111
myDict.clear();
112
}
113
114
115
void
116
NIVissimConflictArea::setPriorityRegulation(NBEdgeCont& ec) {
117
std::map<int, NIVissimConflictArea*>::iterator it;
118
for (it = myDict.begin(); it != myDict.end(); it++) {
119
NIVissimConflictArea* const conflictArea = it->second;
120
NIVissimConnection* const firstLink = NIVissimConnection::dictionary(StringUtils::toInt(conflictArea->getFirstLink()));
121
NIVissimConnection* const secondLink = NIVissimConnection::dictionary(StringUtils::toInt(conflictArea->getSecondLink()));
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
/****************************************************************************/
153
154