WSF
WsfRIPRJob.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
17//* FILE NAME:
18//* WsfRIPRJob.hpp
19//*
20//* PURPOSE:
21//* The WsfRIPRJob class stores information about one job that an agent can
22//* perform. It is generally used with the WsfRIPRJobBoard.
23//*
24//* NOTES:
25//* None
26//***************************************************************************
27
28#ifndef WSFRIPRJOB_HPP
29#define WSFRIPRJOB_HPP
30
31#include <map>
32#include <set>
33#include <string>
34
35#include "UtReferenceTracked.hpp"
36#include "WsfObject.hpp"
37class WsfPlatform;
38#include "WsfRIPRCommon.hpp"
39#include "WsfRIPRJobBoard.hpp"
40class WsfRIPRManager;
43class WsfSimulation;
44
45namespace wsf
46{
47namespace comm
48{
49class Comm;
50}
51} // namespace wsf
52
53// WsfRIPRJob is a data class that holds information specifying what a job
54// is and how it should be carried out.
55
56class WsfRIPRJob : public WsfObject
57{
58public:
59 WsfRIPRJob(WsfRIPRManager* aManagerPtr);
60 // WsfRIPRJob(const WsfRIPRProcessor& aAssigner, std::string aJobName, std::string aJobDescription, double aPriority
61 // = 0, int aMaxTakers = 1);
62 WsfRIPRJob(WsfRIPRManager* aManagerPtr,
63 unsigned int aAssignerRIPRProcId,
64 std::string& aJobName,
65 std::string& aJobDescription,
66 double aPriority = 0,
67 int aMaxTakers = 1);
68 WsfRIPRJob(const WsfRIPRJob& aSrc);
69 WsfRIPRJob* Clone() const override { return new WsfRIPRJob(*this); }
70 ~WsfRIPRJob() override;
71
72 WsfRIPRJob& operator=(const WsfRIPRJob& aSrc);
73
74 void Update(double aSimTime);
75
76 void BidJob(unsigned int aBidderRIPRProcId, double aBid, double aProgress);
77 void BidJob(unsigned int aBidderRIPRProcId, double aBid);
78
79 ripr::RIPRBidderList::iterator UnbidJob(unsigned int aQuitterRIPRProcId);
80
81 void ClearBidders();
82
83 double GetBid(unsigned int aRIPRProcId) const;
84
86
87 double GetBestProgress();
88
89 void SetWinnersMax(const int aNum);
90 void SetWinnersMin(const int aNum);
91
92 void SetPriority(const double aPriority);
93
94 void SetProgress(WsfRIPRProcessor* aBidderPtr, int aChannelIndex, double aProgress);
95 void SetProgress(unsigned int aRIPRProcId, double aProgress);
96
97 double GetProgress(unsigned int aBidderRIPRProcId);
98
99 int GetRank(unsigned int aBidderRIPRProcId);
100
101 int GetId() const;
102
103 unsigned int AssignerProcessorId() const { return mAssignerProcessorId; }
104
106 size_t AssignerPlatformIndex() const;
108 WsfRIPRProcessor* Assigner() const;
110 double GetPriority() const { return mPriority; }
111 int GetWinnersMax() const { return mWinnersMax; }
112 int GetWinnersMin() const { return mWinnersMin; }
113 std::string Description() const { return mDescription; }
114 const ripr::RIPRJobDataMap& Data() const { return mData; }
115 UtScriptData Data(const std::string& aDataKey) const;
116
117 static bool CompareBidders(const ripr::RIPRBidderPair& first, const ripr::RIPRBidderPair& second);
118
119 static int NextId();
120
121 static void Reset() { mNextJobId = 0; }
122
124 template<typename T>
125 void Serialize(T& aBuff)
126 {
128 aBuff& mBidders& mProgress& mDescription& mData& mPriority& mWinnersMax& mBidsChanged& mBidWindowOpen&
129 mAssignerProcessorId& mId& mCurrentTime;
130 }
131
134 double CurrentTime() const { return mCurrentTime; }
135
136 void SetBidWindowOpen(const bool aValue) { mBidWindowOpen = aValue; }
137 bool IsBidWindowOpen() const { return mBidWindowOpen; }
138
139 // Job Board over comm methods
140 void SendMessageSetProgress(wsf::comm::Comm* aCommPtr, WsfRIPRProcessor* aBidderPtr, int aChannelIndex, double aProgress);
141 void SendMessageBidJob(wsf::comm::Comm* aCommPtr,
142 WsfRIPRProcessor* aBidderPtr,
143 int aChannelIndex,
144 double aBid,
145 double aProgress = 0);
146 void SendMessageUnbidJob(wsf::comm::Comm* aCommPtr, WsfRIPRProcessor* aBidderPtr, int aChannelIndex);
149
151
154
157
159 std::string mDescription;
160
163
165 void DependencyAdd(int aDependedOnJobId) { WsfRIPRJobBoard::DependencyAdd(GetId(), aDependedOnJobId); };
166 void DependencyRemove(int aDependedOnJobId) { WsfRIPRJobBoard::DependencyRemove(GetId(), aDependedOnJobId); };
167 bool DependencyCheck(int aDependedOnJobId) { return WsfRIPRJobBoard::DependencyCheck(GetId(), aDependedOnJobId); };
169
170 void Touch();
171 double TouchTime() { return mLastTouched; };
172
173private:
174 void Update();
175
177 bool mBidsChanged;
178
180 bool mBidWindowOpen;
181
182 // priority and num winners trigger observer call on change, so must be
183 // kept provide to ensure the "Set" function triggers the necessary
184 // notification sequence.
185
188 double mPriority;
189
192 int mWinnersMax;
193
196 int mWinnersMin;
197
199 unsigned int mAssignerProcessorId;
200
203 int mId;
204
207 double mCurrentTime;
208
210 double mLastTouched;
211
212 static int mNextJobId;
213};
214
215
218{
219public:
220 WsfScriptRIPRJobClass(const std::string& aClassName, UtScriptTypes* aScriptTypesPtr);
221
222 // See the base class for a description of Create, Clone, and Destroy.
223
224 void Destroy(void* aObjectPtr) override;
225
258 UT_DECLARE_SCRIPT_METHOD(Touch); // NO_DOC | FOR_TEST_ONLY
259 UT_DECLARE_SCRIPT_METHOD(TouchTime); // NO_DOC | FOR_TEST_ONLY
260 UT_DECLARE_SCRIPT_METHOD(DependenciesForJob);
262 UT_DECLARE_SCRIPT_METHOD(DependencyRemove);
263 UT_DECLARE_SCRIPT_METHOD(DependencyCheck);
264 UT_DECLARE_SCRIPT_METHOD(DependencyCount);
265};
266
267#endif
ut::script::Data UtScriptData
Definition WsfScriptContext.hpp:47
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
void Serialize(T &aBuff)
For XIO (de)serialization.
Definition WsfObject.hpp:104
WsfObject()
This is the constructor for the WsfObject class.
Definition WsfObject.cpp:88
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
static int DependencyCount(int aDependentJobId)
Definition WsfRIPRJobBoard.hpp:166
static std::set< int > & DependenciesForJob(int aJobId)
Definition WsfRIPRJobBoard.hpp:153
static bool DependencyCheck(int aDependentJobId, int aDependedOnJobId)
Definition WsfRIPRJobBoard.hpp:162
static void DependencyRemove(int aDependentJobId, int aDependedOnJobId)
Definition WsfRIPRJobBoard.hpp:158
static void DependencyAdd(int aDependentJobId, int aDependedOnJobId)
Definition WsfRIPRJobBoard.hpp:154
Definition WsfRIPRJob.hpp:57
void Serialize(T &aBuff)
For XIO (de)serialization.
Definition WsfRIPRJob.hpp:125
ripr::RIPRBidderList GetBidders() const
Definition WsfRIPRJob.hpp:85
void SetWinnersMin(const int aNum)
Sets the minimum number of bidders who can win this job.
Definition WsfRIPRJob.cpp:438
void Update(double aSimTime)
Definition WsfRIPRJob.cpp:155
void SetWinnersMax(const int aNum)
Sets the maximum number of bidders who can win this job.
Definition WsfRIPRJob.cpp:426
void SendMessageUnbidJob(wsf::comm::Comm *aCommPtr, WsfRIPRProcessor *aBidderPtr, int aChannelIndex)
Definition WsfRIPRJob.cpp:545
double GetBestProgress()
Definition WsfRIPRJob.cpp:193
ripr::RIPRBidderList::iterator UnbidJob(unsigned int aQuitterRIPRProcId)
Definition WsfRIPRJob.cpp:261
void SetBidWindowOpen(const bool aValue)
Definition WsfRIPRJob.hpp:136
bool DependencyCheck(int aDependedOnJobId)
Definition WsfRIPRJob.hpp:167
WsfRIPRJob & operator=(const WsfRIPRJob &aSrc)
Definition WsfRIPRJob.cpp:130
~WsfRIPRJob() override
Definition WsfRIPRJob.cpp:121
void BidJob(unsigned int aBidderRIPRProcId, double aBid, double aProgress)
Definition WsfRIPRJob.cpp:211
int GetRank(unsigned int aBidderRIPRProcId)
Definition WsfRIPRJob.cpp:360
WsfStringId AssignerProcessorName() const
Definition WsfRIPRJob.cpp:410
WsfRIPRJob * Clone() const override
Definition WsfRIPRJob.hpp:69
size_t AssignerPlatformIndex() const
Definition WsfRIPRJob.cpp:386
double CurrentTime() const
Definition WsfRIPRJob.hpp:134
ripr::RIPRBidderList mBidders
list of pairs matching bidders (by proc id) to their bids (doubles)
Definition WsfRIPRJob.hpp:153
void SetPriority(const double aPriority)
Set the job's priority.
Definition WsfRIPRJob.cpp:448
WsfSimulation * GetSimulation() const
Definition WsfRIPRJob.cpp:574
void DependencyAdd(int aDependedOnJobId)
Definition WsfRIPRJob.hpp:165
WsfRIPRProcessor * Assigner() const
Definition WsfRIPRJob.cpp:420
void SendMessageSetProgress(wsf::comm::Comm *aCommPtr, WsfRIPRProcessor *aBidderPtr, int aChannelIndex, double aProgress)
Definition WsfRIPRJob.cpp:480
double GetProgress(unsigned int aBidderRIPRProcId)
Definition WsfRIPRJob.cpp:348
const ripr::RIPRJobDataMap & Data() const
Definition WsfRIPRJob.hpp:114
int GetWinnersMax() const
Definition WsfRIPRJob.hpp:111
WsfStringId AssignerPlatformName() const
Definition WsfRIPRJob.cpp:376
WsfRIPRManager * GetManager() const
Definition WsfRIPRJob.hpp:147
double GetPriority() const
Definition WsfRIPRJob.hpp:110
double GetBid(unsigned int aRIPRProcId) const
Definition WsfRIPRJob.cpp:316
std::string Description() const
Definition WsfRIPRJob.hpp:113
void DependencyRemove(int aDependedOnJobId)
Definition WsfRIPRJob.hpp:166
int GetId() const
Definition WsfRIPRJob.cpp:183
WsfRIPRManager * mManagerPtr
Definition WsfRIPRJob.hpp:150
static int NextId()
Definition WsfRIPRJob.cpp:178
void SendMessageBidJob(wsf::comm::Comm *aCommPtr, WsfRIPRProcessor *aBidderPtr, int aChannelIndex, double aBid, double aProgress=0)
Definition WsfRIPRJob.cpp:510
unsigned int AssignerProcessorId() const
Definition WsfRIPRJob.hpp:103
WsfPlatform * AssignerPlatform() const
Definition WsfRIPRJob.cpp:396
int GetWinnersMin() const
Definition WsfRIPRJob.hpp:112
static void Reset()
Definition WsfRIPRJob.hpp:121
int DependencyCount()
Definition WsfRIPRJob.hpp:168
ripr::RIPRJobProgressMap mProgress
mapping between proc ids and progress performing this job
Definition WsfRIPRJob.hpp:156
void ClearBidders()
Definition WsfRIPRJob.cpp:296
void SetProgress(WsfRIPRProcessor *aBidderPtr, int aChannelIndex, double aProgress)
Definition WsfRIPRJob.cpp:343
WsfRIPRJob(WsfRIPRManager *aManagerPtr)
Definition WsfRIPRJob.cpp:56
std::string mDescription
a human-readable string describing this job
Definition WsfRIPRJob.hpp:159
double TouchTime()
Definition WsfRIPRJob.hpp:171
std::set< int > & Dependencies()
Definition WsfRIPRJob.hpp:164
static bool CompareBidders(const ripr::RIPRBidderPair &first, const ripr::RIPRBidderPair &second)
Definition WsfRIPRJob.cpp:188
ripr::RIPRJobDataMap mData
key/value pairs of auxiliary data attached to this job
Definition WsfRIPRJob.hpp:162
bool IsBidWindowOpen() const
Definition WsfRIPRJob.hpp:137
void Touch()
Definition WsfRIPRJob.cpp:475
Definition WsfRIPRManager.hpp:71
Definition WsfRIPRProcessor.hpp:45
void * Create(const UtScriptContext &aInstance) override
Definition WsfScriptObjectClass.cpp:44
WsfScriptObjectClass(const std::string &aClassName, UtScriptTypes *aTypesPtr)
Definition WsfScriptObjectClass.cpp:24
UT_DECLARE_SCRIPT_METHOD(UnbidJob_1)
UT_DECLARE_SCRIPT_METHOD(Winners)
UT_DECLARE_SCRIPT_METHOD(Progress_1)
WsfScriptRIPRJobClass(const std::string &aClassName, UtScriptTypes *aScriptTypesPtr)
Definition WsfRIPRJob.cpp:580
UT_DECLARE_SCRIPT_METHOD(Description)
UT_DECLARE_SCRIPT_METHOD(SetWinnersMax)
UT_DECLARE_SCRIPT_METHOD(DependencyRemove)
UT_DECLARE_SCRIPT_METHOD(ClearBidders)
UT_DECLARE_SCRIPT_METHOD(SetWinnersMin)
UT_DECLARE_SCRIPT_METHOD(BestProgress)
UT_DECLARE_SCRIPT_METHOD(Data_1)
UT_DECLARE_SCRIPT_METHOD(SetPriority)
UT_DECLARE_SCRIPT_METHOD(Data_2)
UT_DECLARE_SCRIPT_METHOD(Rank_2)
UT_DECLARE_SCRIPT_METHOD(WinnersMin)
UT_DECLARE_SCRIPT_METHOD(GetName)
UT_DECLARE_SCRIPT_METHOD(Progress_2)
UT_DECLARE_SCRIPT_METHOD(DependencyCheck)
UT_DECLARE_SCRIPT_METHOD(DependencyAdd)
UT_DECLARE_SCRIPT_METHOD(DependenciesForJob)
UT_DECLARE_SCRIPT_METHOD(Priority)
UT_DECLARE_SCRIPT_METHOD(TouchTime)
UT_DECLARE_SCRIPT_METHOD(SetProgress_1)
UT_DECLARE_SCRIPT_METHOD(BidJob_4)
UT_DECLARE_SCRIPT_METHOD(Rank_1)
UT_DECLARE_SCRIPT_METHOD(DependencyCount)
void Destroy(void *aObjectPtr) override
Definition WsfRIPRJob.cpp:640
UT_DECLARE_SCRIPT_METHOD(GetBid_2)
UT_DECLARE_SCRIPT_METHOD(Create)
UT_DECLARE_SCRIPT_METHOD(WinnersMax)
UT_DECLARE_SCRIPT_METHOD(Assigner)
UT_DECLARE_SCRIPT_METHOD(BidJob_2)
UT_DECLARE_SCRIPT_METHOD(BidJob_1)
UT_DECLARE_SCRIPT_METHOD(GetBid_1)
UT_DECLARE_SCRIPT_METHOD(WinnersActual)
UT_DECLARE_SCRIPT_METHOD(UnbidJob_2)
UT_DECLARE_SCRIPT_METHOD(SetProgress_2)
UT_DECLARE_SCRIPT_METHOD(SetData)
UT_DECLARE_SCRIPT_METHOD(BidJob_3)
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Definition WsfComm.hpp:43
std::map< UtScriptData, UtScriptData > RIPRJobDataMap
Definition WsfRIPRCommon.hpp:29
std::list< RIPRBidderPair > RIPRBidderList
Definition WsfRIPRCommon.hpp:34
std::pair< unsigned int, double > RIPRBidderPair
Definition WsfRIPRCommon.hpp:33
std::map< unsigned int, double > RIPRJobProgressMap
Definition WsfRIPRCommon.hpp:32
Definition WsfComm.cpp:34
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Copyrights Multiple, All Rights Reserved