Fix time calculation
This commit is contained in:
		
							
								
								
									
										8
									
								
								Assignment8/.idea/runConfigurations/1.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assignment8/.idea/runConfigurations/1.xml
									
									
									
										generated
									
									
									
										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
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assignment8/.idea/runConfigurations/2.xml
									
									
									
										generated
									
									
									
										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
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assignment8/.idea/runConfigurations/3.xml
									
									
									
										generated
									
									
									
										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
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assignment8/.idea/runConfigurations/4.xml
									
									
									
										generated
									
									
									
										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
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assignment8/.idea/runConfigurations/5.xml
									
									
									
										generated
									
									
									
										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
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Assignment8/.idea/runConfigurations/6.xml
									
									
									
										generated
									
									
									
										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 | // 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(); | 	DiskQueue *sameTimeQueue = createDiskQueue(); | ||||||
| 	for (int i = queue->index; i < queue->size - queue->index; i++) { | 	for (int i = queue->index; i < queue->size - queue->index; i++) { | ||||||
| 		if (queue->requests[i].time == time) { | 		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 | // Sorts the queue by position, in place | ||||||
| DiskQueue* sortQueueByPosition(DiskQueue* queue) { | DiskQueue *sortQueueByPosition(DiskQueue *queue) { | ||||||
| 	qsort(queue->requests, queue->size, sizeof(DiskRequest), compareDiskRequestsByPosition); | 	qsort(queue->requests, queue->size, sizeof(DiskRequest), compareDiskRequestsByPosition); | ||||||
| 	return queue; | 	return queue; | ||||||
| } | } | ||||||
| @@ -92,13 +92,14 @@ double seekTime = 0; | |||||||
| DiskQueue *queue; | DiskQueue *queue; | ||||||
|  |  | ||||||
| double timeToProcessRequest(int position, int destination) { | 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, | 	//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) | 	//Plus additional 15 milliseconds penalty if the direction has to change (for FCFS) | ||||||
| 	double time = 0; | 	double time = 0; | ||||||
| 	int distance = position - destination; | 	// Calculated this way so that positive means up and negative means down | ||||||
| 	DiskDirection direction = distance > 0 ? UP : DOWN; | 	int distance = destination - position; | ||||||
| 	time += abs(distance) / 5; | 	DiskDirection direction = (distance > 0) ? UP : DOWN; | ||||||
| 	if (currentDirection != direction) { | 	time += abs(distance) / 5.0; | ||||||
|  | 	if (direction != currentDirection) { | ||||||
| 		time += 15; | 		time += 15; | ||||||
| 		currentDirection = direction; | 		currentDirection = direction; | ||||||
| 	} | 	} | ||||||
| @@ -126,7 +127,7 @@ void cscan(int start) { | |||||||
| 		while (currentTime < request.time) { currentTime++; } | 		while (currentTime < request.time) { currentTime++; } | ||||||
|  |  | ||||||
| 		DiskQueue *sameTimeQueue = sortQueueByPosition(queueOfSameTime(queue, request.time)); | 		DiskQueue *sameTimeQueue = sortQueueByPosition(queueOfSameTime(queue, request.time)); | ||||||
| 		for (;i < sameTimeQueue->size; i++) { | 		for (; i < sameTimeQueue->size; i++) { | ||||||
| 			DiskRequest request = dequeue(sameTimeQueue); | 			DiskRequest request = dequeue(sameTimeQueue); | ||||||
|  |  | ||||||
| 			// Need to return to 0 because we have reached the end of the disk on the current pass | 			// 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') { | 	if (algorithm == 'F') { | ||||||
| 		fcfs(start); | 		fcfs(start); | ||||||
|  | 		printf("Movement:%i Time:%.1lf\n", movement, seekTime); | ||||||
| 	} else if (algorithm == 'C') { | 	} else if (algorithm == 'C') { | ||||||
| 		cscan(start); | 		cscan(start); | ||||||
|  | 		// Stupid printf difference to pass tests, could call once after if statement | ||||||
|  | 		printf("Movement: %i Time:%.1lf\n", movement, seekTime); | ||||||
| 	} | 	} | ||||||
| 	printf("Movement: %i Time:%.1lf\n", movement, seekTime); |  | ||||||
|  |  | ||||||
| 	destroyDiskQueue(queue); | 	destroyDiskQueue(queue); | ||||||
|  |  | ||||||
| 	return 0; | 	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        | | ||||||
		Reference in New Issue
	
	Block a user