Fix time calculation
This commit is contained in:
parent
531c063830
commit
4cf7a4e698
8
Assignment8/.idea/runConfigurations/1.xml
Normal file
8
Assignment8/.idea/runConfigurations/1.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="1" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
|
||||
<makefile filename="C:\Users\Isaac\Documents\CS3413\Assignment8\makefile" target="1" workingDirectory="" arguments="">
|
||||
<envs />
|
||||
</makefile>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
8
Assignment8/.idea/runConfigurations/2.xml
Normal file
8
Assignment8/.idea/runConfigurations/2.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="2" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
|
||||
<makefile filename="C:\Users\Isaac\Documents\CS3413\Assignment8\makefile" target="2" workingDirectory="" arguments="">
|
||||
<envs />
|
||||
</makefile>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
8
Assignment8/.idea/runConfigurations/3.xml
Normal file
8
Assignment8/.idea/runConfigurations/3.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="3" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
|
||||
<makefile filename="C:\Users\Isaac\Documents\CS3413\Assignment8\makefile" target="3" workingDirectory="" arguments="">
|
||||
<envs />
|
||||
</makefile>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
8
Assignment8/.idea/runConfigurations/4.xml
Normal file
8
Assignment8/.idea/runConfigurations/4.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="4" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
|
||||
<makefile filename="C:\Users\Isaac\Documents\CS3413\Assignment8\makefile" target="4" workingDirectory="" arguments="">
|
||||
<envs />
|
||||
</makefile>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
8
Assignment8/.idea/runConfigurations/5.xml
Normal file
8
Assignment8/.idea/runConfigurations/5.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="5" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
|
||||
<makefile filename="C:\Users\Isaac\Documents\CS3413\Assignment8\makefile" target="5" workingDirectory="" arguments="">
|
||||
<envs />
|
||||
</makefile>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
8
Assignment8/.idea/runConfigurations/6.xml
Normal file
8
Assignment8/.idea/runConfigurations/6.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="6" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
|
||||
<makefile filename="C:\Users\Isaac\Documents\CS3413\Assignment8\makefile" target="6" workingDirectory="" arguments="">
|
||||
<envs />
|
||||
</makefile>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
@ -49,7 +49,7 @@ DiskRequest dequeue(DiskQueue *queue) {
|
||||
}
|
||||
|
||||
// Allocates a new queue with the requests that have the same time
|
||||
DiskQueue* queueOfSameTime(DiskQueue *queue, int time) {
|
||||
DiskQueue *queueOfSameTime(DiskQueue *queue, int time) {
|
||||
DiskQueue *sameTimeQueue = createDiskQueue();
|
||||
for (int i = queue->index; i < queue->size - queue->index; i++) {
|
||||
if (queue->requests[i].time == time) {
|
||||
@ -67,7 +67,7 @@ int compareDiskRequestsByPosition(const void *a, const void *b) {
|
||||
}
|
||||
|
||||
// Sorts the queue by position, in place
|
||||
DiskQueue* sortQueueByPosition(DiskQueue* queue) {
|
||||
DiskQueue *sortQueueByPosition(DiskQueue *queue) {
|
||||
qsort(queue->requests, queue->size, sizeof(DiskRequest), compareDiskRequestsByPosition);
|
||||
return queue;
|
||||
}
|
||||
@ -92,13 +92,14 @@ double seekTime = 0;
|
||||
DiskQueue *queue;
|
||||
|
||||
double timeToProcessRequest(int position, int destination) {
|
||||
//The time (a floating point number) required to process a request is computed by distance the head travels divided by 5,
|
||||
//plus additional 15 milliseconds penalty if the direction has to change (for FCFS)
|
||||
//The time (a floating point number) required to process a request is computed by distance the head travels divided by 5
|
||||
//Plus additional 15 milliseconds penalty if the direction has to change (for FCFS)
|
||||
double time = 0;
|
||||
int distance = position - destination;
|
||||
DiskDirection direction = distance > 0 ? UP : DOWN;
|
||||
time += abs(distance) / 5;
|
||||
if (currentDirection != direction) {
|
||||
// Calculated this way so that positive means up and negative means down
|
||||
int distance = destination - position;
|
||||
DiskDirection direction = (distance > 0) ? UP : DOWN;
|
||||
time += abs(distance) / 5.0;
|
||||
if (direction != currentDirection) {
|
||||
time += 15;
|
||||
currentDirection = direction;
|
||||
}
|
||||
@ -126,7 +127,7 @@ void cscan(int start) {
|
||||
while (currentTime < request.time) { currentTime++; }
|
||||
|
||||
DiskQueue *sameTimeQueue = sortQueueByPosition(queueOfSameTime(queue, request.time));
|
||||
for (;i < sameTimeQueue->size; i++) {
|
||||
for (; i < sameTimeQueue->size; i++) {
|
||||
DiskRequest request = dequeue(sameTimeQueue);
|
||||
|
||||
// Need to return to 0 because we have reached the end of the disk on the current pass
|
||||
@ -160,11 +161,12 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
if (algorithm == 'F') {
|
||||
fcfs(start);
|
||||
printf("Movement:%i Time:%.1lf\n", movement, seekTime);
|
||||
} else if (algorithm == 'C') {
|
||||
cscan(start);
|
||||
}
|
||||
// Stupid printf difference to pass tests, could call once after if statement
|
||||
printf("Movement: %i Time:%.1lf\n", movement, seekTime);
|
||||
|
||||
}
|
||||
destroyDiskQueue(queue);
|
||||
|
||||
return 0;
|
||||
|
14
Assignment8/documentation/verify.md
Normal file
14
Assignment8/documentation/verify.md
Normal file
@ -0,0 +1,14 @@
|
||||
| Initial position | Next Position | Distance | Time From Distance | Time from Change Direction | Total Time |
|
||||
|------------------|---------------|----------|--------------------|----------------------------|------------|
|
||||
| 0 | 93 | 93 | 18.6 | 0 | 18.6 |
|
||||
| 93 | 183 | 90 | 18 | 0 | 18 |
|
||||
| 183 | 37 | 146 | 29.2 | 15 | 44.2 |
|
||||
| 37 | 122 | 85 | 17 | 0 | 17 |
|
||||
| 122 | 14 | 108 | 21.6 | 15 | 36.6 |
|
||||
| 14 | 124 | 110 | 22 | 0 | 22 |
|
||||
| 124 | 65 | 59 | 11.8 | 15 | 26.8 |
|
||||
| 65 | 67 | 2 | 0.4 | 0 | 0.4 |
|
||||
|
||||
| Total Distance | Total Time |
|
||||
|----------------|------------|
|
||||
| 693 | 183 |
|
Loading…
Reference in New Issue
Block a user