-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dendrite.cc
282 lines (253 loc) · 9.38 KB
/
dendrite.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*------------------------------------------------------------------------------*/
/* @file dendrite.cc */
/* @details Assign structure for scalar values */
/* @author Paul Isaac's */
/* @date 16.02.2016 */
/* @Copyright © 2016 Paul Isaac's. All rights reserved. */
/*------------------------------------------------------------------------------*/
/* Code snippets used: */
/* Syntax comparison - http://stackoverflow.com & http://cplusplus.com */
/* The class defines a data point and the operations that can be carried out on */
/* it. */
/* Using the hierarchical linking the aim is to develop the application to */
/* relate to real-world physics. This will then ease mapping between simulation,*/
/* emulation and real-world universes. */
#include "dendrite.h"
#include "dendritebranch.h"
bool Dendrite::ResetParameters(std::chrono::time_point<Clock> event_time)
{
// If object instantiated without a time specified then add one.
if(time_object_created == std::chrono::time_point<Clock>(std::chrono::nanoseconds::zero()))
{
time_object_created = event_time;
srand((std::chrono::duration_cast<std::chrono::seconds>(TheTimeNow().time_since_epoch()).count()));
}
// If object instantiated without a type specified the set one.
if(dendrite_type < 1)
{
dendrite_type = 1;
}
m_Volume = 100;
m_SurfaceArea = 100;
m_Length = 100;
object_energy_threshold = 500;
switch(dendrite_type)
{
case 0:
{
m_Volume = 100;
m_SurfaceArea = 100;
m_Length = 100;
break;
}
case 1:
{
m_Volume = 100;
m_SurfaceArea = 100;
m_Length = 100;
break;
}
case 2:
{
m_Volume = 100;
m_SurfaceArea = 100;
m_Length = 100;
break;
}
}
return true;
}
Dendrite* Dendrite::CreateDendriteBranch(std::chrono::time_point<Clock> event_time)
{
if(dendritebranch_list.size() < dendritebranch_pool)
{
DendriteBranch* new_object = new DendriteBranch();
return new_object;
}
else
return nullptr;
}
std::vector<Dendrite*> Dendrite::CreateDendriteBranches(std::chrono::time_point<Clock> event_time, int quantity)
{
quantity = std::min(dendritebranch_pool - int(dendritebranch_list.size()), quantity);
std::vector<Dendrite*> new_dendritebranch_list;
new_dendritebranch_list.clear();
if(quantity > 0)
{
for (int nloop = 0; nloop < quantity; nloop++)
{
Dendrite* new_object = CreateDendriteBranch(event_time);
if(new_object != nullptr)
{
dendritebranch_list.push_back(new_object);
new_dendritebranch_list.push_back(new_object);
}
else nloop = quantity;
}
}
return new_dendritebranch_list;
}
std::vector<Dendrite*> Dendrite::CloneDendriteBranches(std::chrono::time_point<Clock> event_time, std::vector<Dendrite*> cloning_list, double perfection_membership)
{
// Function TBD
return std::vector<Dendrite*>();
}
Dendrite* Dendrite::CloneDendriteBranch(std::chrono::time_point<Clock> event_time, Dendrite* clone_object, double perfection_membership)
{
// Function TBD
return nullptr;
}
std::vector<Dendrite*> Dendrite::DestroyDendriteBranches(std::chrono::time_point<Clock> event_time, std::vector<Dendrite*> destruction_list)
{
// Function TBD
return std::vector<Dendrite*>();
}
Dendrite* Dendrite::DestroyDendriteBranch(std::chrono::time_point<Clock> event_time, Dendrite* destroy_object)
{
// Function TBD
return nullptr;
}
Dendrite* Dendrite::AddDendriteBranch(std::chrono::time_point<Clock> event_time, Dendrite* add_object)
{
if(add_object != nullptr)
{
dendritebranch_list.push_back(add_object);
return dendritebranch_list.back();
}
else
return nullptr;
}
std::vector<Dendrite*> Dendrite::AddDendriteBranches(std::chrono::time_point<Clock> event_time, std::vector<Dendrite*> add_objects)
{
int quantity = int(add_objects.size());
quantity = std::min(dendritebranch_pool - int(dendritebranch_list.size()), quantity);
if(quantity > 0)
{
for (int nloop = 0; nloop < quantity; nloop++)
{
if(add_objects[nloop] != nullptr)
{
Dendrite* result = AddDendriteBranch(event_time, add_objects[nloop]);
if(add_objects[nloop] != result)
{
nloop = quantity;
}
}
}
}
return dendritebranch_list;
}
Dendrite* Dendrite::RemoveDendriteBranch(std::chrono::time_point<Clock> event_time)
{
// Function TBD
return nullptr;
}
std::vector<Dendrite*> Dendrite::RemoveDendriteBranches(std::chrono::time_point<Clock> event_time, int quantity)
{
// Function TBD
return std::vector<Dendrite*>();
}
Dendrite* Dendrite::GetDendriteBranch(std::chrono::time_point<Clock> event_time, int selector)
{
return dendritebranch_list[selector];
}
std::vector<Dendrite*> Dendrite::GetDendriteBranches(std::chrono::time_point<Clock> event_time)
{
return dendritebranch_list;
}
int Dendrite::Growth(std::chrono::time_point<Clock> event_time)
{
if (object_energy > (object_energy_threshold * .9))
{
// time_dimension_pointer->AddTemporalAdjustment(event_time, &object_size, 1, 10000, 0);
Dendrite* dendritebranch_pointer = CreateDendriteBranch(event_time);
dendritebranch_pointer->SetObjectType(event_time, TYPE_NEURON_PYRAMIDAL_SOMA_DENDRITE_DENDRITEBRANCH_GEN1);
dendritebranch_list.push_back(dendritebranch_pointer);
}
if (object_energy < (object_energy_threshold * .1))
{
// time_dimension_pointer->AddTemporalAdjustment(event_time, &object_size, -1, 10000, 0);
}
if (object_size < 1)
{
object_size = 1;
}
if (object_size > 50)
{
object_size = 50;
}
return 0;
}
int Dendrite::Update(std::chrono::time_point<Clock> event_time)
{
// If this is the first time that Update is called after object instantiation use the setup parameters.
// object_initialised should then report true and then not be re-run.
if(!object_initialised)
{
object_initialised = ResetParameters(event_time);
auto visualisation_pointer = dynamic_cast<Solid*>(dynamic_cast<Neuron*>(visualisation_list[0]))->CreatePolyhedron(event_time);
visualisation_pointer->SetObjectType(event_time, TYPE_SOLID_POLYHEDRON_SOMA_DENDRITE_GEN1);
visualisation_list.push_back(visualisation_pointer);
}
if(event_time != previous_event_time)
{
// time_dimension_pointer->AdjustCounters(event_time);
duration_since_last_event = std::chrono::duration_cast<std::chrono::nanoseconds>(event_time - previous_event_time).count();
if (duration_since_last_event < 0)
{
duration_since_last_event = 0;
}
if (object_energy < 0)
{
object_energy = 0;
}
if (duration_since_last_event > 0 && object_energy > 0)
{
#pragma omp parallel
{
#pragma omp single nowait
{
// for(std::vector<DendriteBranch>::iterator it = dendritebranch_list.begin(); it != dendritebranch_list.end(); ++it)
{
#pragma omp task
// it->Update(event_time);
}
}
#pragma omp single nowait
{
/*
for(std::vector<Dendrite*>::iterator it = dynamic_cast<Dendrite*>(dendritebranch_list.begin()); it != dynamic_cast<Dendrite*>(dendritebranch_list.end()); ++it)
{
#pragma omp task
(*it)->Update(event_time);
}
*/
}
}
if (object_energy < object_energy_threshold)
{
/*
for(std::vector<Dendrite*>::iterator it = dendritebranch_list.begin(); it != dendritebranch_list.end(); ++it)
{
// time_dimension_pointer->AddTemporalAdjustment(event_time, &object_energy, it->AddTemporalAdjustment(event_time), 100, 1); // absorb energy
}
// for(std::vector<DendriteBranch>::iterator it = dendritebranch_list.begin(); it != dendritebranch_list.end(); ++it) {
// // time_dimension_pointer->AddTemporalAdjustment(event_time, &object_energy, it->AddTemporalAdjustment(event_time), 100, 1); // absorb energy
*/
}
duration_since_last_event = std::chrono::duration_cast<std::chrono::nanoseconds>(event_time - previous_event_time).count();
if (duration_since_last_event < 0)
{
duration_since_last_event = 0;
}
if (duration_since_last_event > 1000)
{
Growth(event_time);
object_energy_threshold = object_size * 1000;
}
}
// Clock duration does not consider parallel or serial operation
previous_event_time = event_time;
}
return 0;
}