summaryrefslogtreecommitdiff
path: root/Simulator/include/Simulator.h
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2017-07-09 23:48:06 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2017-07-09 23:48:06 +0200
commitc94d0c347fdbd8acc774df4ac17617a3f63e4507 (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /Simulator/include/Simulator.h
parentbc4c41e21a64b444bdbab3b6d1d407fd5d919419 (diff)
Delete old codebase
This change removes version 1 of the OpenDC simulator codebase as it will be replaced by a complete rewrite in the Kotlin language.
Diffstat (limited to 'Simulator/include/Simulator.h')
-rw-r--r--Simulator/include/Simulator.h139
1 files changed, 0 insertions, 139 deletions
diff --git a/Simulator/include/Simulator.h b/Simulator/include/Simulator.h
deleted file mode 100644
index d0828dcd..00000000
--- a/Simulator/include/Simulator.h
+++ /dev/null
@@ -1,139 +0,0 @@
-#pragma once
-#include "simulation/Section.h"
-#include "database/Database.h"
-
-#include <iostream>
-#include <unordered_map>
-
-namespace Simulation
-{
- /*
- The Simulator class controls (the creation of) all experiments, and providing access to the database.
- */
- class Simulator
- {
- public:
- /*
- Initializes the simulator with an empty list of experiments, and with a reference to the database.
- */
- explicit Simulator(char* databaseName) : database(databaseName) {}
-
- /*
- Adds a simulation to the list of experiments from the database, removing it from the queue
- of experiments in the database.
- */
- void load(int experimentId)
- {
- Experiment experiment = database.createExperiment(experimentId);
- experiments.insert(std::make_pair(experimentId, experiment));
- database.dequeueExperiment(experimentId);
- }
-
- /*
- Polls the database for new jobs and simulates every queued simulation it finds.
- */
- void pollAndLoadAll()
- {
- int rc = pollAndLoad();
- if (rc != -1)
- pollAndLoadAll();
- }
-
- /*
- Polls the database for new jobs and simulates the first it finds.
- */
- int pollAndLoad()
- {
- int id = database.pollQueuedExperiments();
- if (id != -1)
- {
- std::cout << "Loaded simulation section " << id << std::endl;
- load(id);
- }
- return id;
- }
-
- /*
- Writes the state of all experiments if their history is size 3000 or larger.
- */
- void writeHistoryAll()
- {
- if (experiments.size() == 0)
- return;
-
- auto it = experiments.begin();
- while(it != experiments.end())
- {
- auto& history = (*it).second.getHistory();
- if (history.historySize() > 3000 || (*it).second.isFinished())
- write((*it).first);
-
- if ((*it).second.isFinished())
- {
- std::cout << "Finished simulation." << std::endl;
- database.finishExperiment((*it).first);
- it = experiments.erase(it);
- }
- else
- {
- ++it;
- }
- }
- }
-
- /*
- Writes the state of the given simulation to the database.
- */
- void write(int id)
- {
- std::cout << "Writing batch." << std::endl;
- database.startTransaction();
- database.writeExperimentHistory(experiments.at(id));
- database.endTransaction();
- auto history = experiments.at(id).getHistory();
- history.clearHistory();
- std::cout << "Finished writing batch." << std::endl;
- }
-
- /*
- Ticks each simulation once.
- */
- void tickAll()
- {
- for (std::pair<const int, Experiment>& s : experiments)
- s.second.tick();
- }
-
- /*
- Ticks the given simulation once.
- */
- void tick(int simulationId)
- {
- experiments.at(simulationId).tick();
- }
-
- /*
- Returns true if all experiments are finished.
- */
- bool hasSimulations() const
- {
- return experiments.size() != 0;
- }
-
- /*
- Saves the state of all workloads to the history.
- */
- void saveStateAll()
- {
- for (auto& pair : experiments)
- pair.second.saveState();
- }
-
- private:
- // The database to write results to.
- Database::Database database;
-
- // The list of experiments.
- std::unordered_map<int, Experiment> experiments;
- };
-}