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"
1312#include " Layout911.h"
1413#include " ParameterManager.h"
@@ -31,13 +30,11 @@ void Connections911::setup()
3130 size_t srcV = gm.source (*it);
3231 size_t destV = gm.target (*it);
3332 edgeType type = layout.edgType (srcV, destV);
34- BGFLOAT *sumPoint = &vertices.summationMap_ [destV];
3533
3634 BGFLOAT dist = layout.dist_ (srcV, destV);
3735 LOG4CPLUS_DEBUG (edgeLogger_, " Source: " << srcV << " Dest: " << destV << " Dist: " << dist);
3836
39- BGSIZE iEdg;
40- edges_->addEdge (iEdg, type, srcV, destV, sumPoint, Simulator::getInstance ().getDeltaT ());
37+ BGSIZE iEdg = edges_->addEdge (type, srcV, destV, Simulator::getInstance ().getDeltaT ());
4138 added++;
4239 }
4340
@@ -46,7 +43,6 @@ void Connections911::setup()
4643
4744void Connections911::loadParameters ()
4845{
49- ParameterManager::getInstance ().getIntByXpath (" //connsPerVertex/text()" , connsPerVertex_);
5046 ParameterManager::getInstance ().getIntByXpath (" //psapsToErase/text()" , psapsToErase_);
5147 ParameterManager::getInstance ().getIntByXpath (" //respsToErase/text()" , respsToErase_);
5248}
@@ -55,20 +51,18 @@ void Connections911::loadParameters()
5551// / Registered to OperationManager as Operation::printParameters
5652void Connections911::printParameters () const
5753{
58- LOG4CPLUS_DEBUG (fileLogger_, " CONNECTIONS PARAMETERS"
59- << endl
60- << " \t Connections Type: Connections911" << endl
61- << " \t Connections per vertex: " << connsPerVertex_ << endl
62- << " \t PSAPs to erase: " << psapsToErase_ << endl
63- << " \t RESPs to erase: " << respsToErase_ << endl
64- << endl);
54+ LOG4CPLUS_DEBUG (fileLogger_,
55+ " CONNECTIONS PARAMETERS"
56+ << endl
57+ << " \t Connections Type: Connections911" << endl
58+ << " \t Maximum Connections per vertex: " << edges_->maxEdgesPerVertex_ << endl
59+ << " \t PSAPs to erase: " << psapsToErase_ << endl
60+ << " \t RESPs to erase: " << respsToErase_ << endl
61+ << endl);
6562}
6663
6764#if !defined(USE_GPU)
6865// / Update the connections status in every epoch.
69- // /
70- // / @param vertices The Vertex list to search from.
71- // / @return true if successful, false otherwise.
7266bool Connections911::updateConnections (AllVertices &vertices)
7367{
7468 // Only run on the first epoch
@@ -94,11 +88,54 @@ bool Connections911::updateConnections(AllVertices &vertices)
9488 return true ;
9589}
9690
91+
92+ // / Finds the outgoing edge from the given vertex to the Responder closest to
93+ // / the emergency call location
94+ BGSIZE Connections911::getEdgeToClosestResponder (const Call &call, BGSIZE vertexIdx)
95+ {
96+ All911Edges &edges911 = dynamic_cast <All911Edges &>(*edges_);
97+
98+ vertexType requiredType;
99+ if (call.type == " Law" )
100+ requiredType = LAW;
101+ else if (call.type == " EMS" )
102+ requiredType = EMS;
103+ else if (call.type == " Fire" )
104+ requiredType = FIRE;
105+
106+ // loop over the outgoing edges looking for the responder with the shortest
107+ // Euclidean distance to the call's location.
108+ BGSIZE startOutEdg = synapseIndexMap_->outgoingEdgeBegin_ [vertexIdx];
109+ BGSIZE outEdgCount = synapseIndexMap_->outgoingEdgeCount_ [vertexIdx];
110+ Layout911 &layout911
111+ = dynamic_cast <Layout911 &>(Simulator::getInstance ().getModel ().getLayout ());
112+
113+ BGSIZE resp, respEdge;
114+ double minDistance = numeric_limits<double >::max ();
115+ for (BGSIZE eIdxMap = startOutEdg; eIdxMap < startOutEdg + outEdgCount; ++eIdxMap) {
116+ BGSIZE outEdg = synapseIndexMap_->outgoingEdgeIndexMap_ [eIdxMap];
117+ assert (edges911.inUse_ [outEdg]); // Edge must be in use
118+
119+ BGSIZE dstVertex = edges911.destVertexIndex_ [outEdg];
120+ if (layout911.vertexTypeMap_ [dstVertex] == requiredType) {
121+ double distance = layout911.getDistance (dstVertex, call.x , call.y );
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 (layout911.vertexTypeMap_ [resp] == requiredType);
134+ return respEdge;
135+ }
136+
137+
97138// / Randomly delete 1 PSAP and rewire all the edges around it.
98- // /
99- // / @param vertices The Vertex list to search from.
100- // / @param layout Layout information of the vertex network.
101- // / @return true if successful, false otherwise.
102139bool Connections911::erasePSAP (AllVertices &vertices, Layout &layout)
103140{
104141 int numVertices = Simulator::getInstance ().getTotalVertices ();
@@ -157,7 +194,8 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
157194 }
158195
159196 // Identify all psap-less responders
160- if (layout.vertexTypeMap_ [destVertex] == RESP) {
197+ if (layout.vertexTypeMap_ [destVertex] == LAW || layout.vertexTypeMap_ [destVertex] == FIRE
198+ || layout.vertexTypeMap_ [destVertex] == EMS) {
161199 respsToReroute.push_back (destVertex);
162200 }
163201 }
@@ -191,10 +229,8 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
191229 }
192230
193231 // Insert Caller to PSAP edge
194- BGFLOAT *sumPoint = &vertices.summationMap_ [closestPSAP];
195- BGSIZE iEdg;
196- edges_->addEdge (iEdg, CP, srcVertex, closestPSAP, sumPoint,
197- Simulator::getInstance ().getDeltaT ());
232+ BGSIZE iEdg
233+ = edges_->addEdge (CP, srcVertex, closestPSAP, Simulator::getInstance ().getDeltaT ());
198234
199235 // Record added edge
200236 ChangedEdge addedEdge;
@@ -221,10 +257,8 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
221257 }
222258
223259 // Insert PSAP to Responder edge
224- BGFLOAT *sumPoint = &vertices.summationMap_ [destVertex];
225- BGSIZE iEdg;
226- edges_->addEdge (iEdg, PR, closestPSAP, destVertex, sumPoint,
227- Simulator::getInstance ().getDeltaT ());
260+ BGSIZE iEdg
261+ = edges_->addEdge (PR, closestPSAP, destVertex, Simulator::getInstance ().getDeltaT ());
228262
229263 // Record added edge
230264 ChangedEdge addedEdge;
@@ -238,10 +272,6 @@ bool Connections911::erasePSAP(AllVertices &vertices, Layout &layout)
238272}
239273
240274// / Randomly delete 1 RESP.
241- // /
242- // / @param vertices The Vertex list to search from.
243- // / @param layout Layout information of the vertex network.
244- // / @return true if successful, false otherwise.
245275bool Connections911::eraseRESP (AllVertices &vertices, Layout &layout)
246276{
247277 int numVertices = Simulator::getInstance ().getTotalVertices ();
@@ -251,7 +281,8 @@ bool Connections911::eraseRESP(AllVertices &vertices, Layout &layout)
251281
252282 // Find all resps
253283 for (int i = 0 ; i < numVertices; i++) {
254- if (layout.vertexTypeMap_ [i] == RESP) {
284+ if (layout.vertexTypeMap_ [i] == LAW || layout.vertexTypeMap_ [i] == FIRE
285+ || layout.vertexTypeMap_ [i] == EMS) {
255286 resps.push_back (i);
256287 }
257288 }
@@ -300,7 +331,8 @@ bool Connections911::eraseRESP(AllVertices &vertices, Layout &layout)
300331 return changesMade;
301332}
302333
303- // / @return xml representation of a single edge
334+
335+ // / Returns an xml representation of a single edge
304336string Connections911::ChangedEdge::toString ()
305337{
306338 stringstream os;
@@ -322,6 +354,9 @@ string Connections911::ChangedEdge::toString()
322354 case RP:
323355 type_s = " RP" ;
324356 break ;
357+ case RC:
358+ type_s = " RC" ;
359+ break ;
325360 default :
326361 type_s = " ETYPE_UNDEF" ;
327362 }
@@ -334,8 +369,6 @@ string Connections911::ChangedEdge::toString()
334369}
335370
336371// / Returns the complete list of all deleted or added edges as a string.
337- // / @param added true returns the list of added edges, false = erased
338- // / @return xml representation of all deleted or added edges
339372string Connections911::changedEdgesToXML (bool added)
340373{
341374 stringstream os;
@@ -360,7 +393,6 @@ string Connections911::changedEdgesToXML(bool added)
360393}
361394
362395// / Returns the complete list of deleted vertices as a string.
363- // / @return xml representation of all deleted vertices
364396string Connections911::erasedVerticesToXML ()
365397{
366398 stringstream os;
0 commit comments