Question: class Job { public: std::string jobID; char jobClass; int priority; double runtime; long long startTime; long long endTime; double elapsedTime; Job ( ) : jobID
class Job
public:
std::string jobID;
char jobClass;
int priority;
double runtime;
long long startTime;
long long endTime;
double elapsedTime;
Job : jobID jobClass priority runtime startTime endTime elapsedTime
Jobconst std::string& id char cls int prio
: jobIDid jobClasscls priorityprio runtime std::rand
startTime endTime elapsedTime
bool operatorconst Job& other const
return priority other.priority;
;
std::queue populateInputQueueconst std::string& filename
std::queue inputQueue;
std::ifstream filefilename;
std::string line;
std::getlinefile line;
while std::getlinefile line
std::istringstream issline;
std::string jobID;
char jobClass;
int priority;
iss jobID jobClass priority;
if iss.fail
Job jobjobID jobClass, priority;
std::cout "Loaded job: job.jobID Class: job.jobClass
Priority: job.priority
Runtime: std::fixed std::setprecision job.runtime s
;
inputQueue.pushjob;
return inputQueue;
std::unorderedmap moveJobsToClassQueuesstd::queue& inputQueue
std::unorderedmap jobClassQueues;
for char c A; c Z; c
jobClassQueuesc std::priorityqueue;
while inputQueue.empty
Job job inputQueue.front;
inputQueue.pop;
jobClassQueuesjobjobClasspushjob;
std::cout "Moving job job.jobID to class job.jobClass queue.
;
return jobClassQueues;
std::vector dispatchJobsstd::unorderedmap& jobClassQueues,
const std::unorderedmap& processors
std::vector outputQueue;
std::unorderedmap processorStatus;
for const auto& p : processors
processorStatuspfirst std::vectorpsecond;
int currentTime ;
std::srandstaticcaststd::time;
while true
bool allQueuesEmpty true;
for const auto& entry : jobClassQueues
if entry.second.empty
std::anyofprocessorStatusentryfirstbegin processorStatusentryfirstend
const Job& job return job.jobID.empty;
allQueuesEmpty false;
break;
if allQueuesEmpty break;
for const auto& entry : processorStatus
char classType entry.first;
for sizet i ; i entry.second.size; i
if entrysecondijobID.empty && jobClassQueuesclassTypeempty
Job job jobClassQueuesclassTypetop;
job.startTime currentTime;
job.endTime currentTime staticcastjobruntime;
processorStatusclassTypei job;
std::cout "Dispatching job: job.jobID from Class: job.jobClass
to Processor i
;
jobClassQueuesclassTypepop;
for auto& entry : processorStatus
char classType entry.first;
for sizet i ; i entry.second.size; i
Job& job entry.secondi;
if job.jobID.empty && job.endTime currentTime
job.elapsedTime job.endTime job.startTime;
outputQueue.pushbackjob;
std::cout "Completed job: job.jobID
Start Time: job.startTime
End Time: job.endTime
Runtime: std::fixed std::setprecision job.runtime s
;
entry.secondi Job;
currentTime;
return outputQueue;
This phase will implementconcurrency of the three different processes.
Chnages to existing functions:
After reading in the initial "jobs file" to populate the input queue, the 'read job' process will allow a user at the console to enter new jobs. Each new job will be entered at the console. The user will enter the job class, and the job priority a higher value has a higher priority The process will generate a 'runtime' between and seconds, and the jobname will be J with the next sequential job number digits
The 'system' will shut down once there are no jobs to be processed. This occurs when there are no available jobs for the processors to handle. C
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
