FERS 0.1.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(const std::vector<SchedulePeriod>& periods,
18 const std::string& ownerName, const bool isPulsed,
19 const RealType pri)
20 {
21 if (periods.empty())
22 {
23 return {};
24 }
25
26 std::vector<SchedulePeriod> valid_periods;
27 valid_periods.reserve(periods.size());
28
31
32 // 1. Filter invalid and out-of-bounds periods
33 for (const auto& p : periods)
34 {
35 if (p.start >= p.end)
36 {
38 "Object '{}' has a schedule period with start ({}) >= end ({}). Ignoring period.", ownerName,
39 p.start, p.end);
40 continue;
41 }
42
43 if (p.end <= sim_start || p.start >= sim_end)
44 {
46 "Object '{}' has a schedule period [{}, {}] completely outside simulation time. Ignoring.",
47 ownerName, p.start, p.end);
48 continue;
49 }
50 valid_periods.push_back(p);
51 }
52
53 if (valid_periods.empty())
54 {
55 return {};
56 }
57
58 // 2. Sort by start time
59 std::ranges::sort(valid_periods, [](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:109
RealType startTime() noexcept
Get the start time for the simulation.
Definition parameters.h:103
std::vector< SchedulePeriod > processRawSchedule(const 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.
math::Vec3 max
RealType b
RealType a