Skip to content

Commit 54fff38

Browse files
authored
Merge pull request #539 from UWB-Biocomputing/issue-180-width-height-move
[ISSUE 180] Moved width_ and height_ parameter from Simulator to FixedLayout
2 parents 86361b1 + c2f7a35 commit 54fff38

File tree

7 files changed

+78
-84
lines changed

7 files changed

+78
-84
lines changed

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/Layouts/Neuro/FixedLayout.cpp

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include "FixedLayout.h"
10+
#include "ConnGrowth.h"
1011
#include "ParameterManager.h"
1112
#include "ParseParamError.h"
1213
#include "Util.h"
@@ -129,11 +130,10 @@ void FixedLayout::loadParameters()
129130
+ inhibitoryNListFilePath);
130131
}
131132

132-
// Get the total number of vertices
133-
int width, height;
134-
ParameterManager::getInstance().getIntByXpath("//PoolSize/x/text()", width);
135-
ParameterManager::getInstance().getIntByXpath("//PoolSize/y/text()", height);
136-
numVertices_ = width * height;
133+
// Get width, height and total number of vertices
134+
ParameterManager::getInstance().getIntByXpath("//PoolSize/x/text()", width_);
135+
ParameterManager::getInstance().getIntByXpath("//PoolSize/y/text()", height_);
136+
numVertices_ = width_ * height_;
137137
}
138138

139139
/// Returns the type of synapse at the given coordinates
@@ -164,14 +164,64 @@ void FixedLayout::initVerticesLocs()
164164
if (gridLayout_) {
165165
// grid layout
166166
for (int i = 0; i < numVertices; i++) {
167-
xloc_[i] = i % Simulator::getInstance().getHeight();
168-
yloc_[i] = i / Simulator::getInstance().getHeight();
167+
xloc_[i] = i % height_;
168+
yloc_[i] = i / height_;
169169
}
170170
} else {
171171
// random layout
172172
for (int i = 0; i < numVertices; i++) {
173-
xloc_[i] = initRNG.inRange(0, Simulator::getInstance().getWidth());
174-
yloc_[i] = initRNG.inRange(0, Simulator::getInstance().getHeight());
173+
xloc_[i] = initRNG.inRange(0, width_);
174+
yloc_[i] = initRNG.inRange(0, height_);
175175
}
176176
}
177177
}
178+
179+
// Note: This code was previously used for debugging, but it is now dead code left behind
180+
// and it is never executed.
181+
void FixedLayout::printLayout()
182+
{
183+
ConnGrowth &pConnGrowth
184+
= dynamic_cast<ConnGrowth &>(Simulator::getInstance().getModel().getConnections());
185+
186+
cout << "format:\ntype,radius,firing rate" << endl;
187+
188+
for (int y = 0; y < height_; y++) {
189+
stringstream ss;
190+
ss << fixed;
191+
ss.precision(1);
192+
193+
for (int x = 0; x < width_; x++) {
194+
switch (vertexTypeMap_[x + y * width_]) {
195+
case EXC:
196+
if (starterMap_[x + y * width_])
197+
ss << "s";
198+
else
199+
ss << "e";
200+
break;
201+
case INH:
202+
ss << "i";
203+
break;
204+
case VTYPE_UNDEF:
205+
assert(false);
206+
break;
207+
}
208+
209+
ss << " " << pConnGrowth.radii_[x + y * width_];
210+
211+
if (x + 1 < width_) {
212+
ss.width(2);
213+
ss << "|";
214+
ss.width(2);
215+
}
216+
}
217+
218+
ss << endl;
219+
220+
for (int i = ss.str().length() - 1; i >= 0; i--) {
221+
ss << "_";
222+
}
223+
224+
ss << endl;
225+
cout << ss.str();
226+
}
227+
}

Simulator/Layouts/Neuro/FixedLayout.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,16 @@ class FixedLayout : public Layout {
5959
/// @return type of the synapse.
6060
virtual edgeType edgType(const int srcVertex, const int destVertex) override;
6161

62+
/// Prints the layout, used for debugging.
63+
void printLayout();
64+
6265
private:
6366
/// initialize the location maps (xloc and yloc).
6467
void initVerticesLocs();
6568

6669
bool gridLayout_; ///< True if grid layout.
70+
71+
int width_; /// Width of the layout (assumes square)
72+
73+
int height_; /// Height of the layout
6774
};

Testing/UnitTesting/SimulatorTests.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ TEST(Simulator, ParametersInitializedSuccessfully)
2929
ParameterManager::getInstance().loadParameterFile("../configfiles/test-medium-500.xml");
3030
Simulator::getInstance().loadParameters();
3131

32-
EXPECT_EQ(30, Simulator::getInstance().getWidth());
33-
EXPECT_EQ(30, Simulator::getInstance().getHeight());
3432
EXPECT_EQ(BGFLOAT(100), Simulator::getInstance().getEpochDuration());
3533
EXPECT_EQ(500, Simulator::getInstance().getNumEpochs());
3634
EXPECT_EQ(200, Simulator::getInstance().getMaxFiringRate());

0 commit comments

Comments
 (0)