forked from Conedy/Conedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathioNode.h
274 lines (183 loc) · 8.87 KB
/
ioNode.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
#ifndef ioNode_h
#define ioNode_h ioNode_h
#define BOOST_IOSTREAMS_UNREACHABLE_RETURN(x) return x;
#ifndef M_PI
#define M_PI 3.14159265358979323846f
#endif
#include "node.h"
//#include "analData.h"
//#include "Tdata.h"
#include "dynNode.h"
#include <iomanip>
#include <map>
#include "globals.h"
#include "nodeImplement.h"
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file.hpp>
using namespace std;
namespace io = boost::iostreams;
//using namespace boost::iostreams;
#include <iostream>
namespace conedy
{
class streamOutNodeBinary : public nodeVirtualEdges<dynNode>, private globals
{
protected:
baseType x;
//! Vector mit allen Ausgabeobjekten.
static std::vector<ostream*> out;
//! counter[a] speichert, wieviele Nodes das a.-ten Ausgabeobjekt benutzen.
static std::map<int, unsigned int> counter;
//! Zuordnung von Dateinamen zu der Nummer des entsprechenden Ausgabeobjekts im Vector out.
static std::map<string, int> streamNumber;
//! zuordnung von der Nummer der Ausgabeobjekte in out zum Namen der Datei, in die geschrieben wird.
static std::map<int,string> stringOfStreamNumber;
//! Kleinste Nummer im Ausgabeobjektvector out, die noch nicht verwendet wird.
static int smallestUnusedNumber;
//! Nummer des Lokalen Ausgabeobjekts.
int localStreamNumber;
public:
//! Ausgabenodes brauchen keinen Aufruf von evolve, und somit gibt timeEvolution 0 zurück.
virtual bool timeEvolution () { return 0; }
//! Ausgabenodes brauchen keinen Speicherplatz von dynNode reserviert zu bekommen -> dimension = 0
virtual const unsigned int dimension() const { return 0;}
streamOutNodeBinary ( networkElementType n ) : nodeVirtualEdges<dynNode>( n ) {};
node * construct () { return new streamOutNodeBinary ( *this ); }
virtual ~streamOutNodeBinary();
virtual void evolve(baseType time) {
x = this->couplingSum();
out [localStreamNumber]->write ( (char *) &x, sizeof (baseType));
};
// virtual node *construct();
streamOutNodeBinary ( const streamOutNodeBinary& n ) : nodeVirtualEdges<dynNode> (n) { localStreamNumber = n.localStreamNumber; counter[localStreamNumber]++; }
streamOutNodeBinary ( string s, networkElementType n = _streamOutNodeBinary_ );
// virtual void streamOut(outStream & out);
// streamOutNodeBinary(string s, string command);
virtual const nodeInfo getNodeInfo() { nodeInfo n = {_streamOutNodeBinary_,_outNode_, "streamOutNodeBinary" }; return n; };
};
//! Klasse, die Werte in Dateien wegschreibt. Verwendet Boost-iostreamm damit Dateien direkt on-the-fly gezipt werden können. Die Ausgabeobjekte werden statisch verwaltet, damit verschiedene Nodes in dieselbe Datei schreiben können.
class streamOutNode : public nodeVirtualEdges<dynNode>, public globals
{
public:
baseType x;
//! Vector mit allen Ausgabeobjekten.
static std::vector<io::filtering_ostream*> out;
//! counter[a] speichert, wieviele Nodes das a.-ten Ausgabeobjekt benutzen.
static std::map<int, unsigned int> counter;
//! Zuordnung von Dateinamen zu der Nummer des entsprechenden Ausgabeobjekts im Vector out.
static std::map<string, int> streamNumber;
//! zuordnung von der Nummer der Ausgabeobjekte in out zum Namen der Datei, in die geschrieben wird.
static std::map<int,string> stringOfStreamNumber;
//! Kleinste Nummer im Ausgabeobjektvector out, die noch nicht verwendet wird.
static int smallestUnusedNumber;
//! Nummer des Lokalen Ausgabeobjekts.
int localStreamNumber;
public:
void enter();
//! Ausgabenodes brauchen keinen Aufruf von evolve, und somit gibt timeEvolution 0 zurück.
virtual bool timeEvolution () { return 0; }
static void registerStandardValues()
{
registerGlobal<bool> ("outputCompress", false);
registerGlobal<bool> ("outputAppend", false);
registerGlobal<int> ("outputPrecision", 15);
}
//! Ausgabenodes brauchen keinen Speicherplatz von dynNode reserviert zu bekommen -> dimension = 0
virtual const unsigned int dimension() const { return 0;}
streamOutNode ( networkElementType n ) : nodeVirtualEdges<dynNode>( n ) {};
node * construct () { return new streamOutNode ( *this ); }
virtual ~streamOutNode();
virtual void evolve(baseType time) ;
// virtual node *construct()
// {
// return new streamOutNode(*this);
// }
streamOutNode ( const streamOutNode& n ) : nodeVirtualEdges<dynNode> (n) { localStreamNumber = n.localStreamNumber; counter[localStreamNumber]++; }
streamOutNode ( string s, networkElementType n = _streamOutNode_ );
// virtual void streamOut(outStream & out);
// streamOutNode(string s, string command);
virtual const nodeInfo getNodeInfo() { nodeInfo n = {_streamOutNode_,_outNode_, "streamOutNode" }; return n; };
};
class streamOutNodeCountEquals : public streamOutNode
{
baseType lastValue;
unsigned int count;
public:
streamOutNodeCountEquals ( networkElementType n ) : streamOutNode( n ), lastValue (0.0), count (0) {};
streamOutNodeCountEquals ( string s, networkElementType n = _streamOutNode_ ) : streamOutNode(s, n) {};
virtual void evolve (baseType time);
node * construct () { return new streamOutNodeCountEquals (*this); }
};
class streamOutNodeHist : public streamOutNode
{
public:
static void registerStandardValues()
{
registerGlobal<baseType> ("streamOutNodeHist_lowest", 0.0);
registerGlobal<baseType> ("streamOutNodeHist_highest", 1.0);
registerGlobal<int> ("streamOutNodeHist_bins", 200);
}
node * construct () { return new streamOutNodeHist (*this); }
streamOutNodeHist ( networkElementType n ) : streamOutNode( n ) {}
streamOutNodeHist ( string s, networkElementType n = _streamOutNode_) : streamOutNode(s, n) {};
virtual void evolve (baseType time);
};
//! Klasse, die Werte in Dateien wegschreibt. Verwendet Boost-iostreamm damit Dateien direkt on-the-fly gezipt werden können. Die Ausgabeobjekte werden statisch verwaltet, damit verschiedene Nodes in dieselbe Datei schreiben können.
//! Knoten, der die vektorielle Summe Targetstates zurückgibt.
class calculateMeanPhaseCoherence : public nodeVirtualEdges<dynNode>
{
public:
virtual bool timeEvolution() { return 0; }
virtual const nodeInfo getNodeInfo() { nodeInfo n = {_calculateMeanPhaseCoherence_,0,"calculateMeanPhaseCoherence"}; return n; };
virtual const unsigned int dimension() const { return 0;}
node * construct () { return new calculateMeanPhaseCoherence (*this); }
calculateMeanPhaseCoherence() : nodeVirtualEdges<dynNode>(_calculateMeanPhaseCoherence_) {};
virtual void clean () {};
virtual baseType getState();
};
//! Berechnet die mittlere Phase der angekopplten Knoten aus.
class calculateMeanPhase : public nodeVirtualEdges<dynNode>
{
public:
virtual bool timeEvolution() { return 0; }
virtual const nodeInfo getNodeInfo() { nodeInfo n = {_calculateMeanPhase_,_dynNode_|_inNode_,"calculateMeanPhase"}; return n; };
virtual const unsigned int dimension() const { return 0;}
node * construct () { return new calculateMeanPhase (*this); }
calculateMeanPhase() : nodeVirtualEdges<dynNode>(_calculateMeanPhase_) {};
virtual void clean () {};
virtual baseType getState();
};
//! Eingabe-node, der Werte aus einer Datei liest und bei Aufruf von getState zurückgibt.
class streamInNode : public nodeVirtualEdges<dynNode>, private globals
{
protected:
static std::vector<io::filtering_istream*> in;
static std::map<int, unsigned int> counter;
static std::map<string, int> streamNumber;
static std::map<int,string> stringOfStreamNumber;
static int smallestUnusedNumber;
int localStreamNumber;
bool inline zipInput() { return ( bool ) getGlobal<bool>("inputCompress"); }
public:
virtual bool timeEvolution () { return 0; }
static void registerStandardValues()
{
registerGlobal<bool>("inputCompress", false);
}
virtual const unsigned int dimension() const { return 1;}
streamInNode ( networkElementType n ) : nodeVirtualEdges<dynNode> ( n, 1 ) {};
virtual node * construct() { return new streamInNode (*this); }
virtual ~streamInNode();
// streamInNode ( outStream &o, int i ) : node ( i, _streamInNode_ ) {};
virtual void evolve(baseType time) { ( * ( in[localStreamNumber] ) ) >> dynNode::x[0]; }; //cout << x << endl; };
// virtual void swap () { this->state = x; };
streamInNode ( const streamInNode& n ) : nodeVirtualEdges<dynNode>(n) { localStreamNumber = n.localStreamNumber; counter[localStreamNumber]++; }
streamInNode ( string s, networkElementType n = _streamInNode_ );
// virtual void streamIn(outStream & out);
// streamInNode(string s, string command);
virtual const nodeInfo getNodeInfo() { nodeInfo n = {_streamInNode_,_inNode_|_dynNode_ , "streamInNode"}; return n; };
};
}
#endif