Eclipse 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-2019 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 /****************************************************************************/
14 // A temporary storage for conflict areas imported from Vissim
15 /****************************************************************************/
16 
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <iterator>
24 #include <map>
25 #include <string>
26 #include <utils/common/ToString.h>
28 #include "NIVissimConflictArea.h"
29 #include "NIVissimConnection.h"
30 #include <netbuild/NBEdgeCont.h>
31 #include <netbuild/NBEdge.h>
32 #include <netbuild/NBNode.h>
33 
34 
35 // ===========================================================================
36 // static members
37 // ===========================================================================
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
45  const std::string& link1,
46  const std::string& link2,
47  const std::string& status)
48  : myConflictID(id), myFirstLink(link1), mySecondLink(link2), myStatus(status) {
49 }
50 
51 
53 
54 
55 
56 
57 bool
58 NIVissimConflictArea::dictionary(int id, const std::string& link1,
59  const std::string& link2,
60  const std::string& status) {
61  NIVissimConflictArea* ca = new NIVissimConflictArea(id, link1, link2, status);
62  if (!dictionary(id, ca)) {
63  delete ca;
64  return false;
65  }
66  return true;
67 }
68 
69 
70 
71 bool
73  DictType::iterator i = myDict.find(id);
74  if (i == myDict.end()) {
75  myDict[id] = ca;
76  return true;
77  }
78  return false;
79 }
80 
81 
82 
85  DictType::iterator i = myDict.find(id);
86  if (i == myDict.end()) {
87  return nullptr;
88  }
89  return (*i).second;
90 }
91 
92 
93 
95 NIVissimConflictArea::dict_findByLinks(const std::string& link1,
96  const std::string& link2) {
97  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
98  if (((*i).second->myFirstLink == link1) &&
99  ((*i).second->mySecondLink == link2)) {
100  return (*i).second;
101  }
102  }
103  return nullptr;
104 }
105 
106 
107 void
109  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
110  delete (*i).second;
111  }
112  myDict.clear();
113 }
114 
115 
116 void
118  std::map<int, NIVissimConflictArea*>::iterator it;
119  for (it = myDict.begin(); it != myDict.end(); it++) {
120  NIVissimConflictArea* const conflictArea = it->second;
123  if (firstLink == nullptr || secondLink == nullptr) {
124  continue;
125  }
126  // status == "TWOYIELDSONE"
127  NIVissimConnection* priority_conn = firstLink;
128  NIVissimConnection* subordinate_conn = secondLink;
129  if (conflictArea->getStatus() == "ONEYIELDSTWO") {
130  priority_conn = secondLink;
131  subordinate_conn = firstLink;
132  }
133  const std::string mayDriveFrom_id = toString<int>(priority_conn->getFromEdgeID());
134  const std::string mayDriveTo_id = toString<int>(priority_conn->getToEdgeID());
135  const std::string mustStopFrom_id = toString<int>(subordinate_conn->getFromEdgeID());
136  const std::string mustStopTo_id = toString<int>(subordinate_conn->getToEdgeID());
137 
138  NBEdge* const mayDriveFrom = ec.retrievePossiblySplit(mayDriveFrom_id, true);
139  NBEdge* const mayDriveTo = ec.retrievePossiblySplit(mayDriveTo_id, false);
140  NBEdge* const mustStopFrom = ec.retrievePossiblySplit(mustStopFrom_id, true);
141  NBEdge* const mustStopTo = ec.retrievePossiblySplit(mustStopTo_id, false);
142 
143  if (mayDriveFrom != nullptr && mayDriveTo != nullptr && mustStopFrom != nullptr && mustStopTo != nullptr) {
144  NBNode* node = mayDriveFrom->getToNode();
145  node->addSortedLinkFoes(
146  NBConnection(mayDriveFrom, mayDriveTo),
147  NBConnection(mustStopFrom, mustStopTo));
148  }
149  }
150 }
151 
152 
153 /****************************************************************************/
ToString.h
NIVissimConflictArea::dict_findByLinks
static NIVissimConflictArea * dict_findByLinks(const std::string &link1, const std::string &link2)
Definition: NIVissimConflictArea.cpp:95
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:60
NIVissimConflictArea::myDict
static DictType myDict
The dictionary.
Definition: NIVissimConflictArea.h:127
NBEdgeCont.h
NIVissimConflictArea::getFirstLink
std::string getFirstLink()
Returns the first link of the conflic area.
Definition: NIVissimConflictArea.h:90
NIVissimConflictArea.h
NIVissimConflictArea::getSecondLink
std::string getSecondLink()
Returns the second link of the conflic area.
Definition: NIVissimConflictArea.h:95
NBNode::addSortedLinkFoes
void addSortedLinkFoes(const NBConnection &mayDrive, const NBConnection &mustStop)
add shorted link FOES
Definition: NBNode.cpp:1561
NIVissimConflictArea::DictType
std::map< int, NIVissimConflictArea * > DictType
Definition of the dictionary type.
Definition: NIVissimConflictArea.h:124
NIVissimConnection::getToEdgeID
int getToEdgeID() const
Definition: NIVissimConnection.cpp:162
NIVissimConflictArea::NIVissimConflictArea
NIVissimConflictArea(int id, const std::string &link1, const std::string &link2, const std::string &status)
Constructor.
Definition: NIVissimConflictArea.cpp:44
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
NBEdge::getToNode
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:498
NIVissimConnection
Definition: NIVissimConnection.h:45
NBEdgeCont::retrievePossiblySplit
NBEdge * retrievePossiblySplit(const std::string &id, bool downstream) const
Tries to retrieve an edge, even if it is splitted.
Definition: NBEdgeCont.cpp:282
NIVissimConflictArea::getStatus
std::string getStatus()
Returns the priority regulation of the conflic area.
Definition: NIVissimConflictArea.h:100
NIVissimConflictArea
A temporary storage for conflict areas imported from Vissim.
Definition: NIVissimConflictArea.h:48
NBConnection
Definition: NBConnection.h:43
NIVissimConflictArea::dictionary
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.
Definition: NIVissimConflictArea.cpp:58
StringUtils.h
StringUtils::toInt
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
Definition: StringUtils.cpp:278
NIVissimConnection.h
config.h
NIVissimConnection::dictionary
static bool dictionary(int id, NIVissimConnection *o)
Definition: NIVissimConnection.cpp:77
NIVissimConflictArea::setPriorityRegulation
static void setPriorityRegulation(NBEdgeCont &ec)
Sets the priority regulation according to the VISSIM conflict area data.
Definition: NIVissimConflictArea.cpp:117
NIVissimConnection::getFromEdgeID
int getFromEdgeID() const
Definition: NIVissimConnection.cpp:156
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:67
NBNode.h
NIVissimConflictArea::~NIVissimConflictArea
~NIVissimConflictArea()
Destructor.
Definition: NIVissimConflictArea.cpp:52
NIVissimConflictArea::clearDict
static void clearDict()
Clears the dictionary.
Definition: NIVissimConflictArea.cpp:108
NBEdge.h