DPsim
Loading...
Searching...
No Matches
SequentialScheduler.cpp
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
9#include <dpsim/SequentialScheduler.h>
10
11using namespace CPS;
12using namespace DPsim;
13
14#include <chrono>
15#include <deque>
16#include <iostream>
17#include <set>
18#include <typeinfo>
19#include <unordered_map>
20
21void SequentialScheduler::createSchedule(const Task::List &tasks,
22 const Edges &inEdges,
23 const Edges &outEdges) {
24 if (mOutMeasurementFile.size() != 0)
25 Scheduler::initMeasurements(tasks);
26 Scheduler::topologicalSort(tasks, inEdges, outEdges, mSchedule);
27
28 for (auto task : mSchedule)
29 SPDLOG_LOGGER_INFO(mSLog, "{}", task->toString());
30}
31
32void SequentialScheduler::step(Real time, Int timeStepCount) {
33 if (mOutMeasurementFile.size() != 0) {
34 for (auto task : mSchedule) {
35 auto start = std::chrono::steady_clock::now();
36 task->execute(time, timeStepCount);
37 auto end = std::chrono::steady_clock::now();
38 updateMeasurement(task.get(), end - start);
39 }
40 } else {
41 for (auto it : mSchedule) {
42 it->execute(time, timeStepCount);
43 }
44 }
45}
46
48 if (mOutMeasurementFile.size() != 0)
49 writeMeasurements(mOutMeasurementFile);
50}
void writeMeasurements(CPS::String filename)
Write measurement data to file.
Definition Scheduler.cpp:32
void topologicalSort(const CPS::Task::List &tasks, const Edges &inEdges, const Edges &outEdges, CPS::Task::List &sortedTasks)
Simple topological sort, filtering out tasks that do not need to be executed.
std::unordered_map< CPS::Task::Ptr, std::deque< CPS::Task::Ptr > > Edges
Definition Scheduler.h:31
void updateMeasurement(CPS::Task *task, TaskTime time)
Definition Scheduler.cpp:28
CPS::Logger::Log mSLog
Logger.
Definition Scheduler.h:106
void stop()
Called on simulation stop to reliably clean up e.g. running helper threads.
void step(Real time, Int timeStepCount)
Performs a single simulation step.
void createSchedule(const CPS::Task::List &tasks, const Edges &inEdges, const Edges &outEdges)
Creates the schedule for the given dependency graph.