WSF
WsfCoverage.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2020 Infoscitex, a DCS Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFCOVERAGECOVERAGE_HPP
13#define WSFCOVERAGECOVERAGE_HPP
14
15#include <map>
16#include <set>
17#include <string>
18#include <utility>
19#include <vector>
20
21#include "UtCalendar.hpp"
22#include "UtCallback.hpp"
23#include "UtCloneablePtr.hpp"
25#include "WsfCoverageAsset.hpp"
30#include "WsfObject.hpp"
31#include "WsfScenario.hpp"
32class WsfSimulation;
33
34#include "wsf_coverage_export.h"
35
36namespace wsf
37{
38namespace coverage
39{
40
41class Grid;
42
56class WSF_COVERAGE_EXPORT Coverage : public WsfObject
57{
58public:
59 explicit Coverage(const WsfScenario& aScenario)
60 : mScenario(aScenario)
61 {
62 mStartEpoch.SetDate(1900, 1, 1);
63 mEndEpoch.SetDate(1900, 1, 1);
64 }
65 Coverage(const Coverage& aOther) = default;
66 ~Coverage() override = default;
67
68 // WsfObject overrides
69 Coverage* Clone() const override = 0;
70 bool ProcessInput(UtInput& aInput) override;
71
72 // Main coverage methods
73 bool Initialize(WsfSimulation& aSimulation);
74 bool ResolveAssets(WsfSimulation& aSimulation);
75 void CategorizePlatforms(const WsfSimulation& aSimulation);
76 void PendingStart(WsfSimulation& aSimulation);
77 void Finalize(double aSimTime, const UtCalendar& aSimStartEpoch);
78
79 // The observable event signatures
80 using AccessIntervalStartCallback = UtCallbackListN<void(const GridAsset&, const FreeAsset&, double)>;
81 using AccessIntervalEndCallback = UtCallbackListN<void(const GridAsset&, const FreeAsset&, double)>;
82 using AccessIntervalCompleteCallback = UtCallbackListN<void(const GridAsset&, const FreeAsset&, const AccessInterval&)>;
83
91
95 AccessIntervalEndCallback& AccessIntervalEnd() { return mIntervalEnd; }
96
103
111 const Grid* GetGrid() const { return mGridPtr; }
112
117 const std::string& GetOutputDir() const { return mOutputDir; }
118
120 bool InCoverageInterval(double aSimTime) const { return mCoverageInterval.Contains(aSimTime); }
121
123 double GetStartTime() const { return mCoverageInterval.GetStart(); }
124
126 double GetEndTime() const { return mCoverageInterval.GetEnd(); }
127
129 const UtCalendar& GetStartEpoch() const { return mStartEpoch; }
130
132 bool IsStartEpochDefined() const { return mStartEpoch.GetYear() > 1900; }
133
135 const UtCalendar& GetEndEpoch() const { return mEndEpoch; }
136
138 bool IsEndEpochDefined() const { return mEndEpoch.GetYear() > 1900; }
139
141 bool IsAsset(const WsfPlatform* aPlatformPtr) const
142 {
143 return IsFreeAsset(aPlatformPtr) || IsGridAsset(aPlatformPtr);
144 }
145
147 bool IsFreeAsset(const WsfPlatform* aPlatformPtr) const
148 {
149 return aPlatformPtr && aPlatformPtr->IsCategoryMember(mFreeAssetCategory);
150 }
151
153 bool IsGridAsset(const WsfPlatform* aPlatformPtr) const
154 {
155 return aPlatformPtr && aPlatformPtr->IsCategoryMember(mGridAssetCategory);
156 }
157
159 bool IsPlatformOfType(const std::string& aPlatformName, const std::string& aPlatformType) const;
160
163 bool IsPlatformDeviceOfType(const std::string& aPlatformName,
164 const std::string& aDeviceName,
165 const std::string& aDeviceType) const;
166
167protected:
174 void SetGrid(const Grid* aGridPtr) { mGridPtr = aGridPtr; }
175
176 void AddIntervalStartToData(const GridAsset& aGridAsset, const FreeAsset& aFreeAsset, double aSimTime);
177 void AddIntervalEndToData(const GridAsset& aGridAsset, const FreeAsset& aFreeAsset, double aSimTime);
178
180 const std::string& GetGridAssetCategory() const { return mGridAssetCategory; }
181
183 const std::string& GetFreeAssetCategory() const { return mFreeAssetCategory; }
184
186 std::set<FreeAsset> mFreeAssets{};
187
190 UtCallbackHolder mCallbacks{};
191
192private:
202 virtual bool InitializeP(WsfSimulation& aSimulation) = 0;
203
219 virtual bool AreNullDevicesAllowed(bool aGridAssetNull,
220 bool aAllGridAssetsNull,
221 bool aFreeAssetNull,
222 bool aAllFreeAssetsNull) const = 0;
223
233 virtual bool VerifyDeviceP(const WsfPlatform& aPlatform, const std::string& aDeviceName) const = 0;
234
246 virtual bool VerifyDeviceAndType(const WsfPlatform& aPlatform,
247 const std::string& aDeviceName,
248 const std::string& aDeviceType) const = 0;
249
257 virtual void PendingStartP(WsfSimulation& aSimulation) = 0;
258
259 bool FindGrid(const WsfSimulation& aSimulation);
260 bool NullDeviceCheck();
261 bool InitializeCoverageInterval(const WsfSimulation& aSimulation);
262 bool InitializeMeasures();
263 bool AssureFilterFileUniqueness() const;
264 bool VerifyDevice(const WsfPlatform& aPlatform, const std::string& aDeviceName) const;
265 bool ResolvePlatformFreeAsset(const WsfSimulation& aSimulation, const AssetSpecification::Asset& aAsset);
266 bool ResolvePlatformTypeFreeAsset(const WsfSimulation& aSimulation, const AssetSpecification::Asset& aAsset);
267 bool ResolveCategoryFreeAssets(const WsfSimulation& aSimulation, const AssetSpecification::Asset& aAsset);
268 bool ResolveGroupFreeAssets(const WsfSimulation& aSimulation, const AssetSpecification::Asset& aAsset);
269 void StartInterval(double aSimTime);
270 void CloseAllOpenIntervals(double aSimTime);
271 void ProcessInterval(const GridAsset& aGridAsset, const FreeAsset& aFreeAsset, const AccessInterval& aInterval);
272 void CategorizeAssets(const WsfSimulation& aSimulation);
273 void WriteOverlayData() const;
274
275 // Needed to get at the Measure types
276 const WsfScenario& mScenario;
277 const WsfSimulation* mSimulationPtr{nullptr};
278
279 // Some basic data
280 std::string mGridName{};
281 AssetSpecification mAssetSpecification{};
282 std::map<std::string, ut::CloneablePtr<Measure>> mMeasures{};
283
284 // Coverage interval - saved as calendar objects, or sim times
285 UtCalendar mStartEpoch{};
286 UtCalendar mEndEpoch{};
287 AccessInterval mCoverageInterval{};
288
289 // Output related options
290 std::string mOutputDir{};
291 ut::CloneablePtr<RawDataOutput> mRawData{nullptr};
292 std::string mOverlayOutputFileName{};
293
294 // reference to the grid
295 const Grid* mGridPtr{nullptr};
296 std::string mGridAssetCategory{};
297 std::string mFreeAssetCategory{};
298
299 // Interval events to which Measures can subscribe
300 AccessIntervalStartCallback mIntervalStart{};
301 AccessIntervalEndCallback mIntervalEnd{};
302 AccessIntervalCompleteCallback mIntervalComplete{};
303
304 // The intervals as they are built.
305 std::map<GridAsset, std::map<FreeAsset, AccessInterval>> mData{};
306
307 // Constraints
308 std::vector<IntervalConstraint> mConstraints{};
309
310 bool mFinalized{false};
311};
312
313} // namespace coverage
314} // namespace wsf
315
316#endif // WSFCOVERAGECOVERAGE_HPP
WsfObject()
This is the constructor for the WsfObject class.
Definition WsfObject.cpp:88
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
bool IsCategoryMember(WsfStringId aCategoryId) const
Definition WsfPlatform.cpp:1474
Contains the data required to create a simulation, and acts as the entry point for input file process...
Definition WsfScenario.hpp:111
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Definition WsfCoverageAccessInterval.hpp:28
bool IsGridAsset(const WsfPlatform *aPlatformPtr) const
Return if the given aPlatformPtr is a grid asset for this coverage.
Definition WsfCoverage.hpp:153
bool IsAsset(const WsfPlatform *aPlatformPtr) const
Return if the given aPlatformPtr is either a grid or free asset for this coverage.
Definition WsfCoverage.hpp:141
bool IsEndEpochDefined() const
Has the end epoch been given a value?
Definition WsfCoverage.hpp:138
AccessIntervalCompleteCallback & AccessIntervalComplete()
Definition WsfCoverage.hpp:102
void Finalize(double aSimTime, const UtCalendar &aSimStartEpoch)
Definition WsfCoverage.cpp:254
Coverage(const Coverage &aOther)=default
AccessIntervalEndCallback & AccessIntervalEnd()
Definition WsfCoverage.hpp:95
const std::string & GetFreeAssetCategory() const
Return the category assigned to free asset platform for this coverage.
Definition WsfCoverage.hpp:183
UtCallbackHolder mCallbacks
Definition WsfCoverage.hpp:190
bool IsFreeAsset(const WsfPlatform *aPlatformPtr) const
Return if the given aPlatformPtr is a free asset for this coverage.
Definition WsfCoverage.hpp:147
bool IsStartEpochDefined() const
Has the start epoch been given a value?
Definition WsfCoverage.hpp:132
bool InCoverageInterval(double aSimTime) const
Does the given simulation time fall inside this object's coverage interval?
Definition WsfCoverage.hpp:120
void PendingStart(WsfSimulation &aSimulation)
Definition WsfCoverage.cpp:209
Coverage * Clone() const override=0
bool ResolveAssets(WsfSimulation &aSimulation)
Definition WsfCoverage.cpp:162
double GetEndTime() const
Return the simulation time of the end of the coverage interval.
Definition WsfCoverage.hpp:126
std::set< FreeAsset > mFreeAssets
Free assets for this coverage.
Definition WsfCoverage.hpp:186
UtCallbackListN< void(const GridAsset &, const FreeAsset &, double)> AccessIntervalEndCallback
Definition WsfCoverage.hpp:81
const std::string & GetOutputDir() const
Definition WsfCoverage.hpp:117
double GetStartTime() const
Return the simulation time of the start of the coverage interval.
Definition WsfCoverage.hpp:123
bool ProcessInput(UtInput &aInput) override
Definition WsfCoverage.cpp:37
const Grid * GetGrid() const
Definition WsfCoverage.hpp:111
const std::string & GetGridAssetCategory() const
Return the category assigned to grid asset platforms for this coverage.
Definition WsfCoverage.hpp:180
Coverage(const WsfScenario &aScenario)
Definition WsfCoverage.hpp:59
~Coverage() override=default
UtCallbackListN< void(const GridAsset &, const FreeAsset &, const AccessInterval &)> AccessIntervalCompleteCallback
Definition WsfCoverage.hpp:82
void SetGrid(const Grid *aGridPtr)
Definition WsfCoverage.hpp:174
const UtCalendar & GetStartEpoch() const
Return the date and time of the start of the coverage interval.
Definition WsfCoverage.hpp:129
UtCallbackListN< void(const GridAsset &, const FreeAsset &, double)> AccessIntervalStartCallback
Definition WsfCoverage.hpp:80
bool Initialize(WsfSimulation &aSimulation)
Definition WsfCoverage.cpp:133
AccessIntervalStartCallback & AccessIntervalStart()
Definition WsfCoverage.hpp:90
void CategorizePlatforms(const WsfSimulation &aSimulation)
Definition WsfCoverage.cpp:203
const UtCalendar & GetEndEpoch() const
Return the date and time of the end of the coverage interval.
Definition WsfCoverage.hpp:135
Definition WsfCoverageAsset.hpp:81
Definition WsfCoverageAsset.hpp:37
The Grid object defines the region over which coverage can be computed.
Definition WsfCoverageGrid.hpp:38
Definition WsfCoverage.cpp:35
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
A record read in from the input file.
Definition WsfCoverageAssetSpecification.hpp:53
Copyrights Multiple, All Rights Reserved