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::ranges::sort(valid_periods, [](const auto& a, const auto& b) { return a.start < b.start; });
59
60 // 3. Merge overlapping intervals
61 std::vector<SchedulePeriod> merged;
62 merged.reserve(valid_periods.size());
63 merged.push_back(valid_periods.front());
64
65 for (size_t i = 1; i < valid_periods.size(); ++i)
66 {
67 if (valid_periods[i].start <= merged.back().end)
68 {
69 // Overlap or adjacency: extend the previous period
70 merged.back().end = std::max(merged.back().end, valid_periods[i].end);
71 }
72 else
73 {
74 merged.push_back(valid_periods[i]);
75 }
76 }
77
78 // 4. Check PRI constraints
79 if (isPulsed)
80 {
81 for (const auto& period : merged)
82 {
83 if (period.end - period.start < pri)
84 {
85 LOG(logging::Level::WARNING, "Object '{}' has a schedule period [{}, {}] shorter than PRI ({}s).",
86 ownerName, period.start, period.end, pri);
87 }
88 }
89 }
90
91 return merged;
92 }
93
94} // 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:109
RealType startTime() noexcept
Get the start time for the simulation.
Definition parameters.h:103
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.