SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
NIVissimConflictArea.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A temporary storage for conflict areas imported from Vissim
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <iterator>
32 #include <map>
33 #include <string>
34 #include <utils/common/ToString.h>
36 #include "NIVissimConflictArea.h"
37 #include "NIVissimConnection.h"
38 #include <netbuild/NBEdgeCont.h>
39 #include <netbuild/NBEdge.h>
40 #include <netbuild/NBNode.h>
41 
42 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // static members
49 // ===========================================================================
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
57  const std::string& link1,
58  const std::string& link2,
59  const std::string& status)
60  : myConflictID(id), myFirstLink(link1), mySecondLink(link2), myStatus(status) {
61 }
62 
63 
65 
66 
67 
68 
69 bool
70 NIVissimConflictArea::dictionary(int id, const std::string& link1,
71  const std::string& link2,
72  const std::string& status) {
73  NIVissimConflictArea* ca = new NIVissimConflictArea(id, link1, link2, status);
74  if (!dictionary(id, ca)) {
75  delete ca;
76  return false;
77  }
78  return true;
79 }
80 
81 
82 
83 bool
85  DictType::iterator i = myDict.find(id);
86  if (i == myDict.end()) {
87  myDict[id] = ca;
88  return true;
89  }
90  return false;
91 }
92 
93 
94 
97  DictType::iterator i = myDict.find(id);
98  if (i == myDict.end()) {
99  return 0;
100  }
101  return (*i).second;
102 }
103 
104 
105 
107 NIVissimConflictArea::dict_findByLinks(const std::string& link1,
108  const std::string& link2) {
109  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
110  if (((*i).second->myFirstLink == link1) &&
111  ((*i).second->mySecondLink == link2)) {
112  return (*i).second;
113  }
114  }
115  return 0;
116 }
117 
118 
119 void
121  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
122  delete(*i).second;
123  }
124  myDict.clear();
125 }
126 
127 
128 void
130  std::map<int, NIVissimConflictArea*>::iterator it;
131  for (it = myDict.begin(); it != myDict.end(); it++) {
132  NIVissimConflictArea* const conflictArea = it->second;
135  if (firstLink == 0 || secondLink == 0) {
136  continue;
137  }
138  // status == "TWOYIELDSONE"
139  NIVissimConnection* priority_conn = firstLink;
140  NIVissimConnection* subordinate_conn = secondLink;
141  if (conflictArea->getStatus() == "ONEYIELDSTWO") {
142  priority_conn = secondLink;
143  subordinate_conn = firstLink;
144  }
145  const std::string mayDriveFrom_id = toString<int>(priority_conn->getFromEdgeID());
146  const std::string mayDriveTo_id = toString<int>(priority_conn->getToEdgeID());
147  const std::string mustStopFrom_id = toString<int>(subordinate_conn->getFromEdgeID());
148  const std::string mustStopTo_id = toString<int>(subordinate_conn->getToEdgeID());
149 
150  NBEdge* const mayDriveFrom = ec.retrievePossiblySplit(mayDriveFrom_id, true);
151  NBEdge* const mayDriveTo = ec.retrievePossiblySplit(mayDriveTo_id, false);
152  NBEdge* const mustStopFrom = ec.retrievePossiblySplit(mustStopFrom_id, true);
153  NBEdge* const mustStopTo = ec.retrievePossiblySplit(mustStopTo_id, false);
154 
155  if (mayDriveFrom != 0 && mayDriveTo != 0 && mustStopFrom != 0 && mustStopTo != 0) {
156  NBNode* node = mayDriveFrom->getToNode();
157  node->addSortedLinkFoes(
158  NBConnection(mayDriveFrom, mayDriveTo),
159  NBConnection(mustStopFrom, mustStopTo));
160  }
161  }
162 }
163 
164 
165 /****************************************************************************/
std::string getStatus()
Returns the priority regulation of the conflic area.
NBEdge * retrievePossiblySplit(const std::string &id, bool downstream) const
Tries to retrieve an edge, even if it is splitted.
Definition: NBEdgeCont.cpp:283
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:71
~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)
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:160
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)
Definition: NBNode.cpp:1254
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.