FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
schedule_period.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2025-present FERS Contributors (see AUTHORS.md).
4//
5// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
6
7#include "schedule_period.h"
8
9#include <algorithm>
10
11#include "core/logging.h"
12#include "core/parameters.h"
13
14namespace radar
15{
16
17 std::vector<SchedulePeriod> processRawSchedule(std::vector<SchedulePeriod> periods, const std::string& ownerName,
18 const bool isPulsed, const RealType pri)
19 {
20 if (periods.empty())
21 {
22 return {};
23 }
24
25 std::vector<SchedulePeriod> valid_periods;
26 valid_periods.reserve(periods.size());
27
28 const RealType sim_start = params::startTime();
29 const RealType sim_end = params::endTime();
30
31 // 1. Filter invalid and out-of-bounds periods
32 for (const auto& p : periods)
33 {
34 if (p.start >= p.end)
35 {
37 "Object '{}' has a schedule period with start ({}) >= end ({}). Ignoring period.", ownerName,
38 p.start, p.end);
39 continue;
40 }
41
42 if (p.end <= sim_start || p.start >= sim_end)
43 {
45 "Object '{}' has a schedule period [{}, {}] completely outside simulation time. Ignoring.",
46 ownerName, p.start, p.end);
47 continue;
48 }
49 valid_periods.push_back(p);
50 }
51
52 if (valid_periods.empty())
53 {
54 return {};
55 }
56
57 // 2. Sort by start time
58 std::sort(valid_periods.begin(), valid_periods.end(),
59 [](const auto& a, const auto& b) { return a.start < b.start; });
60
61 // 3. Merge overlapping intervals
62 std::vector<SchedulePeriod> merged;
63 merged.reserve(valid_periods.size());
64 merged.push_back(valid_periods.front());
65
66 for (size_t i = 1; i < valid_periods.size(); ++i)
67 {
68 if (valid_periods[i].start <= merged.back().end)
69 {
70 // Overlap or adjacency: extend the previous period
71 merged.back().end = std::max(merged.back().end, valid_periods[i].end);
72 }
73 else
74 {
75 merged.push_back(valid_periods[i]);
76 }
77 }
78
79 // 4. Check PRI constraints
80 if (isPulsed)
81 {
82 for (const auto& period : merged)
83 {
84 if (period.end - period.start < pri)
85 {
86 LOG(logging::Level::WARNING, "Object '{}' has a schedule period [{}, {}] shorter than PRI ({}s).",
87 ownerName, period.start, period.end, pri);
88 }
89 }
90 }
91
92 return merged;
93 }
94
95} // namespace radar
double RealType
Type for real numbers.
Definition config.h:27
Header file for the logging system.
#define LOG(level,...)
Definition logging.h:19
@ WARNING
Warning level for potentially harmful situations.
RealType endTime() noexcept
Get the end time for the simulation.
Definition parameters.h:97
RealType startTime() noexcept
Get the start time for the simulation.
Definition parameters.h:91
std::vector< SchedulePeriod > processRawSchedule(std::vector< SchedulePeriod > periods, const std::string &ownerName, const bool isPulsed, const RealType pri)
Processes a raw list of schedule periods.
Defines the Parameters struct and provides methods for managing simulation parameters.