forked from Conedy/Conedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.h
285 lines (179 loc) · 10.3 KB
/
node.h
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
282
283
284
285
#ifndef node_h
#define node_h node_h
#include "networkConstants.h"
#include "baseType.h"
#include <iostream>
#include <vector>
namespace conedy
{
using namespace std;
// Nodetype : int
typedef short int nodeKind; // node kinds correspond to different kinds of dynamical systems or to special nodes for file input and output
const nodeKind _inNode_ = 1 << 1;
const nodeKind _outNode_ = 1 << 2;
const nodeKind _dynNode_ = 1 << 3;
const nodeKind _ode_ = 1 << 4;
const nodeKind _sde_ = 1 << 5;
const nodeKind _pco_ = 1 << 6;
const nodeKind _pcoDelay_ = 1 << 7;
const nodeKind _mapNode_ = 1 << 8;
typedef char edgeKind; // edge kinds determine if an edge is weighted or not.
const edgeKind _weighted_ = 1 << 1;
const edgeKind _polynomial_ = 1 << 2; // erbt von params<vector<baseType>>
//! identifier for nodes, determines the maximum number of nodes.
typedef unsigned int nodeDescriptor;
//! info-object which is returned by all nodes.
struct nodeInfo
{ // a unique identifier for the node type
networkElementType theNodeType;
// a bit mask for booleans which specify the kind of the node. inNode | outNode | dynNode
nodeKind theNodeKind;
// the node name. Printey by printNodeStatistics
string theNodeName;
};
//! info-object which is returned by all edges
struct edgeInfo
{ // unique identifier for the edgetype
networkElementType theEdgeType;
// bit mask with the node type,
edgeKind theEdgeKind;
// the edge name. Printed by printNodeStatistics
string theEdgeName;
};
class node;
class dynNode;
//! base class for all edges. Has no virtual functions. Specialized edges should be defined as template, such that the template parameter is the base class. In this way both edges with and without virtual functions can use the same code.
//! The inheritance looks as following. For static edges:
//! edge -> edge1 -> edge2 -> edge...
//! edge1, edge2 are here different 'features' for edges like coupling weights, edges which point to specific components of nodes, etc.
//! Filter chains can also be implemeted in this way, but is not at the moment.
//! For virtual edges:
// edge -> edgeVirtual -> edge1 -> dege2 -> edge...
// Class which contain the edge features edge1, edge2, ... are the same as for static edges. However, functions like getWeight, getTarget and getTargetSTate are differently interpreted by the compiler. For the static approach they are overloadad funtcions, for the virtual approach they are virtual functions. This allows
class edge
{
public:
typedef dynNode targetNodeType;
//! Number of the target node, pointer to the node is store in node::thenodes
nodeDescriptor targetNumber;
edge() : targetNumber(0) {};
edge ( nodeDescriptor t) :targetNumber ( t ) {};
public:
//! Return pointer to the target node.
nodeDescriptor getTarget();// { return node::theNodes [targetNumber];}
void setParameter(vector < baseType > parameter) { }
void getParameter(vector < baseType > ¶meter) { }
//! Returns the state of the target node.
baseType getTargetState();
//! Return info-object for the edge.
const edgeInfo getEdgeInfo() {edgeInfo ei = {_edge_,0}; return ei;}
// edge *construct() { return new edge ( *this ); };
//! print information about the edge to the console.
ostream& printStatistics ( ostream &os, int edgeOptVerbosity, int theEdgeKind, string theEdgeName, baseType weight);
//! Return the weight of the edge, 1 for unweighted edges.
baseType getWeight() { return (baseType)1; }
//! Set the weight of the edge, throw an exception for unweighted edges.
void setWeight(baseType newWeight) { };
};
//! base class for edges with virtual functions.
class edgeVirtual : public edge
{
public:
edgeVirtual() :edge(0) {};
edgeVirtual ( nodeDescriptor t) :edge(t ) {};
public:
virtual void setParameter(vector < baseType > parameter) { }
virtual void getParameter(vector < baseType > ¶meter) { }
virtual nodeDescriptor getTarget() { return edge::getTarget();}
virtual baseType getTargetState();
virtual const edgeInfo getEdgeInfo() {edgeInfo ei = {_edgeVirtual_,0, "edgeVirtual"}; return ei;}
virtual edgeVirtual *construct() { return new edgeVirtual ( *this ); };
virtual ostream& printStatistics ( ostream &os, int edgeVirtualVerbosity = 1);
virtual ~edgeVirtual() {}
virtual baseType getWeight() { return (baseType)1; }
virtual void setWeight(baseType newWeight) {throw "Trying to set weight of unweighted edge!";}
};
/*!
\Brief Base class for all nodes.
Contains a list of edges and supplies functions like link and unlink, which change this list.
All these functions are only interface functions and are given two different implementations by nodeVirtualEdges and nodeTemplateEdges.
Also contains a vector of pointer to all nodes, which serves as lookup table. In this way edges need only memorize a 32 bit node number instead of a 64 bit pointer.
*/
class node
{
public:
//! virtual function, which returns the standard node state. don't use, its slow. Use specialized edges.
virtual baseType getState() { throw "getState von nodeVirtual aufgerufen !";}
//! returns a description object for the node. The object consists of an identifying integer, a bitmask for the node kind and a string for the node name
virtual const nodeInfo getNodeInfo() { nodeInfo n = {_node_,0}; return n;};
//! returns a copy of this node instance. All nodes which are added to networks are created by such a call. Nodes which are created by standard constructors serve as blueprints only.
virtual node *construct() { throw "unimplemented function construct of node called!"; };
//! Identifizierungs-Objekt für die Edges des Knotens XXX obsolete ?
typedef unsigned int edgeDescriptor;
virtual ~node();
private:
//! return the identifying integer of the given edge. XXX obsolete ?
nodeDescriptor getTarget (edge * e) { return e->targetNumber; }
public:
//! return the description object for the edge.
virtual edgeInfo getEdgeInfo (edgeDescriptor) { throw "unimplemented function getEdgeInfo of node called!"; };
//! sets the weight of the edge ed to w.
virtual void setWeight (edgeDescriptor ed, baseType w) { throw "unimplemented function setWeight of node called!"; };
//! returns a pointer to the target of edge ed XXX should be returning nodedescriptor ?
virtual nodeDescriptor getTarget(edgeDescriptor ed) { throw "unimplemented function getTarget of node called!"; };
//! returns the weight of edge ed.
virtual baseType getWeight (edgeDescriptor ed) { throw "unimplemented function getWeight of node called!"; } ;
//! returns the state of the target of edge ed XXX slow
virtual baseType getTargetState (edgeDescriptor ed) { throw "unimplemented function getTargetState of node called!"; } ;
//! return a pointer to the edge with given edgeDescriptor XXX obsolete ?
virtual edgeVirtual * getEdge (edgeDescriptor) { throw "unimplemented function getEdge of node called!"; };
//! Copy-constructor. Constructed nodes are inserted into the lookup table node::theNodes
node( const node &b ) { theNodes.push_back ( this ); number = theNodes.size() - 1;}
//! Construktor
node ();
// manage connections
//! removes all edges pointing to targetNumber. Warning: removing edges invalidates edgeDescriptors!
virtual bool unlink (nodeDescriptor targetNumber) { throw "unimplemented function unlink of node called!"; };
//! remove edge e.
virtual void removeEdge (edgeDescriptor e) { throw "unimplemented function removeEdge of node called!"; };
virtual void removeEdges () { throw "unimplemented function removeEdges of node called!"; };
//! adds a link which points targetNumber with weight weight.
virtual void link (nodeDescriptor targetNumber, baseType weight) { throw "unimplemented function link of node called!"; };
//! adds a link which is copied from l.
virtual void link (nodeDescriptor targetNumber, edgeVirtual *l) { throw "unimplemented function link of node called!"; };
//! returns true if there is at least one link which points to target
virtual bool isLinked ( nodeDescriptor target ) { throw "unimplemented function isLinked of node called!"; };
//! returns the weight of a link which points to target. Returns 0 if no such link exists.
virtual baseType linkStrength ( nodeDescriptor target ) { throw "unimplemented function linkStrength of node called!"; };
//!
virtual void normalizeInWeightSum(baseType d) { throw "unimplemented function normalizeInWeightSum of node called!"; };
// Statistikkram
//! debug-function which prints all connections and their type to os, depending on nodeVerbosity and edgeVerbosity
virtual void printStatistics(ostream &os, int nodeVerbosity, int edgeVerbosity);
virtual void printEdgeStatistics(ostream &os, int edgeVerbosity = 1);
//! returns the number of connections
virtual unsigned int degree() { throw "unimplemented function degree of node called!"; };
//! gibt die Summe der Verbindungsgewichte aller ausgehende Verbindungen zurück TODO move to statisticNetwork.
virtual baseType weightSum() { throw "unimplemented function weightSum of node called!"; };
//! gibt die Summer der Verbindungsgewichte aller eingehenden Verbindungen zurück TODO move to statisticNetwork.
virtual baseType inWeightSum() { throw "unimplemented function inWeightSum of node called!"; };
//! gibt die Nummer im statischen Vector theNodes zurück, andessen Stelle ein Zeiger auf den momentanen Knotens gespeichert ist.
virtual nodeDescriptor getNumber() { return number; }
//! Statischer Vector mit Zeigern zu allen Knoten, die mit construct erzeugt wurden.
static vector<node* > theNodes;
virtual void clean () {};
protected:
//! so wie couplingSum. Allerdings werden die Zustände zirkulär addiert.
inline baseType getMeanPhaseCoherence();
private:
//! die Nummer vom Knoten. theNodes[number] = this!
nodeDescriptor number;
};
inline nodeDescriptor edge::getTarget() { return targetNumber;};
bool match (nodeDescriptor l, nodeDescriptor r);
bool match (nodeKind l, nodeDescriptor r) ;
bool match (nodeDescriptor l, nodeKind r) ;
bool match (nodeDescriptor l, networkElementType r) ;
bool match (networkElementType l, nodeDescriptor r) ;
}
#endif