00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef SIMULATIONMANAGER_H
00024 #define SIMULATIONMANAGER_H
00025
00026
00027 #include "DBInterface.h"
00028 #include "NetworkMonitor.h"
00029 #include "SimulationTypes.h"
00030 #include "BusyDialog.h"
00031 #include "MonitorDataPlotter.h"
00032 #include "GlobalVariables.h"
00033
00034
00035 #include <qthread.h>
00036 #include <qwidget.h>
00037 #include <qprogressdialog.h>
00038 #include <qstring.h>
00039
00040
00041
00042
00043
00044 struct StartSimRes {
00045 bool started;
00046 bool canceled;
00047 };
00048
00049
00050
00051
00052
00053
00054
00055
00056 class SimulationManager : public QObject, public QThread {
00057 Q_OBJECT
00058
00059 public:
00060 SimulationManager(DBInterface *networkDBInterface, DBInterface *archiveDBInterface, DBInterface *patternDBInterface, DBInterface *deviceDBInterface, QWidget *simulationWidget);
00061 ~SimulationManager();
00062 void clearSimulationError();
00063 bool destroySimulation();
00064 void fireNeuron(unsigned int neuronGrpID, unsigned int neuronID);
00065 bool getCleanUpError();
00066 QString getCleanUpErrorMsg();
00067 QString getInitErrorMsg();
00068 QString getSimulationErrorMsg();
00069 bool getViewWeightsSaved();
00070 bool getWeightsLoaded();
00071 bool getWeightsSaved();
00072 StartSimRes initialiseSimulation(QString archiveName, map<unsigned int, unsigned int> patternInputMap, map<unsigned int, unsigned int> deviceInOutMap, map<unsigned int, double>deviceFiringModeMap, map<const char*, unsigned int> paramMap);
00073 void injectNoise(unsigned int neuronGrpID, int amount);
00074 static bool isInitialised();
00075 bool isRunning();
00076 bool loadWeights();
00077 void monitorNeuronGroup(unsigned int neuronGrpID, bool monitorType);
00078 bool saveViewWeights();
00079 bool saveWeights();
00080 void setFrameRate(int fr);
00081 bool setGlobalParameters();
00082 void setGraphicsLoading(bool gl);
00083 void setMaxNeurDataLoadTime_sec(int mNeurData);
00084 void setNetworkMonitors(map<unsigned int, NetworkMonitor*> nwMonitorMap);
00085 void setNeuronMonitors(map<unsigned int, MonitorDataPlotter*> *neurMonMap);
00086 bool setNeuronParameters();
00087 void setSynapseMonitors(map<unsigned int*, MonitorDataPlotter*, synapseKeyCompare> *synMonMap);
00088 bool setNoiseParameters();
00089 bool setSynapseParameters();
00090 void setUpdateMode(bool, bool);
00091 bool simulationError();
00092 bool startNeuronMonitoring(unsigned int neuronGrpID, unsigned int neuronID, bool restart);
00093 bool startRecording();
00094 bool startSimulation();
00095 bool startSynapseMonitoring(unsigned int neuronGrpID, unsigned int fromNeuronID, unsigned int toNeuronID, bool restart);
00096 bool stepSimulation();
00097 void stopMonitoringNeuronGroup(unsigned int neuronGrpID, bool monitorType);
00098 bool stopNeuronMonitoring(unsigned int neuronGrpID, unsigned int neuronID);
00099 bool stopRecording();
00100 bool stopSimulation();
00101 bool stopSynapseMonitoring(unsigned int neurGrpID, unsigned int fromNeurID, unsigned int toNeurID);
00102
00103
00104 signals:
00105 void simulationStartTimeChanged(unsigned int newSimStartTime);
00106
00107
00108 protected:
00109
00110 void run();
00111
00112
00113 private:
00114
00115
00116 int thisTaskID;
00117
00118
00119 DBInterface *networkDBInterface;
00120 DBInterface *archiveDBInterface;
00121 DBInterface *patternDBInterface;
00122 DBInterface *deviceDBInterface;
00123
00124
00125 QWidget *simulationWidget;
00126
00127
00128 SpikeStreamApplication *spikeStrApp;
00129
00130
00131 int archiveTaskID;
00132
00133
00134
00135 map<unsigned int, int> neuronGrpTaskMap;
00136
00137
00138
00139 map<int, NetworkMonitor*> networkMonitorMap;
00140
00141
00142 vector<int> neuronGrpTaskVector;
00143
00144
00145 static bool stop;
00146
00147
00148 bool cleanUpError;
00149
00150
00151 QString cleanUpErrorMsg;
00152
00153
00154 QString initErrorMsg;
00155
00156
00157 bool simError;
00158
00159
00160 QString simulationErrorMsg;
00161
00162
00163 bool simulationRunning;
00164
00165
00166 bool weightsSaved;
00167
00168
00169 map<int, bool> weightsSavedAcknowledgementMap;
00170
00171
00172
00173 bool viewWeightsSaved;
00174
00175
00176 map<int, bool> viewWeightsSavedAcknowledgementMap;
00177
00178
00179 bool synapseWeightsLoaded;
00180
00181
00182 map<int, bool> weightsLoadedAcknowledgementMap;
00183
00184
00185 BusyDialog *busyDialog;
00186
00187
00188
00189 bool graphicsLoading;
00190
00191
00192 map<unsigned int, MonitorDataPlotter*> *neuronMonitorMap;
00193
00194
00195 map<unsigned int*, MonitorDataPlotter*, synapseKeyCompare> *synapseMonitorMap;
00196
00197
00198
00199 int maxNeurDataLoadTime_sec;
00200
00201
00202
00203
00204 SimulationManager (const SimulationManager&);
00205
00206
00207 SimulationManager operator = (const SimulationManager&);
00208
00209 bool checkNeuronGroupTasks();
00210 void cleanUpErrorMsgReceived(int senderTID);
00211 void cleanUpSimulation();
00212 bool createTempVirtualConnections();
00213 bool deleteTempVirtualConnections();
00214 void initErrorMsgReceived(int senderTID);
00215 StartSimRes loadNeuronData(map<unsigned int, unsigned int> patternInputMap, map<unsigned int, unsigned int> deviceInOutMap, map<unsigned int, double>deviceFiringModeMap, map<const char*, unsigned int> paramMap, QProgressDialog* progressDialog);
00216 bool sendMessage(int taskID, int msgtag);
00217 bool sendMessage(int taskID, int msgtag, unsigned int*, int arrayLength);
00218 bool sendMessage(int taskID, int msgtag, int msgData);
00219 bool sendMessage_unsigned(int taskID, int msgtag, unsigned int msgData);
00220 bool sendMessage(int taskID, int msgtag, unsigned int msgData1, unsigned int msgData2);
00221 bool sendMessage(int taskId, int msgtag, double [], int arrayLength);
00222 void showErrorMessage(int senderTID);
00223 void showErrorMessage(const char* msg);
00224 void showInformationMessage();
00225 bool spawnArchiveTask(const QString& archiveName, map<const char*, unsigned int>);
00226 bool spawnNeuronGroupTasks();
00227 bool startPvm();
00228 void unpackMonitorNeuronData();
00229 void unpackMonitorNeuronInfo();
00230 void unpackMonitorSynapseData();
00231 void unpackMonitorSynapseInfo();
00232 void updateViewWeightsSavedState(int taskID);
00233 void updateWeightsLoadedState(int taskID);
00234 void updateWeightsSavedState(int taskID);
00235
00236 };
00237
00238
00239 #endif//SIMULATIONMANAGER_H
00240
00241