Skip to content

Commit 81bb63e

Browse files
authored
Merge branch 'development' into issue-516-rename-summationMap
2 parents e7a4ef6 + 870ef8b commit 81bb63e

File tree

18 files changed

+564
-371
lines changed

18 files changed

+564
-371
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/Core/Model.cpp

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515

1616
#include "Model.h"
17-
#include "ConnGrowth.h"
1817
#include "Connections.h"
1918
#include "Factory.h"
2019
#include "ParameterManager.h"
@@ -106,55 +105,17 @@ void Model::setupSim()
106105
connections_->createEdgeIndexMap();
107106
}
108107

108+
// Note: This method was previously used for debugging, but it is now dead code left behind.
109109
/// Log this simulation step.
110-
void Model::logSimStep() const
111-
{
112-
ConnGrowth *pConnGrowth = dynamic_cast<ConnGrowth *>(connections_.get());
113-
if (pConnGrowth == nullptr)
114-
return;
115-
116-
cout << "format:\ntype,radius,firing rate" << endl;
117-
118-
for (int y = 0; y < Simulator::getInstance().getHeight(); y++) {
119-
stringstream ss;
120-
ss << fixed;
121-
ss.precision(1);
122-
123-
for (int x = 0; x < Simulator::getInstance().getWidth(); x++) {
124-
switch (layout_->vertexTypeMap_[x + y * Simulator::getInstance().getWidth()]) {
125-
case EXC:
126-
if (layout_->starterMap_[x + y * Simulator::getInstance().getWidth()])
127-
ss << "s";
128-
else
129-
ss << "e";
130-
break;
131-
case INH:
132-
ss << "i";
133-
break;
134-
case VTYPE_UNDEF:
135-
assert(false);
136-
break;
137-
}
138-
139-
ss << " " << pConnGrowth->radii_[x + y * Simulator::getInstance().getWidth()];
140-
141-
if (x + 1 < Simulator::getInstance().getWidth()) {
142-
ss.width(2);
143-
ss << "|";
144-
ss.width(2);
145-
}
146-
}
147-
148-
ss << endl;
149-
150-
for (int i = ss.str().length() - 1; i >= 0; i--) {
151-
ss << "_";
152-
}
153-
154-
ss << endl;
155-
cout << ss.str();
156-
}
157-
}
110+
// void Model::logSimStep() const
111+
// {
112+
// FixedLayout *fixedLayout = dynamic_cast<FixedLayout *>(layout_.get());
113+
// if (fixedLayout == nullptr) {
114+
// return;
115+
// }
116+
117+
// fixedLayout->printLayout();
118+
// }
158119

159120
/// Update the simulation history of every epoch.
160121
void Model::updateHistory()

Simulator/Core/Model.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ class Model {
8080
virtual void updateConnections() = 0;
8181

8282
protected:
83+
// Note: This method was previously used for debugging, but it is now dead code left behind.
8384
/// Prints debug information about the current state of the network.
84-
void logSimStep() const;
85+
// void logSimStep() const;
8586

8687
/// Copy GPU Edge data to CPU.
8788
virtual void copyGPUtoCPU() = 0;

Simulator/Core/Simulator.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ void Simulator::finish()
7676
/// Load member variables from configuration file
7777
void Simulator::loadParameters()
7878
{
79-
ParameterManager::getInstance().getIntByXpath("//PoolSize/x/text()", width_);
80-
ParameterManager::getInstance().getIntByXpath("//PoolSize/y/text()", height_);
81-
// numVertices_ = width_ * height_;
82-
8379
ParameterManager::getInstance().getBGFloatByXpath("//SimParams/epochDuration/text()",
8480
epochDuration_);
8581
ParameterManager::getInstance().getIntByXpath("//SimParams/numEpochs/text()", numEpochs_);
@@ -110,7 +106,6 @@ void Simulator::printParameters() const
110106
LOG4CPLUS_DEBUG(fileLogger_,
111107
"\nSIMULATION PARAMETERS"
112108
<< endl
113-
<< "\tpool size x:" << width_ << " y:" << height_ << endl
114109
<< "\tTime between growth updates (in seconds): " << epochDuration_ << endl
115110
<< "\tNumber of epochs to run: " << numEpochs_ << endl
116111
<< "\tMax firing rate: " << maxFiringRate_ << endl
@@ -284,16 +279,6 @@ void Simulator::setStimulusFileName(const string &fileName)
284279
* Accessors
285280
***********************************************/
286281
///@{
287-
int Simulator::getWidth() const
288-
{
289-
return width_;
290-
}
291-
292-
int Simulator::getHeight() const
293-
{
294-
return height_;
295-
}
296-
297282
int Simulator::getTotalVertices() const
298283
{
299284
return model_->getLayout().getNumVertices();

Simulator/Core/Simulator.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ class Simulator {
6161
* Accessors
6262
***********************************************/
6363
///@{
64-
int getWidth() const; /// Width of neuron map (assumes square)
65-
66-
int getHeight() const; /// Height of neuron map
67-
6864
int getTotalVertices() const; /// Count of neurons in the simulation
6965

7066
int getCurrentStep() const; /// Current simulation step
@@ -130,10 +126,6 @@ class Simulator {
130126
Simulator(); /// Constructor is private to keep a singleton instance of this
131127
/// class.
132128

133-
int width_; /// Width of neuron map (assumes square)
134-
135-
int height_; /// Height of neuron map
136-
137129
int totalNeurons_; /// Count of neurons in the simulation
138130

139131
int currentEpoch_; /// Current epoch step

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;

0 commit comments

Comments
 (0)