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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A temporary storage for conflict areas imported from Vissim
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <iterator>
31 #include <map>
32 #include <string>
33 #include <utils/common/ToString.h>
35 #include "NIVissimConflictArea.h"
36 #include "NIVissimConnection.h"
37 #include <netbuild/NBEdgeCont.h>
38 #include <netbuild/NBEdge.h>
39 #include <netbuild/NBNode.h>
40 
41 
42 // ===========================================================================
43 // static members
44 // ===========================================================================
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
52  const std::string& link1,
53  const std::string& link2,
54  const std::string& status)
55  : myConflictID(id), myFirstLink(link1), mySecondLink(link2), myStatus(status) {
56 }
57 
58 
60 
61 
62 
63 
64 bool
65 NIVissimConflictArea::dictionary(int id, const std::string& link1,
66  const std::string& link2,
67  const std::string& status) {
68  NIVissimConflictArea* ca = new NIVissimConflictArea(id, link1, link2, status);
69  if (!dictionary(id, ca)) {
70  delete ca;
71  return false;
72  }
73  return true;
74 }
75 
76 
77 
78 bool
80  DictType::iterator i = myDict.find(id);
81  if (i == myDict.end()) {
82  myDict[id] = ca;
83  return true;
84  }
85  return false;
86 }
87 
88 
89 
92  DictType::iterator i = myDict.find(id);
93  if (i == myDict.end()) {
94  return 0;
95  }
96  return (*i).second;
97 }
98 
99 
100 
102 NIVissimConflictArea::dict_findByLinks(const std::string& link1,
103  const std::string& link2) {
104  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
105  if (((*i).second->myFirstLink == link1) &&
106  ((*i).second->mySecondLink == link2)) {
107  return (*i).second;
108  }
109  }
110  return 0;
111 }
112 
113 
114 void
116  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
117  delete(*i).second;
118  }
119  myDict.clear();
120 }
121 
122 
123 void
125  std::map<int, NIVissimConflictArea*>::iterator it;
126  for (it = myDict.begin(); it != myDict.end(); it++) {
127  NIVissimConflictArea* const conflictArea = it->second;
130  if (firstLink == 0 || secondLink == 0) {
131  continue;
132  }
133  // status == "TWOYIELDSONE"
134  NIVissimConnection* priority_conn = firstLink;
135  NIVissimConnection* subordinate_conn = secondLink;
136  if (conflictArea->getStatus() == "ONEYIELDSTWO") {
137  priority_conn = secondLink;
138  subordinate_conn = firstLink;
139  }
140  const std::string mayDriveFrom_id = toString<int>(priority_conn->getFromEdgeID());
141  const std::string mayDriveTo_id = toString<int>(priority_conn->getToEdgeID());
142  const std::string mustStopFrom_id = toString<int>(subordinate_conn->getFromEdgeID());
143  const std::string mustStopTo_id = toString<int>(subordinate_conn->getToEdgeID());
144 
145  NBEdge* const mayDriveFrom = ec.retrievePossiblySplit(mayDriveFrom_id, true);
146  NBEdge* const mayDriveTo = ec.retrievePossiblySplit(mayDriveTo_id, false);
147  NBEdge* const mustStopFrom = ec.retrievePossiblySplit(mustStopFrom_id, true);
148  NBEdge* const mustStopTo = ec.retrievePossiblySplit(mustStopTo_id, false);
149 
150  if (mayDriveFrom != 0 && mayDriveTo != 0 && mustStopFrom != 0 && mustStopTo != 0) {
151  NBNode* node = mayDriveFrom->getToNode();
152  node->addSortedLinkFoes(
153  NBConnection(mayDriveFrom, mayDriveTo),
154  NBConnection(mustStopFrom, mustStopTo));
155  }
156  }
157 }
158 
159 
160 /****************************************************************************/
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:70
~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:286
static void clearDict()
Clears the dictionary.
static int _str2int(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
Definition: TplConvert.h:167
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
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:74
void addSortedLinkFoes(const NBConnection &mayDrive, const NBConnection &mustStop)
add shorted link FOES
Definition: NBNode.cpp:1238
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.