DPsim
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 
11 using namespace CPS;
12 using namespace DPsim;
13 
14 #include <chrono>
15 #include <deque>
16 #include <iostream>
17 #include <set>
18 #include <typeinfo>
19 #include <unordered_map>
20 
21 void 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 
32 void 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 
47 void SequentialScheduler::stop() {
48  if (mOutMeasurementFile.size() != 0)
49  writeMeasurements(mOutMeasurementFile);
50 }
std::unordered_map< CPS::Task::Ptr, std::deque< CPS::Task::Ptr > > Edges
Definition: Scheduler.h:31