SUMO - Simulation of Urban MObility
NIVissimConflictArea.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // A temporary storage for conflict areas imported from Vissim
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <iterator>
25 #include <map>
26 #include <string>
27 #include <utils/common/ToString.h>
29 #include "NIVissimConflictArea.h"
30 #include "NIVissimConnection.h"
31 #include <netbuild/NBEdgeCont.h>
32 #include <netbuild/NBEdge.h>
33 #include <netbuild/NBNode.h>
34 
35 
36 // ===========================================================================
37 // static members
38 // ===========================================================================
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
46  const std::string& link1,
47  const std::string& link2,
48  const std::string& status)
49  : myConflictID(id), myFirstLink(link1), mySecondLink(link2), myStatus(status) {
50 }
51 
52 
54 
55 
56 
57 
58 bool
59 NIVissimConflictArea::dictionary(int id, const std::string& link1,
60  const std::string& link2,
61  const std::string& status) {
62  NIVissimConflictArea* ca = new NIVissimConflictArea(id, link1, link2, status);
63  if (!dictionary(id, ca)) {
64  delete ca;
65  return false;
66  }
67  return true;
68 }
69 
70 
71 
72 bool
74  DictType::iterator i = myDict.find(id);
75  if (i == myDict.end()) {
76  myDict[id] = ca;
77  return true;
78  }
79  return false;
80 }
81 
82 
83 
86  DictType::iterator i = myDict.find(id);
87  if (i == myDict.end()) {
88  return nullptr;
89  }
90  return (*i).second;
91 }
92 
93 
94 
96 NIVissimConflictArea::dict_findByLinks(const std::string& link1,
97  const std::string& link2) {
98  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
99  if (((*i).second->myFirstLink == link1) &&
100  ((*i).second->mySecondLink == link2)) {
101  return (*i).second;
102  }
103  }
104  return nullptr;
105 }
106 
107 
108 void
110  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
111  delete(*i).second;
112  }
113  myDict.clear();
114 }
115 
116 
117 void
119  std::map<int, NIVissimConflictArea*>::iterator it;
120  for (it = myDict.begin(); it != myDict.end(); it++) {
121  NIVissimConflictArea* const conflictArea = it->second;
124  if (firstLink == nullptr || secondLink == nullptr) {
125  continue;
126  }
127  // status == "TWOYIELDSONE"
128  NIVissimConnection* priority_conn = firstLink;
129  NIVissimConnection* subordinate_conn = secondLink;
130  if (conflictArea->getStatus() == "ONEYIELDSTWO") {
131  priority_conn = secondLink;
132  subordinate_conn = firstLink;
133  }
134  const std::string mayDriveFrom_id = toString<int>(priority_conn->getFromEdgeID());
135  const std::string mayDriveTo_id = toString<int>(priority_conn->getToEdgeID());
136  const std::string mustStopFrom_id = toString<int>(subordinate_conn->getFromEdgeID());
137  const std::string mustStopTo_id = toString<int>(subordinate_conn->getToEdgeID());
138 
139  NBEdge* const mayDriveFrom = ec.retrievePossiblySplit(mayDriveFrom_id, true);
140  NBEdge* const mayDriveTo = ec.retrievePossiblySplit(mayDriveTo_id, false);
141  NBEdge* const mustStopFrom = ec.retrievePossiblySplit(mustStopFrom_id, true);
142  NBEdge* const mustStopTo = ec.retrievePossiblySplit(mustStopTo_id, false);
143 
144  if (mayDriveFrom != nullptr && mayDriveTo != nullptr && mustStopFrom != nullptr && mustStopTo != nullptr) {
145  NBNode* node = mayDriveFrom->getToNode();
146  node->addSortedLinkFoes(
147  NBConnection(mayDriveFrom, mayDriveTo),
148  NBConnection(mustStopFrom, mustStopTo));
149  }
150  }
151 }
152 
153 
154 /****************************************************************************/
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.
The representation of a single edge during network building.
Definition: NBEdge.h:65
~NIVissimConflictArea()
Destructor.
static bool dictionary(int id, NIVissimConnection *o)
static void setPriorityRegulation(NBEdgeCont &ec)
Sets the priority regulation according to the VISSIM conflict area data.
static NIVissimConflictArea * dict_findByLinks(const std::string &link1, const std::string &link2)
NBEdge * retrievePossiblySplit(const std::string &id, bool downstream) const
Tries to retrieve an edge, even if it is splitted.
Definition: NBEdgeCont.cpp:281
static void clearDict()
Clears the dictionary.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
std::string getSecondLink()
Returns the second link of the conflic area.
NIVissimConflictArea(int id, const std::string &link1, const std::string &link2, const std::string &status)
Constructor.
static DictType myDict
The dictionary.
Represents a single node (junction) during network building.
Definition: NBNode.h:68
void addSortedLinkFoes(const NBConnection &mayDrive, const NBConnection &mustStop)
add shorted link FOES
Definition: NBNode.cpp:1417
A temporary storage for conflict areas imported from Vissim.
std::string getFirstLink()
Returns the first link of the conflic area.
std::map< int, NIVissimConflictArea * > DictType
Definition of the dictionary type.