SUMO - Simulation of Urban MObility
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-2017 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 
43 // ===========================================================================
44 // static members
45 // ===========================================================================
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
53  const std::string& link1,
54  const std::string& link2,
55  const std::string& status)
56  : myConflictID(id), myFirstLink(link1), mySecondLink(link2), myStatus(status) {
57 }
58 
59 
61 
62 
63 
64 
65 bool
66 NIVissimConflictArea::dictionary(int id, const std::string& link1,
67  const std::string& link2,
68  const std::string& status) {
69  NIVissimConflictArea* ca = new NIVissimConflictArea(id, link1, link2, status);
70  if (!dictionary(id, ca)) {
71  delete ca;
72  return false;
73  }
74  return true;
75 }
76 
77 
78 
79 bool
81  DictType::iterator i = myDict.find(id);
82  if (i == myDict.end()) {
83  myDict[id] = ca;
84  return true;
85  }
86  return false;
87 }
88 
89 
90 
93  DictType::iterator i = myDict.find(id);
94  if (i == myDict.end()) {
95  return 0;
96  }
97  return (*i).second;
98 }
99 
100 
101 
103 NIVissimConflictArea::dict_findByLinks(const std::string& link1,
104  const std::string& link2) {
105  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
106  if (((*i).second->myFirstLink == link1) &&
107  ((*i).second->mySecondLink == link2)) {
108  return (*i).second;
109  }
110  }
111  return 0;
112 }
113 
114 
115 void
117  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
118  delete(*i).second;
119  }
120  myDict.clear();
121 }
122 
123 
124 void
126  std::map<int, NIVissimConflictArea*>::iterator it;
127  for (it = myDict.begin(); it != myDict.end(); it++) {
128  NIVissimConflictArea* const conflictArea = it->second;
131  if (firstLink == 0 || secondLink == 0) {
132  continue;
133  }
134  // status == "TWOYIELDSONE"
135  NIVissimConnection* priority_conn = firstLink;
136  NIVissimConnection* subordinate_conn = secondLink;
137  if (conflictArea->getStatus() == "ONEYIELDSTWO") {
138  priority_conn = secondLink;
139  subordinate_conn = firstLink;
140  }
141  const std::string mayDriveFrom_id = toString<int>(priority_conn->getFromEdgeID());
142  const std::string mayDriveTo_id = toString<int>(priority_conn->getToEdgeID());
143  const std::string mustStopFrom_id = toString<int>(subordinate_conn->getFromEdgeID());
144  const std::string mustStopTo_id = toString<int>(subordinate_conn->getToEdgeID());
145 
146  NBEdge* const mayDriveFrom = ec.retrievePossiblySplit(mayDriveFrom_id, true);
147  NBEdge* const mayDriveTo = ec.retrievePossiblySplit(mayDriveTo_id, false);
148  NBEdge* const mustStopFrom = ec.retrievePossiblySplit(mustStopFrom_id, true);
149  NBEdge* const mustStopTo = ec.retrievePossiblySplit(mustStopTo_id, false);
150 
151  if (mayDriveFrom != 0 && mayDriveTo != 0 && mustStopFrom != 0 && mustStopTo != 0) {
152  NBNode* node = mayDriveFrom->getToNode();
153  node->addSortedLinkFoes(
154  NBConnection(mayDriveFrom, mayDriveTo),
155  NBConnection(mustStopFrom, mustStopTo));
156  }
157  }
158 }
159 
160 
161 /****************************************************************************/
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: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)
NBEdge * retrievePossiblySplit(const std::string &id, bool downstream) const
Tries to retrieve an edge, even if it is splitted.
Definition: NBEdgeCont.cpp:287
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:75
void addSortedLinkFoes(const NBConnection &mayDrive, const NBConnection &mustStop)
add shorted link FOES
Definition: NBNode.cpp:1248
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.