Skip to content

Commit 870ef8b

Browse files
authored
Merge pull request #534 from UWB-Biocomputing/issue-490-responder-dispatch
[ISSUE 490] Implemented the responder dispatch logic
2 parents 54fff38 + a55c465 commit 870ef8b

File tree

11 files changed

+486
-287
lines changed

11 files changed

+486
-287
lines changed

Simulator/Connections/NG911/Connections911.cpp

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
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

1614
void 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.
7065
bool 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.
100139
bool 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.
239275
bool 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
298336
string 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
336372
string 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
361396
string Connections911::erasedVerticesToXML()
362397
{
363398
stringstream os;

Simulator/Connections/NG911/Connections911.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
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
7+
*
8+
* Connections in the NG911 models, represent communication links between the
9+
* various network nodes. These are potentially dynamic connections, where
10+
* edges between nodes are erased and added, representing loss of communication
11+
* between nodes and re-routing of disconnected nodes.
812
*/
913

1014
#pragma once
1115

1216
#include "Connections.h"
13-
#include "Global.h"
14-
#include "Simulator.h"
17+
#include "InputEvent.h"
1518
#include <vector>
1619

1720
using namespace std;
@@ -73,6 +76,14 @@ class Connections911 : public Connections {
7376
/// @return true if successful, false otherwise.
7477
virtual bool updateConnections(AllVertices &vertices) override;
7578

79+
/// Finds the outgoing edge from the given vertex to the Responder closest to
80+
/// the emergency call location
81+
///
82+
/// @param call The call that needs a Responder
83+
/// @param vertexIdx The index of the vertex serving the call (A PSAP)
84+
/// @return The index of the outgoing edge to the closest Responder
85+
BGSIZE getEdgeToClosestResponder(const Call &call, BGSIZE vertexIdx);
86+
7687
/// Returns the complete list of all deleted or added edges as a string.
7788
/// @return xml representation of all deleted or added edges
7889
string changedEdgesToXML(bool added);

Simulator/Edges/NG911/All911Edges.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @ingroup Simulator/Edges/NG911
55
*
6-
* @brief A container of all 911 edge data
6+
* @brief Specialization of the AllEdges class for the NG911 network
77
*/
88

99
#include "All911Edges.h"
@@ -44,9 +44,6 @@ void All911Edges::createEdge(const BGSIZE iEdg, int srcVertex, int destVertex, c
4444
#if !defined(USE_GPU)
4545

4646
/// Advance all the edges in the simulation.
47-
///
48-
/// @param vertices The vertex list to search from.
49-
/// @param edgeIndexMap Pointer to EdgeIndexMap structure.
5047
void All911Edges::advanceEdges(AllVertices &vertices, EdgeIndexMap &edgeIndexMap)
5148
{
5249
Simulator &simulator = Simulator::getInstance();
@@ -72,22 +69,25 @@ void All911Edges::advanceEdges(AllVertices &vertices, EdgeIndexMap &edgeIndexMap
7269
} // Edge doesn't have a call
7370

7471
int dst = destVertexIndex_[edgeIdx];
75-
7672
// The destination vertex should be the one pulling the information
7773
assert(dst == vertex);
78-
if (all911Vertices.vertexQueues_[dst].isFull()) {
74+
75+
CircularBuffer<Call> &dstQueue = all911Vertices.vertexQueues_[dst];
76+
if (dstQueue.size() == dstQueue.capacity() - all911Vertices.busyServers_[dst]) {
7977
// Call is dropped because there is no space in the waiting queue
8078
if (!isRedial_[edgeIdx]) {
8179
// Only count the dropped call if it's not a redial
8280
all911Vertices.droppedCalls_[dst]++;
8381
// Record that we received a call
8482
all911Vertices.receivedCalls_[dst]++;
85-
LOG4CPLUS_DEBUG(edgeLogger_, "Call dropped: " << all911Vertices.droppedCalls_[dst]
86-
<< ", time: " << call_[edgeIdx].time
87-
<< ", eIdx: " << edgeIdx);
83+
LOG4CPLUS_DEBUG(edgeLogger_,
84+
"Call dropped: " << all911Vertices.droppedCalls_[dst] << ", time: "
85+
<< call_[edgeIdx].time << ", vertex: " << dst
86+
<< ", queue size: " << dstQueue.size());
8887
}
8988
} else {
90-
all911Vertices.vertexQueues_[dst].put(call_[edgeIdx]);
89+
// Transfer call to destination
90+
dstQueue.put(call_[edgeIdx]);
9191
// Record that we received a call
9292
all911Vertices.receivedCalls_[dst]++;
9393
isAvailable_[edgeIdx] = true;

Simulator/Edges/NG911/All911Edges.h

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
/**
2-
* @file All911Edges.h
2+
* @file All911Edges.h
33
*
4-
* @ingroup Simulator/Edges/NG911
5-
*
6-
* @brief A container of all 911 edge data
7-
*
8-
* The container holds edge parameters of all edges.
9-
* Each kind of edge parameter is stored in a 2D array. Each item in the first
10-
* dimension of the array corresponds with each vertex, and each item in the second
11-
* dimension of the array corresponds with an edge parameter of each edge of the vertex.
12-
* Because each vertex owns different number of edges, the number of edges
13-
* for each vertex is stored in a 1D array, edge_counts.
14-
*
15-
* For CUDA implementation, we used another structure, AllEdgesDevice, where edge
16-
* parameters are stored in 1D arrays instead of 2D arrays, so that device functions
17-
* can access these data with less latency. When copying a edge parameter, P[i][j],
18-
* from host to device, it is stored in P[i * max_edges_per_vertex + j] in
19-
* AllEdgesDevice structure.
4+
* @ingroup Simulator/Edges/NG911
205
*
6+
* @brief Specialization of the AllEdges class for the NG911 network
7+
*
8+
* In the NG911 Model, an edge represent a communication link between two nodes.
9+
* When communication messages, such as calls, are send between the vertices;
10+
* they are placed in the outgoing edge of the vertex where the message
11+
* originates. These messages are then pulled, for processing, by the destination
12+
* vertex.
13+
*
14+
* Besides having a placeholder for the message being sent, each edge has
15+
* parameters to keep track of its availability. It is worth mentioning that
16+
* because the class contains all the edges; these parameters are contained in
17+
* vectors or arrays, where each item correspond to an edge parameter.
18+
*
19+
* During the `advanceEdges` step of the simulation the destination vertex pulls
20+
* the calls placed in the given edge and queues them into their internal queue.
21+
* Here we check that there is space in the queue, the queue in considered full
22+
* if all trunks are busy. That is, if the total calls in the waiting queue +
23+
* the number of busy agents equals the total number of trunks available.
2124
*/
2225

2326
#pragma once
@@ -82,7 +85,7 @@ class All911Edges : public AllEdges {
8285
public:
8386
/// Advance all the edges in the simulation.
8487
///
85-
/// @param vertices The vertex list to search from.
88+
/// @param vertices The vertex list to search from.
8689
/// @param edgeIndexMap Pointer to EdgeIndexMap structure.
8790
virtual void advanceEdges(AllVertices &vertices, EdgeIndexMap &edgeIndexMap);
8891

Simulator/Layouts/NG911/Layout911.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*
44
* @ingroup Simulator/Layouts/NG911
55
*
6-
* @brief The Layout class defines the layout of vertices in networks
6+
* @brief Specialization of the Layout class for the NG911 network
77
*/
88

9-
// #include <string>
109
#include "Layout911.h"
1110
#include "GraphManager.h"
1211
#include "ParameterManager.h"
1312

13+
// Register vertex properties with the GraphManager
1414
void Layout911::registerGraphProperties()
1515
{
1616
// The base class registers properties that are common to all vertices
@@ -27,17 +27,19 @@ void Layout911::registerGraphProperties()
2727
gm.registerProperty("type", &VertexProperty::type);
2828
gm.registerProperty("y", &VertexProperty::y);
2929
gm.registerProperty("x", &VertexProperty::x);
30-
gm.registerProperty("agents", &VertexProperty::agents);
30+
gm.registerProperty("servers", &VertexProperty::servers);
3131
gm.registerProperty("trunks", &VertexProperty::trunks);
3232
gm.registerProperty("segments", &VertexProperty::segments);
3333
}
3434

35+
// Loads Layout911 member variables.
3536
void Layout911::loadParameters()
3637
{
3738
// Get the number of verticese from the GraphManager
3839
numVertices_ = GraphManager::getInstance().numVertices();
3940
}
4041

42+
// Setup the internal structure of the class.
4143
void Layout911::setup()
4244
{
4345
// Base class allocates memory for: xLoc_, yLoc, dist2_, and dist_
@@ -69,12 +71,12 @@ void Layout911::setup()
6971
dist_ = sqrt(dist2_);
7072
}
7173

74+
// Prints out all parameters to logging file.
7275
void Layout911::printParameters() const
7376
{
7477
}
7578

76-
/// Creates a vertex type map.
77-
/// @param numVertices number of the vertices to have in the type map.
79+
// Creates a vertex type map.
7880
void Layout911::generateVertexTypeMap(int numVertices)
7981
{
8082
DEBUG(cout << "\nInitializing vertex type map" << endl;);
@@ -83,9 +85,9 @@ void Layout911::generateVertexTypeMap(int numVertices)
8385
// In the GraphML file Responders are divided in LAW, FIRE, and EMS.
8486
// Perhaps, we need to expand the vertex types?
8587
map<string, vertexType> vTypeMap = {{"CALR", vertexType::CALR},
86-
{"LAW", vertexType::RESP},
87-
{"FIRE", vertexType::RESP},
88-
{"EMS", vertexType::RESP},
88+
{"LAW", vertexType::LAW},
89+
{"FIRE", vertexType::FIRE},
90+
{"EMS", vertexType::EMS},
8991
{"PSAP", vertexType::PSAP}};
9092
// Count map for debugging
9193
map<string, int> vTypeCount;
@@ -110,24 +112,26 @@ void Layout911::generateVertexTypeMap(int numVertices)
110112
LOG4CPLUS_INFO(fileLogger_, "Finished initializing vertex type map");
111113
}
112114

113-
/// Returns the type of synapse at the given coordinates
114-
///
115-
/// @param srcVertex integer that points to a Neuron in the type map as a source.
116-
/// @param destVertex integer that points to a Neuron in the type map as a destination.
117-
/// @return type of the synapse.
115+
// Returns the type of synapse at the given coordinates
118116
edgeType Layout911::edgType(const int srcVertex, const int destVertex)
119117
{
120118
if (vertexTypeMap_[srcVertex] == CALR && vertexTypeMap_[destVertex] == PSAP)
121119
return CP;
122-
else if (vertexTypeMap_[srcVertex] == PSAP && vertexTypeMap_[destVertex] == RESP)
120+
else if (vertexTypeMap_[srcVertex] == PSAP
121+
&& (vertexTypeMap_[destVertex] == LAW || vertexTypeMap_[destVertex] == FIRE
122+
|| vertexTypeMap_[destVertex] == EMS))
123123
return PR;
124124
else if (vertexTypeMap_[srcVertex] == PSAP && vertexTypeMap_[destVertex] == CALR)
125125
return PC;
126126
else if (vertexTypeMap_[srcVertex] == PSAP && vertexTypeMap_[destVertex] == PSAP)
127127
return PP;
128-
else if (vertexTypeMap_[srcVertex] == RESP && vertexTypeMap_[destVertex] == PSAP)
128+
else if ((vertexTypeMap_[srcVertex] == LAW || vertexTypeMap_[destVertex] == FIRE
129+
|| vertexTypeMap_[destVertex] == EMS)
130+
&& vertexTypeMap_[destVertex] == PSAP)
129131
return RP;
130-
else if (vertexTypeMap_[srcVertex] == RESP && vertexTypeMap_[destVertex] == CALR)
132+
else if ((vertexTypeMap_[srcVertex] == LAW || vertexTypeMap_[destVertex] == FIRE
133+
|| vertexTypeMap_[destVertex] == EMS)
134+
&& vertexTypeMap_[destVertex] == CALR)
131135
return RC;
132136
else
133137
return ETYPE_UNDEF;

0 commit comments

Comments
 (0)