NEST  2.6.0,not_revisioned_source_dir@0
subnet.h
Go to the documentation of this file.
1 /*
2  * subnet.h
3  *
4  * This file is part of NEST.
5  *
6  * Copyright (C) 2004 The NEST Initiative
7  *
8  * NEST is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * NEST is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef SUBNET_H
24 #define SUBNET_H
25 
26 #include <vector>
27 #include <string>
28 #include "node.h"
29 #include "dictdatum.h"
30 #include "multirange.h"
31 
32 /* BeginDocumentation
33 
34 Name: subnet - Root node for subnetworks.
35 
36 Description:
37 A network node of type subnet serves as a root node for subnetworks
38 
39 Parameters:
40 Parameters that can be accessed via the GetStatus and SetStatus functions:
41 
42 customdict (dictionarytype) -
43  A user-defined dictionary, which may be used to store additional
44  data.
45 label (stringtype) -
46  A user-defined string, which may be used to give a symbolic name to
47  the node.
48 number_of_children (integertype) -
49  The number of direct children of the subnet
50 
51  SeeAlso: modeldict, Node
52 */
53 
54 namespace nest{
55 
56  using std::vector;
57 
58  class Node;
59 
67  class Subnet: public Node
68  {
69  public:
70 
71  Subnet();
72 
73  Subnet(const Subnet &);
74 
75  virtual ~Subnet(){}
76 
77  void set_status(const DictionaryDatum&);
78  void get_status(DictionaryDatum&) const;
79 
80  bool has_proxies() const;
81 
82  size_t global_size() const;
83  size_t local_size() const;
84  bool global_empty() const;
85  bool local_empty() const;
86 
87  void reserve(size_t);
88 
94  index add_node(Node *);
95 
100  index add_remote_node(index gid, index mid);
101 
105  vector<Node*>::iterator local_begin();
106 
110  vector<Node*>::iterator local_end();
111 
115  vector<Node*>::const_iterator local_begin() const;
116 
120  vector<Node*>::const_iterator local_end() const;
121 
126  Node* at_lid(index) const;
127 
135  std::string get_label() const;
136 
144  void set_label(std::string const);
145 
154 
162  void set_customdict(DictionaryDatum const dict);
163 
164  std::string print_network(int , int, std::string = "");
165 
166  bool is_subnet() const;
167 
168  bool is_homogeneous() const;
169 
170  protected:
171  void init_node_(const Node&) {}
172  void init_state_(const Node&) {}
173  void init_buffers_() {}
174 
175  void calibrate() {}
176  void update(Time const &, const long_t, const long_t) {}
177 
185  vector<Node *> nodes_;
186 
193 
194  private:
195  void get_dimensions_(std::vector<int>&) const;
196 
197  std::string label_;
199  // note that DictionaryDatum is a pointer and must be initialized in the constructor.
202  };
203 
207  inline
209  {
210  const index lid = gids_.size();
211  const index mid = n->get_model_id();
212  if ((homogeneous_) && (lid > 0))
213  if (mid != last_mid_)
214  homogeneous_ = false;
215  n->set_lid_(lid);
216  n->set_subnet_index_(nodes_.size());
217  nodes_.push_back(n);
218  n->set_parent_(this);
219  gids_.push_back(n->get_gid());
220  last_mid_ = mid;
221  return lid;
222  }
223 
227  inline
229  {
230  const index lid = gids_.size();
231  if((homogeneous_) && (lid > 0))
232  if (mid != last_mid_)
233  homogeneous_ = false;
234  last_mid_ = mid;
235  gids_.push_back(gid);
236  return lid;
237  }
238 
239  inline
240  vector<Node*>::iterator Subnet::local_begin()
241  {
242  return nodes_.begin();
243  }
244 
245  inline
246  vector<Node*>::iterator Subnet::local_end()
247  {
248  return nodes_.end();
249  }
250 
251  inline
252  vector<Node*>::const_iterator Subnet::local_begin() const
253  {
254  return nodes_.begin();
255  }
256 
257  inline
258  vector<Node*>::const_iterator Subnet::local_end() const
259  {
260  return nodes_.end();
261  }
262 
263  inline
264  bool Subnet::local_empty() const
265  {
266  return nodes_.empty();
267  }
268 
269  inline
270  bool Subnet::global_empty() const
271  {
272  return gids_.empty();
273  }
274 
275  inline
276  size_t Subnet::global_size() const
277  {
278  return gids_.size();
279  }
280 
281  inline
282  size_t Subnet::local_size() const
283  {
284  return nodes_.size();
285  }
286 
287  inline
289  {
290  // defined for "dense" subnets only
291  assert(local_size() == global_size());
292 
293  if ( lid >= nodes_.size() )
294  throw UnknownNode();
295 
296  return nodes_[lid];
297  }
298 
299  inline
300  void Subnet::reserve(size_t n)
301  {
302  nodes_.reserve(n);
303  }
304 
305  inline
306  std::string Subnet::get_label() const
307  {
308  return label_;
309  }
310 
311  inline
313  {
314  return customdict_;
315  }
316 
317  inline
319  {
320  customdict_=d;
321  }
322 
323  inline
324  bool Subnet::has_proxies() const
325  {
326  return false;
327  }
328 
329  inline
331  {
332  return homogeneous_;
333  }
334 
335 } // namespace
336 
337 #endif
vector< Node * >::iterator local_end()
Return iterator to the end of the local child-list.
Definition: subnet.h:246
size_t index
Unsigned long type for enumerations.
Definition: nest.h:109
Multirange gids_
GIDs of global child nodes.
Definition: subnet.h:192
Base class for all subnet nodes.
Definition: subnet.h:67
index get_gid() const
Return global Network ID.
Definition: node.h:753
Definition: lockptrdatum.h:40
void set_status(const DictionaryDatum &)
Definition: subnet.cpp:57
const Name d("d")
Specific to Izhikevich 2003.
Definition: nest_names.h:83
Declarations for base class Node.
void get_dimensions_(std::vector< int > &) const
Definition: subnet.cpp:71
void get_status(DictionaryDatum &) const
Definition: subnet.cpp:63
void set_label(std::string const)
Set the subnet's user label.
Definition: subnet.cpp:233
index last_mid_
model index of last child
Definition: subnet.h:201
void init_buffers_()
Private function to initialize the buffers of a node.
Definition: subnet.h:173
bool is_subnet() const
Definition: subnet.cpp:245
void push_back(index x)
Definition: multirange.h:75
bool homogeneous_
flag which indicates if the subnet contains different kinds of models.
Definition: subnet.h:200
index size() const
Definition: multirange.h:93
assert(pNet!=0)
void init_state_(const Node &)
Private function to initialize the state of a node to model defaults.
Definition: subnet.h:172
bool local_empty() const
returns true if subnet has no local nodes
Definition: subnet.h:264
DictionaryDatum get_customdict() const
Set the subnet's custom dictionary.
Definition: subnet.h:312
void set_subnet_index_(index)
Index into node array in subnet.
Definition: node.h:777
Definition: nest_time.h:130
vector< Node * > nodes_
Pointer to child nodes.
Definition: subnet.h:185
virtual ~Subnet()
Definition: subnet.h:75
std::string label_
user-defined label for this node.
Definition: subnet.h:197
bool is_homogeneous() const
Definition: subnet.h:330
void calibrate()
Re-calculate dependent parameters of the node.
Definition: subnet.h:175
bool empty() const
Definition: multirange.h:99
size_t local_size() const
Returns number of childern in local process.
Definition: subnet.h:282
std::string get_label() const
Return the subnets's user label.
Definition: subnet.h:306
index add_remote_node(index gid, index mid)
Add a remote node to the subnet.
Definition: subnet.h:228
const Name lid("lid")
Definition: topology_names.h:58
size_t global_size() const
Returns total number of children.
Definition: subnet.h:276
void init_node_(const Node &)
Definition: subnet.h:171
int get_model_id() const
Return model ID of the node.
Definition: node.h:783
Node * at_lid(index) const
Return pointer to Node at given LID if it is local.
Definition: subnet.h:288
void set_parent_(Subnet *)
Set pointer to parent subnet.
Definition: node.h:807
index add_node(Node *)
Add a local node to the subnet.
Definition: subnet.h:208
const Name n("n")
Number of synaptic release sites (int >=0) (Tsodyks2_connection)
Definition: nest_names.h:202
bool has_proxies() const
Returns true if the node has proxies on remote threads.
Definition: subnet.h:324
Class for sequences of ranges acting like a compressed vector.
Definition: multirange.h:35
vector< Node * >::iterator local_begin()
Return iterator to the first local child node.
Definition: subnet.h:240
Base class for all NEST network objects.
Definition: node.h:96
bool global_empty() const
returns true if subnet is empty globally
Definition: subnet.h:270
std::string print_network(int, int, std::string="")
Prints out one line of the tree view of the network.
Definition: subnet.cpp:102
void set_customdict(DictionaryDatum const dict)
Return pointer to the subnet's custom dictionary.
Definition: subnet.h:318
void reserve(size_t)
Definition: subnet.h:300
Exception to be thrown if the specified Node does not exist.
Definition: exceptions.h:175
void set_lid_(index)
Set local id, relative to the parent subnet.
Definition: node.h:771
long long_t
Integer number with at least 32 bit.
Definition: nest.h:96
void update(Time const &, const long_t, const long_t)
Bring the node from state $t$ to $t+n*dt$.
Definition: subnet.h:176
DictionaryDatum customdict_
user-defined dictionary for this node.
Definition: subnet.h:198
Subnet()
Definition: subnet.cpp:35