From 070ce923574dcc57435cb3fb2dfe86b6a38cd249 Mon Sep 17 00:00:00 2001 From: MDBijman Date: Tue, 24 Jan 2017 12:15:26 +0100 Subject: Initial code commit with organized dependencies --- Simulator/src/Simulator.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Simulator/src/Simulator.cpp (limited to 'Simulator/src/Simulator.cpp') diff --git a/Simulator/src/Simulator.cpp b/Simulator/src/Simulator.cpp new file mode 100644 index 00000000..fe963e0c --- /dev/null +++ b/Simulator/src/Simulator.cpp @@ -0,0 +1,51 @@ +#include "Simulator.h" +#include "modeling/ModelingTypes.h" + +#include +#include +#include +#include + +int main(int argc, char* argv[]) +{ + assert(argc == 2); + + // The main simulator, responsible for updating and writing away each simulation. + Simulation::Simulator simulator(argv[1]); + + // Timer used for polling only once every 5 seconds + auto pollTimer = std::chrono::high_resolution_clock::now() - std::chrono::seconds(5); + + while (true) + { + auto now = std::chrono::high_resolution_clock::now(); + + // Calculate the time since the last polling + std::chrono::duration diff = now - pollTimer; + if (diff.count() > 5) // Every five seconds, poll and load + { + // Poll and load all experiments queued in the database + simulator.pollAndLoadAll(); + // Reset the timer for polling + pollTimer = std::chrono::high_resolution_clock::now(); + } + + if (simulator.hasSimulations()) + { + // Update each simulation + simulator.tickAll(); + // Save the state of each simulation + simulator.saveStateAll(); + // Write the history of each simulation when 500 states have been saved + simulator.writeHistoryAll(); + } + else // Wait for polling + { + std::chrono::duration timeToSleep = std::chrono::seconds(5) - diff; + std::this_thread::sleep_for(diff); + } + } + + // Terminal pause, press key to exit + std::cin.get(); +} -- cgit v1.2.3