33*
44* @ingroup Simulator/Connections/NG911
55*
6- * @brief The model of the static network
7- *
6+ * @brief This class manages the Connections of the NG911 network
87*/
98
109#include " Connections911.h"
11- #include " All911Vertices .h"
10+ #include " All911Edges .h"
1211#include " GraphManager.h"
13- #include " Layout911.h"
1412#include " ParameterManager.h"
1513
1614void Connections911::setup ()
@@ -64,9 +62,6 @@ void Connections911::printParameters() const
6462
6563#if !defined(USE_GPU)
6664// / Update the connections status in every epoch.
67- // /
68- // / @param vertices The Vertex list to search from.
69- // / @return true if successful, false otherwise.
7065bool Connections911::updateConnections (AllVertices &vertices)
7166{
7267 // Only run on the first epoch
@@ -92,11 +87,55 @@ bool Connections911::updateConnections(AllVertices &vertices)
9287 return true ;
9388}
9489
90+
91+ // / Finds the outgoing edge from the given vertex to the Responder closest to
92+ // / the emergency call location
93+ BGSIZE Connections911::getEdgeToClosestResponder (const Call &call, BGSIZE vertexIdx)
94+ {
95+ All911Edges &edges911 = dynamic_cast <All911Edges &>(*edges_);
96+
97+ vertexType requiredType;
98+ if (call.type == " Law" )
99+ requiredType = LAW;
100+ else if (call.type == " EMS" )
101+ requiredType = EMS;
102+ else if (call.type == " Fire" )
103+ requiredType = FIRE;
104+
105+ // loop over the outgoing edges looking for the responder with the shortest
106+ // Euclidean distance to the call's location.
107+ BGSIZE startOutEdg = synapseIndexMap_->outgoingEdgeBegin_ [vertexIdx];
108+ BGSIZE outEdgCount = synapseIndexMap_->outgoingEdgeCount_ [vertexIdx];
109+ Layout &layout = Simulator::getInstance ().getModel ().getLayout ();
110+
111+ BGSIZE resp, respEdge;
112+ double minDistance = numeric_limits<double >::max ();
113+ for (BGSIZE eIdxMap = startOutEdg; eIdxMap < startOutEdg + outEdgCount; ++eIdxMap) {
114+ BGSIZE outEdg = synapseIndexMap_->outgoingEdgeIndexMap_ [eIdxMap];
115+ assert (edges911.inUse_ [outEdg]); // Edge must be in use
116+
117+ BGSIZE dstVertex = edges911.destVertexIndex_ [outEdg];
118+ if (layout.vertexTypeMap_ [dstVertex] == requiredType) {
119+ double xDelta = call.x - layout.xloc_ [dstVertex];
120+ double yDelta = call.y - layout.yloc_ [dstVertex];
121+ double distance = sqrt (pow (xDelta, 2 ) + pow (yDelta, 2 ));
122+
123+ if (distance < minDistance) {
124+ minDistance = distance;
125+ resp = dstVertex;
126+ respEdge = outEdg;
127+ }
128+ }
129+ }
130+
131+ // We must have found the closest responder of the right type
132+ assert (minDistance < numeric_limits<double >::max ());
133+ assert (layout.vertexTypeMap_ [resp] == requiredType);
134+ return respEdge;
135+ }
136+
137+
95138// / Randomly delete 1 PSAP and rewire all the edges around it.
96- // /
97- // / @param vertices The Vertex list to search from.
98- // / @param layout Layout information of the vertex network.
99- // / @return true if successful, false otherwise.
100139bool Connections911::erasePSAP (AllVertices &vertices, Layout &layout)
101140{
102141 int numVertices = Simulator::getInstance ().getTotalVertices ();
@@ -155,7 +194,8 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
155194 }
156195
157196 // Identify all psap-less responders
158- if (layout.vertexTypeMap_ [destVertex] == RESP) {
197+ if (layout.vertexTypeMap_ [destVertex] == LAW || layout.vertexTypeMap_ [destVertex] == FIRE
198+ || layout.vertexTypeMap_ [destVertex] == EMS) {
159199 respsToReroute.push_back (destVertex);
160200 }
161201 }
@@ -232,10 +272,6 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
232272}
233273
234274// / Randomly delete 1 RESP.
235- // /
236- // / @param vertices The Vertex list to search from.
237- // / @param layout Layout information of the vertex network.
238- // / @return true if successful, false otherwise.
239275bool Connections911::eraseRESP (AllVertices &vertices, Layout &layout)
240276{
241277 int numVertices = Simulator::getInstance ().getTotalVertices ();
@@ -245,7 +281,8 @@ bool Connections911::eraseRESP(AllVertices &vertices, Layout &layout)
245281
246282 // Find all resps
247283 for (int i = 0 ; i < numVertices; i++) {
248- if (layout.vertexTypeMap_ [i] == RESP) {
284+ if (layout.vertexTypeMap_ [i] == LAW || layout.vertexTypeMap_ [i] == FIRE
285+ || layout.vertexTypeMap_ [i] == EMS) {
249286 resps.push_back (i);
250287 }
251288 }
@@ -294,7 +331,8 @@ bool Connections911::eraseRESP(AllVertices &vertices, Layout &layout)
294331 return changesMade;
295332}
296333
297- // / @return xml representation of a single edge
334+
335+ // / Returns an xml representation of a single edge
298336string Connections911::ChangedEdge::toString ()
299337{
300338 stringstream os;
@@ -331,8 +369,6 @@ string Connections911::ChangedEdge::toString()
331369}
332370
333371// / Returns the complete list of all deleted or added edges as a string.
334- // / @param added true returns the list of added edges, false = erased
335- // / @return xml representation of all deleted or added edges
336372string Connections911::changedEdgesToXML (bool added)
337373{
338374 stringstream os;
@@ -357,7 +393,6 @@ string Connections911::changedEdgesToXML(bool added)
357393}
358394
359395// / Returns the complete list of deleted vertices as a string.
360- // / @return xml representation of all deleted vertices
361396string Connections911::erasedVerticesToXML ()
362397{
363398 stringstream os;
0 commit comments