DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
simulator.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // DISPLACE: DYNAMIC INDIVIDUAL VESSEL-BASED SPATIAL PLANNING
3 // AND EFFORT DISPLACEMENT
4 // Copyright (c) 2012-2019 Francois Bastardie <fba@aqua.dtu.dk>
5 
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // --------------------------------------------------------------------------
20 
21 /* --------------------------------------------------------------------------
22  * DISPLACE: DYNAMIC INDIVIDUAL VESSEL-BASED SPATIAL PLANNING
23  * AND EFFORT DISPLACEMENT
24  * Copyright (c) 2012, 2013, 2014 Francois Bastardie <fba@aqua.dtu.dk>
25  *
26  * This program is free software; you can redistribute it and/or modify
27  * it under the terms of the GNU General Public License as published by
28  * the Free Software Foundation; either version 2 of the License, or
29  * (at your option) any later version.
30  *
31  * This program is distributed in the hope that it will be useful,
32  * but WITHOUT ANY WARRANTY; without even the implied warranty of
33  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34  * GNU General Public License for more details.
35  *
36  * You should have received a copy of the GNU General Public License along
37  * with this program; if not, write to the Free Software Foundation, Inc.,
38  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
39  * --------------------------------------------------------------------------
40  */
41 #ifndef SIMULATOR_H
42 #define SIMULATOR_H
43 
44 #include <QObject>
45 #include <QProcess>
46 
47 #include <simulatoripcmanager.h>
48 #include <Vessel.h>
49 #include <memory>
50 
51 class DisplaceModel;
52 class OutputFileParser;
53 
57 class Simulator : public QObject
58 {
59  Q_OBJECT
60 public:
61  Simulator();
62  ~Simulator();
63 
64  void linkModel (std::shared_ptr<DisplaceModel> model);
65  bool start(QString outdir, QString name, QString folder, QString simul_name);
66  bool isRunning();
67  bool forceStop();
68  QProcess::ProcessState processState() const;
69 
70  void setSimSteps(int value);
71  void setUseStaticPaths(int value);
73  void setVerbosityLevel(int value) { mVerbosity = value; }
74 
75  bool getMoveVesselOption() const;
76  void setMoveVesselOption(bool value);
77 
80 
81  void setOutDir(const QString &value);
82  void setOutputName(const QString &value);
83 
84  bool wasSimulationStarted() const;
85 
86 signals:
87  void log(QString);
88  void simulationEnded (int status);
89  void processStateChanged(QProcess::ProcessState oldstate, QProcess::ProcessState newstate);
90  void simulationStepChanged(int);
91  void vesselMoved (int laststep, int idx, float x, float y, float course, float fuel, int state);
92  void shipMoved (int laststep, int idx, float x, float y, float course);
93  void outputFileUpdated(QString, int);
94  void nodesStatsUpdate(QString);
95  void debugMemoryStats(long rss, long peak);
96  void debugCapture(QString);
97  void sqliteStorageOpened(QString);
98 
99 private slots:
100  void error(QProcess::ProcessError);
101  void finished (int, QProcess::ExitStatus);
102  void readyReadStandardError();
103  void readyReadStandardOutput();
104  void started();
105  void subprocessStateChanged(QProcess::ProcessState);
106  bool processCodedLine(QString line);
107  void vesselLogbookReceived(VesselStats);
108 
109 private:
110  QProcess *mSimulation;
111  QThread *mIpcThread;
112  SimulatorIpcManager *mIpcQueue;
113  std::shared_ptr<DisplaceModel> mModel;
114  int mSimSteps;
115  int useStaticPaths;
116  int mLastStep;
117  QString mOutDir;
118  QString mOutputName;
119  QString mSimuName;
120  bool mMoveVesselOption;
121  int mVesselMoveDisplayUpdateRate;
122  QProcess::ProcessState mProcessState;
123  bool mCapture;
124  int mVerbosity;
125 
126  void parseUpdateVessel(QStringList fields);
127  void parseUpdateShip(QStringList fields);
128  void parseUpdateVesselStats(QStringList fields);
129  void parseDebug(QStringList fields);
130  void parseOutputSpecs(QString details);
131 
132 public:
133  static QString SET_NUMTHREADS;
134  static QString SET_VERBOSITY;
135 };
136 
137 #endif // SIMULATOR_H
Definition: outputfileparser.h:53
void debugCapture(QString)
Definition: moc_simulator.cpp:342
QProcess::ProcessState processState() const
Definition: simulator.cpp:191
void processStateChanged(QProcess::ProcessState oldstate, QProcess::ProcessState newstate)
Definition: moc_simulator.cpp:293
Simulator()
Definition: simulator.cpp:42
bool getMoveVesselOption() const
Definition: simulator.cpp:273
int getVesselMoveDisplayUpdateRate() const
Definition: simulator.cpp:263
void debugMemoryStats(long rss, long peak)
Definition: moc_simulator.cpp:335
bool isRunning()
Definition: simulator.cpp:177
static QString SET_NUMTHREADS
Definition: simulator.h:133
void setPreexistingPathsShop(int value)
Definition: vesseldata.h:152
string outdir
Definition: main.cpp:425
An ongoing simulation process.
Definition: simulator.h:57
void setVesselMoveDisplayUpdateRate(int value)
Definition: simulator.cpp:268
void simulationEnded(int status)
void outputFileUpdated(QString, int)
Definition: moc_simulator.cpp:321
bool start(QString outdir, QString name, QString folder, QString simul_name)
Definition: simulator.cpp:77
void simulationStepChanged(int)
Definition: moc_simulator.cpp:300
void setMoveVesselOption(bool value)
Definition: simulator.cpp:278
void log(QString)
Definition: moc_simulator.cpp:286
void setUseStaticPaths(int value)
Definition: simulator.cpp:288
Definition: displacemodel.h:71
~Simulator()
Definition: simulator.cpp:61
std::pair< box, unsigned > value
Definition: diffusion.cpp:30
void setOutputName(const QString &value)
Definition: simulator.cpp:258
bool wasSimulationStarted() const
Definition: simulator.cpp:248
bool forceStop()
Definition: simulator.cpp:182
void linkModel(std::shared_ptr< DisplaceModel > model)
Definition: simulator.cpp:71
void sqliteStorageOpened(QString)
Definition: moc_simulator.cpp:349
void shipMoved(int laststep, int idx, float x, float y, float course)
Definition: moc_simulator.cpp:314
Definition: simulatoripcmanager.h:48
void setVerbosityLevel(int value)
Definition: simulator.h:73
void setOutDir(const QString &value)
Definition: simulator.cpp:253
void setSimSteps(int value)
Definition: simulator.cpp:283
static QString SET_VERBOSITY
Definition: simulator.h:134
void nodesStatsUpdate(QString)
Definition: moc_simulator.cpp:328
void vesselMoved(int laststep, int idx, float x, float y, float course, float fuel, int state)
Definition: moc_simulator.cpp:307