WSF
WsfQuantumTaskerProcessor.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 2003-2015 The Boeing 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 WSFQUANTUMTASKERPROCESSOR_HPP
13#define WSFQUANTUMTASKERPROCESSOR_HPP
14
15#include <map>
16#include <string>
17#include <vector>
18
20#include "wsf_mil_export.h"
22class WsfPlatform;
23class WsfProcessor;
27#include "WsfQuantumMatrix.hpp"
28class WsfQuantumTask;
31#include "WsfTaskManager.hpp"
33
54class WSF_MIL_EXPORT WsfQuantumTaskerProcessor : public WsfTaskManager, public WsfQuantumMatrix
55{
56public:
63
65 {
66 cSTATIC, // never reallocate any tasks
67 cDYNAMIC, // reallocate any time - whenever max profit suggests it
68 cRESPONSE, // only reallocate tasks that were rejected/canceled by assets
69 cEVENT // check for reallocation when a new task appears or an asset drops off (change event)
70 };
71
72 using AllocationMap = std::map<int, std::set<WsfAssetPerception*>>;
73
75 WsfQuantumTaskerProcessor(WsfScenario& aScenario, const std::string& aPartClass, const std::string& aPartName);
79
81
82 WsfProcessor* Clone() const override;
83 bool PreInitialize(double aSimTime) override;
84 bool Initialize(double aSimTime) override;
85 bool Initialize2(double aSimTime) override;
87
88 bool ProcessInput(UtInput& aInput) override;
89 void Update(double aSimTime) override;
90 bool ProcessMessage(double aSimTime, const WsfMessage& aMessage) override;
91 bool ReceiveMessage(double aSimTime, const WsfMessage& aMessage) override;
92 void PlatformDeleted(WsfPlatform* aPlatformPtr) override;
93
94 const char* GetScriptClassName() const override;
98
100
101
104 bool ProcessTaskAssignMessage(double aSimTime, const WsfTaskAssignMessage& aMessage) override;
105 bool ProcessTaskStatusMessage(double aSimTime, const WsfTaskStatusMessage& aMessage) override;
107
109
110
113 virtual bool AssignTask(double aSimTime, const WsfTask& aTask);
119 bool AssignTask(double aSimTime, const WsfTrack& aTrack, const WsfTask& aTask, bool aLockTrack = true) override;
121
123
124
128 void PurgeReceivedTask(double aSimTime, WsfTask& aTask) override;
129 void PurgeTransmittedTask(double aSimTime, WsfTask& aTask) override;
130 void UpdateTaskCorrelation(double aSimTime, WsfTask& aTask) override;
132
134
135
137 virtual void SetAssetRepresentation(AssetRepresentationType aType) { mAssetRep = aType; }
139 virtual void SetReallocationStrategy(ReallocationStrategyType aType) { mReallocateStrategy = aType; }
141 virtual void SetIgnoreAllyTracks(bool aVal) { mIgnoreAllyTracks = aVal; }
143
144 WsfQuantumGenerator* Generator() const { return mGeneratorPtr.get(); }
145 WsfQuantumEvaluator* Evaluator() const { return mEvaluatorPtr.get(); }
146
148
149
150 std::list<WsfTask*> TaskListReceivedOfType(WsfStringId aTaskType);
151 std::list<WsfTask*> TaskListReceivedForTrack(const WsfTrackId& aTrackId);
152 std::list<WsfTask*> TaskListReceivedOfTypeForTrack(WsfStringId aTaskType, const WsfTrackId& aTrackId);
153 std::list<WsfTask*> TaskListReceivedForResourceType(int aResourceType);
154 std::list<WsfTask*> TaskListReceivedForResourceName(WsfStringId aResourceName);
155
156 std::list<WsfTask*> TaskListAssignedOfType(WsfStringId aTaskType);
157 std::list<WsfTask*> TaskListAssignedForTrack(const WsfTrackId& aTrackId);
158 std::list<WsfTask*> TaskListAssignedForResourceType(int aResourceType);
159 std::list<WsfTask*> TaskListAssignedForResourceName(WsfStringId aResourceName);
161
163
164
165 std::set<size_t> AssigneesForTask(WsfQuantumTask* aTaskPtr);
166
167 using WsfTaskManager::AssigneesForTask; // don't hide this
168
170 std::set<WsfAssetPerception*> AssetAssigneesForTask(WsfQuantumTask* aTaskPtr);
172
174
175
180 bool ReportTaskProgress(double aSimTime, WsfTask& aTask, WsfStringId aSubStatus);
181 bool ReportTaskComplete(double aSimTime, WsfTask& aTask, WsfStringId aSubStatus);
182 bool RejectTask(double aSimTime, WsfTask& aTask);
184 void TaskCompleted(double aSimTime, WsfTask& aTask) override;
186
191 void UpdateEvaluations(double aSimTime, WsfQuantumEvaluator& aEvaluator, std::vector<WsfLocalTrack*>& aPerception) override;
192
193 // Disambiguate
195
196protected:
199
200 bool AcquireResource(double aSimTime, WsfTask& aTask, const WsfTrack& aTrack) override;
201 bool ReleaseResource(double aSimTime, WsfTask& aTask) override;
202
204 bool Rejected(WsfAssetPerception* aAssetPtr, WsfQuantumTask* aTaskPtr);
206 bool RejectedAnyTasks(WsfAssetPerception* aAssetPtr);
208 bool RejectedByAnyAsset(WsfQuantumTask* aTaskPtr);
210 bool CompletedAfter(WsfQuantumTask* aTaskPtr, double aSimTime);
211
212 void SetMatrixAssets(double aSimTime);
213 void SetMatrixTasks(double aSimTime, std::map<int, std::set<size_t>>& aAllocationMap);
214 void SetAllocations(AllocationList& aList);
215 void AllocateExtraTasks(AllocationList& aList);
216 void AllocateExtraAssets(AllocationList& aList);
217
218private:
219 TaskList::iterator FindTask(TaskList& aTaskList, WsfTask& aTask);
221
222 AssetRepresentationType mAssetRep;
223 ReallocationStrategyType mReallocateStrategy;
224 bool mIgnoreAllyTracks;
225 int mAssetsId;
226 int mTasksId;
227 int mPrevRejectCount;
228
229 WsfPerceptionProcessor* mPerceptionProcessorPtr;
230 ut::CloneablePtr<WsfQuantumGenerator> mGeneratorPtr;
231 ut::CloneablePtr<WsfQuantumEvaluator> mEvaluatorPtr;
232 ut::CloneablePtr<WsfQuantumAllocator> mAllocatorExtraTasksPtr;
233 ut::CloneablePtr<WsfQuantumAllocator> mAllocatorExtraAssetsPtr;
234
235 std::vector<ut::CloneablePtr<WsfQuantumAllocator>> mAllocators;
236
237 std::map<size_t, std::map<int, int>> mRejectedTaskMap; // map from asset id to vector of rejected task ids
238 std::map<int, int> mRejectedTasks; // map from task id to 1
239
240 std::map<int, double> mCompletedTaskTimes; // map from task id to time reported complete (ignore if task creation
241 // impetus is more up to date???)
242
243 AllocationMap mAllocationMap;
244
245 bool mFilterAssignedTasks;
246 bool mFilterRejectedTasks;
247 bool mFilterCompletedTasks;
248 bool mUpdateAssignments;
249};
250
251#endif
std::vector< std::pair< WsfAssetPerception *, ut::CloneablePtr< WsfQuantumTask > > > AllocationList
Definition WsfQuantumAllocator.hpp:32
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
Definition WsfAssetPerception.hpp:32
A base class for messages sent among simulation communication objects, processors and sensors.
Definition WsfMessage.hpp:33
const std::string & GetName() const
Definition WsfObject.cpp:235
Definition WsfPerceptionProcessor.hpp:38
WsfSimulation * GetSimulation() const
Definition WsfPlatformPart.cpp:689
WsfPlatform * GetPlatform() const
Definition WsfPlatformPart.hpp:107
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
Definition WsfProcessor.hpp:39
WsfProcessor(const WsfScenario &aScenario)
Definition WsfProcessor.cpp:25
Definition WsfQuantumAllocator.hpp:36
Definition WsfQuantumEvaluator.hpp:31
Definition WsfQuantumGenerator.hpp:33
WsfQuantumMatrix()=default
virtual void UpdateEvaluations(double aSimTime, WsfQuantumEvaluator &aEvaluator, std::vector< WsfLocalTrack * > &aPerception)
Definition WsfQuantumMatrix.cpp:122
Definition WsfQuantumTask.hpp:85
WsfQuantumTaskerProcessor(WsfScenario &aScenario)
Definition WsfQuantumTaskerProcessor.cpp:40
WsfQuantumGenerator * Generator() const
Definition WsfQuantumTaskerProcessor.hpp:144
virtual void SetReallocationStrategy(ReallocationStrategyType aType)
See comments for ReallocationStrategyType enum.
Definition WsfQuantumTaskerProcessor.hpp:139
WsfQuantumTaskerProcessor & operator=(const WsfQuantumTaskerProcessor &)=delete
void PurgeTransmittedTask(double aSimTime, WsfTask &aTask) override
Definition WsfQuantumTaskerProcessor.cpp:895
ReallocationStrategyType
Definition WsfQuantumTaskerProcessor.hpp:65
@ cRESPONSE
Definition WsfQuantumTaskerProcessor.hpp:68
@ cEVENT
Definition WsfQuantumTaskerProcessor.hpp:69
@ cDYNAMIC
Definition WsfQuantumTaskerProcessor.hpp:67
@ cSTATIC
Definition WsfQuantumTaskerProcessor.hpp:66
AssetRepresentationType
Definition WsfQuantumTaskerProcessor.hpp:58
@ cRESOURCES
Definition WsfQuantumTaskerProcessor.hpp:61
@ cPLATFORM
Definition WsfQuantumTaskerProcessor.hpp:59
@ cSYSTEMS
Definition WsfQuantumTaskerProcessor.hpp:60
std::map< int, std::set< WsfAssetPerception * > > AllocationMap
Definition WsfQuantumTaskerProcessor.hpp:72
void PurgeReceivedTask(double aSimTime, WsfTask &aTask) override
Definition WsfQuantumTaskerProcessor.cpp:847
virtual void SetAssetRepresentation(AssetRepresentationType aType)
Definition WsfQuantumTaskerProcessor.hpp:137
WsfQuantumEvaluator * Evaluator() const
Definition WsfQuantumTaskerProcessor.hpp:145
void UpdateTaskCorrelation(double aSimTime, WsfTask &aTask) override
Update the task track/local track correlation in a received task.
Definition WsfQuantumTaskerProcessor.cpp:901
virtual void SetIgnoreAllyTracks(bool aVal)
Sets whether or not ally tracks are passed to the generator (and subsequently tasks on those tracks w...
Definition WsfQuantumTaskerProcessor.hpp:141
Contains the data required to create a simulation, and acts as the entry point for input file process...
Definition WsfScenario.hpp:111
Definition WsfScriptContext.hpp:71
bool Initialize2(double aSimTime) override
Definition WsfScriptProcessor.cpp:142
Definition WsfTaskAssignMessage.hpp:45
void AssigneesForTask(const WsfTrackId &aTrackId, WsfStringId aTaskType, std::vector< size_t > &aAssignees) const
Definition WsfTaskManager.cpp:1417
bool ReceiveMessage(double aSimTime, const WsfMessage &aMessage) override
Definition WsfTaskManager.cpp:519
bool ProcessMessage(double aSimTime, const WsfMessage &aMessage) override
Definition WsfTaskManager.cpp:480
void PlatformDeleted(WsfPlatform *aPlatformPtr) override
Definition WsfTaskManager.cpp:440
virtual bool ProcessTaskAssignMessage(double aSimTime, const WsfTaskAssignMessage &aMessage)
Definition WsfTaskManager.cpp:2021
virtual bool AcquireResource(double aSimTime, WsfTask &aTask, const WsfTrack &aTrack)
Definition WsfTaskManager.cpp:792
virtual bool ReleaseResource(double aSimTime, WsfTask &aTask)
Definition WsfTaskManager.cpp:873
virtual bool ProcessTaskStatusMessage(double aSimTime, const WsfTaskStatusMessage &aMessage)
Definition WsfTaskManager.cpp:2263
const char * GetScriptClassName() const override
Definition WsfTaskManager.cpp:244
WsfProcessor * Clone() const override
A virtual copy constructor.
Definition WsfTaskManager.cpp:252
bool Initialize(double aSimTime) override
Definition WsfTaskManager.cpp:285
bool ProcessInput(UtInput &aInput) override
Definition WsfTaskManager.cpp:362
bool Initialize2(double aSimTime) override
Definition WsfTaskManager.cpp:296
virtual void TaskCompleted(double aSimTime, WsfTask &aTask)
Definition WsfTaskManager.cpp:974
void Update(double aSimTime) override
Definition WsfTaskManager.cpp:639
static TaskList::iterator FindTask(TaskList &aTaskList, size_t aAssigneeIndex, const WsfTrackId &aTrackId, WsfStringId aTaskType, WsfStringId aResourceName)
Definition WsfTaskManager.cpp:1577
virtual bool ReportTaskProgress(double aSimTime, const WsfTrackId &aTrackId, WsfStringId aTaskType, WsfStringId aResourceName, WsfStringId aSubStatus)
Definition WsfTaskManager.cpp:1363
WsfTaskManager(WsfScenario &aScenario, const std::string &aClassName="WsfTaskManager")
Constructor.
Definition WsfTaskManager.cpp:146
bool PreInitialize(double aSimTime) override
Definition WsfTaskManager.cpp:277
virtual bool ReportTaskComplete(double aSimTime, const WsfTrackId &aTrackId, WsfStringId aTaskType, WsfStringId aResourceName, WsfStringId aSubStatus)
Definition WsfTaskManager.cpp:1283
virtual bool AssignTask(double aSimTime, const WsfTrack &aTrack, const WsfTask &aTask, bool aLockTrack=true)
Definition WsfTaskManager.cpp:655
Definition WsfTaskStatusMessage.hpp:42
A class that defines a task to be performed.
Definition WsfTask.hpp:28
Definition WsfTrackId.hpp:33
An object that represents an 'track' (perception) of something.
Definition WsfTrack.hpp:120
Copyrights Multiple, All Rights Reserved