Function to be used for testing purposes. This function guarantees the correct solution for FCFS scheduling algorithm.
Sorts the input vector according to arrival time. Processes whose arrival times are same get sorted according to process ID For each process, completion time, turnaround time and completion time are calculated, inserted in a tuple, which is added to the vector result.
227 {
230 double timeElapsed = 0;
231 for (
size_t i{}; i < input.
size(); i++) {
232 T arrival = get<1>(input[i]);
233 E burst = get<2>(input[i]);
234
235 if (arrival > timeElapsed) {
236 timeElapsed += arrival - timeElapsed;
237 }
238 timeElapsed += burst;
239 double completion = timeElapsed;
240 double turnaround = completion - arrival;
241 double waiting = turnaround - burst;
242
243 get<0>(result[i]) = get<0>(input[i]);
244 get<1>(result[i]) = arrival;
245 get<2>(result[i]) = burst;
246 get<3>(result[i]) = completion;
247 get<4>(result[i]) = turnaround;
248 get<5>(result[i]) = waiting;
249 }
251}
bool sortcol(tuple< S, T, E > &t1, tuple< S, T, E > &t2)
Comparator function for sorting a vector.
Definition fcfs_scheduling.cpp:46
uint64_t result(uint64_t n)
Definition fibonacci_sum.cpp:77