I am trying to do Shortest Remaining Time scheduling algorithms turnaround time. This is the formula.
Turnaround Time = Completion Time - Arrival Time
I have already sorted my arrays.
This is what it looks like my hand.
5,1 done with magical 0
9,2 2nd iteration 1
2,4 1st iteration 2
0,7 done because first 3
0 to 7, 7 to 11, 11 to 12, 12 to 14
7 9 7 5
Turnaround Time = Completion Time - Arrival Time
1 3 2 4
0 to 7, 7 to 8, 8 to 12, 12 to 14
7 3 10 5
My issue is the backtracking to the 9,2. Since it hasn't arrived yet you have to skip it. 9 is the arrival time and 2 is how much time it takes to process. It has A LOT of print statements because I have been trying to figure out what is going on.
for(j = 1; j < i; j++)
{
printf("kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk \n");
printf("j is %d abcd \n", j);
printf("arrival_time_array is %d\n", arrival_time_array[1]);
printf("time_cycles_required_for_job_array is %d\n", time_cycles_required_for_job_array[1]);
printf("completion_time[1] above while: %d \n",completion_time[1]);
printf("aaacompletion_time[j]: %d \n",completion_time[j]);
printf("%d %d\n", magical_completion_time ,arrival_time_array[j]);
printf("arrival_time_array[j] is %d \n", arrival_time_array[j]);
printf("kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk \n");
if(completed_flag[j] != 1)
{
printf("%d %d\n", completion_time[j] ,arrival_time_array[j]);
printf("bbbcompletion_time[j]: %d \n",completion_time[j]);
if(magical_completion_time >= arrival_time_array[j])
{
printf("j is %d \n", j);
printf("%d %d\n", completion_time[j] ,arrival_time_array[j]);
printf("arrival_time_array is %d\n", arrival_time_array[j]);
printf("time_cycles_required_for_job_array is %d\n", time_cycles_required_for_job_array[j]);
printf("completion_time[j] is %d\n", completion_time[j]);
completion_time[j+1] = magical_completion_time + time_cycles_required_for_job_array[j+1];
magical_completion_time = completion_time[j];
completed_flag[j] = 1;
printf("setting completed_flag[j] at j which is: %d \n",j);
printf("yyycompletion_time[j]: %d \n",completion_time[j]);
}
else
{
printf("j is %d \n", j);
printf("In the else: \n");
printf("magical_completion_time is %d \n", magical_completion_time);
printf("completion_time[j]: %d \n",completion_time[j]);
printf("time_cycles_required_for_job_array[j]: %d \n",time_cycles_required_for_job_array[j+1]);
completion_time[j+1] = magical_completion_time + time_cycles_required_for_job_array[j+1];
magical_completion_time = completion_time[j+1];
printf("xxxcompletion_time[j+1]: %d \n",completion_time[j+1]);
completed_flag[j+1] = 1;
printf("setting completed_flag[j+1] at j + 1 which is: %d \n",j + 1);
j = 1;
}
}
printf("j is %d \n", j);
}