WSF
WsfRIPRJobBoard.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// Updated by Infoscitex, a DCS Company.
13// ****************************************************************************
14
15//***************************************************************************
16//* FILE NAME:
17//* WsfRIPRJobBoard.hpp
18//*
19//* PURPOSE:
20//* The WsfRIPRJobBoard class accepts jobs from a WsfRIPRProcessor and makes
21//* them available for browsing and claiming by subordinates.
22//*
23//* NOTES:
24//* None
25//***************************************************************************
26
27#ifndef WSFRIPRJOBBOARD_HPP
28#define WSFRIPRJOBBOARD_HPP
29
30#include <set>
31
32#include "WsfObject.hpp"
33#include "WsfRIPRCommon.hpp"
35class WsfRIPRJob;
36class WsfRIPRJobBoard;
37class WsfRIPRManager;
38class WsfSimulation;
39
40// WsfRIPRJobBoard holds a vector of jobs for its owner that its subordinates
41// can browse, claim, and perform.
42
44{
45public:
47 // WsfRIPRJobBoard(const WsfRIPRProcessor* aOwner);
48 WsfRIPRJobBoard(const WsfRIPRProcessor* aOwnerPtr,
49 bool aAutoExclusiveMode = false,
50 double aJobWindowOpenLength = 0,
51 double aBidWindowOpenLength = 0,
52 bool aJobWindowOpen = true,
53 bool aBidWindowOpen = true);
56 WsfRIPRJobBoard* Clone() const override { return new WsfRIPRJobBoard(*this); }
57 ~WsfRIPRJobBoard() override;
58
60 bool DebugEnabled() const;
61
62 // Add aJobPtr to the job board
63 void AddJob(WsfRIPRJob* aJobPtr);
64
65 // Remove aJobPtr from the job board //and notify the takers if any
66 void RemoveJob(WsfRIPRJob* aJobPtr);
67 void RemoveAllJobs();
68
69 // Delete jobs with at least one taker with progress == 1
70 int DeleteCompletedJobs(double aSimTime);
71
72 // Delete jobs with at least one taker with progress == 1 using current sim time.
74
75 // Delete jobs that haven't been touched in mPurgeTouchTime or aStaleTime seconds
77 int PurgeUntouchedJobs(double aStaleTime);
78
79 // perform callbacks of any completed jobs
81
82 // Purge dead bidders from jobs
83 int PurgeDeadBidders(double aSimTime);
84
85 void SetOwner(const WsfRIPRProcessor* aOwnerPtr) { mOwnerPtr = aOwnerPtr; }
86 const WsfRIPRProcessor* GetOwner() { return mOwnerPtr; }
87
88 std::list<WsfRIPRJob*> GetJobs(); // TODO change to const & instead of *?
89
90 static bool CompareJobPriorities(WsfRIPRJob* firstPtr, WsfRIPRJob* secondPtr);
91
92 void Update(double aSimTime);
93
94 WsfRIPRJob* JobFor(double aSimTime, unsigned int aBidderRIPRProcId);
95
96 WsfRIPRJob* GetJobByData(std::string aDataKey, UtScriptData aDataValue);
97 WsfRIPRJob* GetJobById(int aJobId);
98
101 std::map<unsigned int, WsfRIPRJob*> GetWinnerList(const double aSimTime);
102
106
107 void AllocateJobs(double aSimTime, bool aForceReallocation);
108
110 void AllocateJobs(bool aForceReallocation);
111
112 double NormalizeBid(double);
113
122
124
126
127 void ClearBidsFor(double aSimTime, unsigned int aBidderRIPRProcId);
128
129 void UpdateWindows(double aSimTime);
130
131 void SetAutoExclusiveMode(bool aAutoExclusiveMode) { mAutoExclusiveMode = aAutoExclusiveMode; };
132 void SetJobWindowOpenLength(double aJobWindowOpenLength) { mJobWindowOpenLength = aJobWindowOpenLength; };
133 void SetBidWindowOpenLength(double aBidWindowOpenLength) { mBidWindowOpenLength = aBidWindowOpenLength; };
134
135 bool IsJobWindowOpen(double aSimTime);
136 bool IsBidWindowOpen(double aSimTime);
137
138 void SetJobWindowOpen(bool aOpen);
139 void SetBidWindowOpen(bool aOpen);
140
141 void SetJobStickiness(double aStickiness) { mJobStickiness = aStickiness; };
142
143 void SetOwner(WsfRIPRProcessor* aOwnerPtr) { mOwnerPtr = aOwnerPtr; };
144
145 void SetDirtyJobs() { mDirtyJobs = true; };
146 void UpdateMinMaxBids(double aBid);
147
148 void SetPurgeTouchTime(double aPurgeTime) { mPurgeTouchTime = aPurgeTime; };
149 double PurgeTouchTime() { return mPurgeTouchTime; };
150
151 // managing job dependencies
152 static std::map<int, std::set<int>> DependenciesAll() { return mDependencies; }
153 static std::set<int>& DependenciesForJob(int aJobId) { return mDependencies[aJobId]; }
154 static void DependencyAdd(int aDependentJobId, int aDependedOnJobId)
155 {
156 mDependencies[aDependentJobId].insert(aDependedOnJobId);
157 }
158 static void DependencyRemove(int aDependentJobId, int aDependedOnJobId)
159 {
160 mDependencies[aDependentJobId].erase(aDependedOnJobId);
161 }
162 static bool DependencyCheck(int aDependentJobId, int aDependedOnJobId)
163 {
164 return (mDependencies[aDependentJobId].find(aDependedOnJobId) == mDependencies[aDependentJobId].end() ? false : true);
165 }
166 static int DependencyCount(int aDependentJobId) { return static_cast<int>(mDependencies[aDependentJobId].size()); }
167 static void DependencyClearAll() { mDependencies.clear(); }
168
170 WsfRIPRManager* GetManager() const;
171
172protected:
174
175 std::list<WsfRIPRJob*> mJobs;
177 std::map<unsigned int, WsfRIPRJob*> mJobWinners; // key = proc id, value = job pointer
183
184 std::map<unsigned int, double> AllocateJobsCover(double aSimTime, bool aStrictPriority = false);
185 void AllocateJobsGreedy(double aSimTime);
186 void AllocateJobsCoverThenGreedy(double aSimTime);
187 void AllocateJobsCoverThenSpread(double aSimTime);
188
190 void SetJobWon(const unsigned int aBidder, WsfRIPRJob* aJobPtr);
191
192 bool BlockJobsWithoutMinWinners(std::list<WsfRIPRJob*>& aJobs,
193 std::map<WsfRIPRJob*, int>& aCurWinners,
194 std::set<int>& aBlockedJobs,
195 std::map<unsigned int, WsfRIPRJob*>& aJobWinners,
196 std::map<unsigned int, double>& aProcProfit);
197
198 bool BlockJobsWithFailedDependencies(std::list<WsfRIPRJob*>& aJobs,
199 std::map<WsfRIPRJob*, int>& aCurWinners,
200 std::set<int>& aBlockedJobs,
201 std::map<unsigned int, WsfRIPRJob*>& aJobWinners,
202 std::map<unsigned int, double>& aProcProfit);
203
204 bool DependencyTest(WsfRIPRJob* aJobPtr,
205 std::map<WsfRIPRJob*, int>& aCurWinners, // current number of winners for each job
206 std::set<int>& aBlockedJobs, // set of jobs that are currently blocked
207 std::set<int>& aKnownGood, // set of jobs that are known to have ok dependencies
208 std::set<int>& aVisitedJobs); // set of jobs that have already been visited
209
210private:
211 std::map<unsigned int, double>
212 AllocateJobsCover(double aSimTime, double aOldJobBonus, int aExtraSlots, bool aStrictPriority = false);
213
214 bool mJobWindowOpen;
215 bool mBidWindowOpen;
216
217 // never SET these, always use SetXWindowOpen()
218 // reading ok!
219 double mJobWindowOpenLength;
220 double mBidWindowOpenLength;
221 double mJobStickiness;
222 bool mDirtyJobs;
223 double mPurgeTouchTime;
224
225 static std::map<int, std::set<int>> mDependencies;
226};
227
228#endif
WsfComponentListT< T >::Iterator end(const WsfComponentListT< T > &aList)
Definition WsfComponentList.hpp:546
ut::script::Data UtScriptData
Definition WsfScriptContext.hpp:47
double simTime
Definition WsfScriptTrackClass.cpp:1880
WsfObject()
This is the constructor for the WsfObject class.
Definition WsfObject.cpp:88
Definition WsfRIPRJobBoard.hpp:44
WsfSimulation * GetSimulation() const
Definition WsfRIPRJobBoard.cpp:1261
void AddJob(WsfRIPRJob *aJobPtr)
Definition WsfRIPRJobBoard.cpp:285
AllocationMode GetAllocationMode()
Definition WsfRIPRJobBoard.hpp:123
bool IsBidWindowOpen(double aSimTime)
Definition WsfRIPRJobBoard.cpp:168
bool IsJobWindowOpen(double aSimTime)
Definition WsfRIPRJobBoard.cpp:162
int PurgeUntouchedJobs()
Definition WsfRIPRJobBoard.cpp:393
void SetJobStickiness(double aStickiness)
Definition WsfRIPRJobBoard.hpp:141
bool DependencyTest(WsfRIPRJob *aJobPtr, std::map< WsfRIPRJob *, int > &aCurWinners, std::set< int > &aBlockedJobs, std::set< int > &aKnownGood, std::set< int > &aVisitedJobs)
Definition WsfRIPRJobBoard.cpp:1160
double mHighestBid
Definition WsfRIPRJobBoard.hpp:180
static int DependencyCount(int aDependentJobId)
Definition WsfRIPRJobBoard.hpp:166
double NormalizeBid(double)
Definition WsfRIPRJobBoard.cpp:1026
static void DependencyClearAll()
Definition WsfRIPRJobBoard.hpp:167
void SetOwner(const WsfRIPRProcessor *aOwnerPtr)
Definition WsfRIPRJobBoard.hpp:85
void CompletedJobsCallbacks(double simTime)
Definition WsfRIPRJobBoard.cpp:337
AllocationMode mAllocationMode
Definition WsfRIPRJobBoard.hpp:179
WsfRIPRJobBoard & operator=(const WsfRIPRJobBoard &)=delete
void AllocateJobsCoverThenSpread(double aSimTime)
Definition WsfRIPRJobBoard.cpp:891
WsfRIPRJobBoard * Clone() const override
Definition WsfRIPRJobBoard.hpp:56
void SetBidWindowOpenLength(double aBidWindowOpenLength)
Definition WsfRIPRJobBoard.hpp:133
std::list< WsfRIPRJob * > GetJobs()
Definition WsfRIPRJobBoard.cpp:279
WsfRIPRJob * GetJobByData(std::string aDataKey, UtScriptData aDataValue)
Definition WsfRIPRJobBoard.cpp:996
WsfRIPRJobBoard()
Definition WsfRIPRJobBoard.cpp:52
double PurgeTouchTime()
Definition WsfRIPRJobBoard.hpp:149
std::list< WsfRIPRJob * > mJobs
Definition WsfRIPRJobBoard.hpp:175
const WsfRIPRProcessor * GetOwner()
Definition WsfRIPRJobBoard.hpp:86
void SetPurgeTouchTime(double aPurgeTime)
Definition WsfRIPRJobBoard.hpp:148
bool mJobPrioritiesChanged
Definition WsfRIPRJobBoard.hpp:176
void ClearBidsFor(double aSimTime, unsigned int aBidderRIPRProcId)
Definition WsfRIPRJobBoard.cpp:956
void AllocateJobs(double aSimTime, bool aForceReallocation)
Definition WsfRIPRJobBoard.cpp:455
bool DebugEnabled() const
Returns 'true' if debugging is enabled for this instance.
Definition WsfRIPRJobBoard.cpp:152
std::map< unsigned int, WsfRIPRJob * > mJobWinners
Definition WsfRIPRJobBoard.hpp:177
void SetJobWindowOpenLength(double aJobWindowOpenLength)
Definition WsfRIPRJobBoard.hpp:132
WsfRIPRJob * GetJobById(int aJobId)
Definition WsfRIPRJobBoard.cpp:983
void AllocateJobsGreedy(double aSimTime)
Definition WsfRIPRJobBoard.cpp:705
void UpdateWindows(double aSimTime)
Update job and bid window status if necessary.
Definition WsfRIPRJobBoard.cpp:176
static std::set< int > & DependenciesForJob(int aJobId)
Definition WsfRIPRJobBoard.hpp:153
static bool DependencyCheck(int aDependentJobId, int aDependedOnJobId)
Definition WsfRIPRJobBoard.hpp:162
int mAllocationAttempts
Definition WsfRIPRJobBoard.hpp:178
void Update(double aSimTime)
Purge deleted jobs and bidders and reprioritize jobs if necessary.
Definition WsfRIPRJobBoard.cpp:248
double mLowestBid
Definition WsfRIPRJobBoard.hpp:181
void SetBidWindowOpen(bool aOpen)
Sets mBidWindowOpen to aOpen; should be the ONLY place this value is set.
Definition WsfRIPRJobBoard.cpp:232
static void DependencyRemove(int aDependentJobId, int aDependedOnJobId)
Definition WsfRIPRJobBoard.hpp:158
void RemoveJob(WsfRIPRJob *aJobPtr)
Definition WsfRIPRJobBoard.cpp:300
void SetAllocationMode(AllocationMode aMode)
Definition WsfRIPRJobBoard.hpp:125
bool mAutoExclusiveMode
Definition WsfRIPRJobBoard.hpp:182
ripr::RIPRWinnerMap GetWinnerListAsIds() const
Definition WsfRIPRJobBoard.cpp:1238
AllocationMode
Definition WsfRIPRJobBoard.hpp:115
@ Spread
Definition WsfRIPRJobBoard.hpp:116
@ CoverThenSpread
Definition WsfRIPRJobBoard.hpp:119
@ Greedy
Definition WsfRIPRJobBoard.hpp:117
@ CoverThenGreedy
Definition WsfRIPRJobBoard.hpp:118
@ StrictPriority
Definition WsfRIPRJobBoard.hpp:120
void SetJobWindowOpen(bool aOpen)
Sets mJobWindowOpen to aOpen; should be the ONLY place this value is set.
Definition WsfRIPRJobBoard.cpp:226
const WsfRIPRProcessor * mOwnerPtr
Definition WsfRIPRJobBoard.hpp:173
static void DependencyAdd(int aDependentJobId, int aDependedOnJobId)
Definition WsfRIPRJobBoard.hpp:154
std::map< unsigned int, double > AllocateJobsCover(double aSimTime, bool aStrictPriority=false)
Definition WsfRIPRJobBoard.cpp:519
void SetOwner(WsfRIPRProcessor *aOwnerPtr)
Definition WsfRIPRJobBoard.hpp:143
WsfRIPRManager * GetManager() const
Definition WsfRIPRJobBoard.cpp:1266
void AllocateJobsCoverThenGreedy(double aSimTime)
Definition WsfRIPRJobBoard.cpp:792
bool BlockJobsWithFailedDependencies(std::list< WsfRIPRJob * > &aJobs, std::map< WsfRIPRJob *, int > &aCurWinners, std::set< int > &aBlockedJobs, std::map< unsigned int, WsfRIPRJob * > &aJobWinners, std::map< unsigned int, double > &aProcProfit)
check aJobs and block single highest priority job that has failed or blocked dependencies
Definition WsfRIPRJobBoard.cpp:1106
static bool CompareJobPriorities(WsfRIPRJob *firstPtr, WsfRIPRJob *secondPtr)
Definition WsfRIPRJobBoard.cpp:273
bool BlockJobsWithoutMinWinners(std::list< WsfRIPRJob * > &aJobs, std::map< WsfRIPRJob *, int > &aCurWinners, std::set< int > &aBlockedJobs, std::map< unsigned int, WsfRIPRJob * > &aJobWinners, std::map< unsigned int, double > &aProcProfit)
check aJobs and block single highest priority unblocked job without the min number of winners
Definition WsfRIPRJobBoard.cpp:1053
void SetJobWon(const unsigned int aBidder, WsfRIPRJob *aJobPtr)
SetJobWon registers a job as being won and notifies the observer class.
Definition WsfRIPRJobBoard.cpp:1037
void SetAutoExclusiveMode(bool aAutoExclusiveMode)
Definition WsfRIPRJobBoard.hpp:131
static std::map< int, std::set< int > > DependenciesAll()
Definition WsfRIPRJobBoard.hpp:152
void UpdateMinMaxBids(double aBid)
Definition WsfRIPRJobBoard.cpp:1012
int DeleteCompletedJobs()
Definition WsfRIPRJobBoard.cpp:365
void RemoveAllJobs()
Definition WsfRIPRJobBoard.cpp:316
std::map< unsigned int, WsfRIPRJob * > GetWinnerList(const double aSimTime)
Definition WsfRIPRJobBoard.cpp:1249
void SetDirtyJobs()
Definition WsfRIPRJobBoard.hpp:145
WsfRIPRJob * JobFor(double aSimTime, unsigned int aBidderRIPRProcId)
Definition WsfRIPRJobBoard.cpp:940
~WsfRIPRJobBoard() override
Definition WsfRIPRJobBoard.cpp:141
int PurgeDeadBidders(double aSimTime)
Definition WsfRIPRJobBoard.cpp:421
Definition WsfRIPRJob.hpp:57
Definition WsfRIPRManager.hpp:71
Definition WsfRIPRProcessor.hpp:45
The main controller for a simulation.
Definition WsfSimulation.hpp:109
std::map< unsigned int, int > RIPRWinnerMap
Definition WsfRIPRCommon.hpp:31
Copyrights Multiple, All Rights Reserved