Compare commits

..

No commits in common. "64f9b632151b2862d5dbd05f2cf65c142d3436f3" and "4494f47a3215376446149bacb7375a231beecf72" have entirely different histories.

6 changed files with 34 additions and 129 deletions

View File

@ -1,86 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BackendCodeEditorSettings">
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_BINARY_EXPRESSIONS_CHAIN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXPRESSION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_FOR_STMT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_TERNARY/@EntryValue" value="ALIGN_ALL" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_CLASS_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_CODE/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_USER_LINEBREAKS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CASE_FROM_SWITCH/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_COMMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_EQ/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SIMPLE_BLOCK_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_SEMICOLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_SEMICOLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_UNARY_OPERATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_ARRAY_ACCESS_BRACKETS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_METHOD_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPECIAL_ELSE_IF_TREATMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_BINARY_OPSIGN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_TERNARY_OPSIGNS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DECLARATION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_INDENTATION/@EntryValue" value="All" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_ARGUMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_PARAMETER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_ARGUMENT/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_PARAMETER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_DECLARATIONS/@EntryValue" value="0" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_ACCESS_SPECIFIERS_FROM_CLASS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CLASS_MEMBERS_FROM_ACCESS_SPECIFIERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_COLON_IN_MEMBER_INITIALIZER_LISTS/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/MEMBER_INITIALIZER_LIST_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_NAMESPACE_DEFINITIONS_ON_SAME_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_COLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_ABSTRACT_DECL/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_DECLARATION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_BLOCKS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_ARGUMENTS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_PARAMETERS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BREAK_TEMPLATE_DECLARATION/@EntryValue" value="LINE_BREAK" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/FREE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INITIALIZER_BRACES/@EntryValue" value="END_OF_LINE_NO_SPACE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_STYLE/@EntryValue" value="Tab" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CONTINUOUS_LINE_INDENT/@EntryValue" value="Double" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
</component>
</project>

View File

@ -1,7 +1,8 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="5" type="CLionNativeAppRunConfigurationType" PROGRAM_PARAMS="F" REDIRECT_INPUT="true" REDIRECT_INPUT_PATH="$PROJECT_DIR$/in/time_dependent_second_spaces.in" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Assignment8" TARGET_NAME="build" CONFIG_NAME="build" version="1" RUN_PATH="a.out"> <configuration default="false" name="5" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
<method v="2"> <makefile filename="C:\Users\Isaac\Documents\CS3413\Assignment8\makefile" target="5" workingDirectory="" arguments="">
<option name="CLION.COMPOUND.BUILD" enabled="true" /> <envs />
</method> </makefile>
<method v="2" />
</configuration> </configuration>
</component> </component>

View File

@ -1,7 +1,8 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="6" type="CLionNativeAppRunConfigurationType" PROGRAM_PARAMS="C" REDIRECT_INPUT="true" REDIRECT_INPUT_PATH="$PROJECT_DIR$/in/time_dependent_second_spaces.in" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Assignment8" TARGET_NAME="build" CONFIG_NAME="build" version="1" RUN_PATH="a.out"> <configuration default="false" name="6" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
<method v="2"> <makefile filename="C:\Users\Isaac\Documents\CS3413\Assignment8\makefile" target="6" workingDirectory="" arguments="">
<option name="CLION.COMPOUND.BUILD" enabled="true" /> <envs />
</method> </makefile>
<method v="2" />
</configuration> </configuration>
</component> </component>

View File

@ -36,7 +36,7 @@ void enqueue(DiskQueue *queue, int time, int position) {
queue->size++; queue->size++;
} }
void delete(DiskQueue *queue, DiskRequest request) { DiskRequest *delete(DiskQueue *queue, DiskRequest request) {
DiskRequest *current = queue->head; DiskRequest *current = queue->head;
DiskRequest *previous = NULL; DiskRequest *previous = NULL;
while (current != NULL) { while (current != NULL) {
@ -47,8 +47,7 @@ void delete(DiskQueue *queue, DiskRequest request) {
previous->next = current->next; previous->next = current->next;
} }
queue->size--; queue->size--;
free(current); return current;
return;
} }
previous = current; previous = current;
current = current->next; current = current->next;
@ -61,11 +60,11 @@ DiskRequest peek(DiskQueue *queue) {
return *queue->head; return *queue->head;
} }
DiskRequest *dequeue(DiskQueue *queue) { DiskRequest dequeue(DiskQueue *queue) {
DiskRequest *head = queue->head; DiskRequest *head = queue->head;
queue->head = head->next; queue->head = head->next;
queue->size--; queue->size--;
return head; return *head;
} }
void destroyDiskQueue(DiskQueue *queue) { void destroyDiskQueue(DiskQueue *queue) {
@ -83,14 +82,14 @@ DiskRequest* findClosest(DiskQueue *queue, int position, double time) {
DiskRequest *current = queue->head; DiskRequest *current = queue->head;
DiskRequest *closest = NULL; DiskRequest *closest = NULL;
while (current != NULL) { while (current != NULL) {
if (current->time <= time) { // Filter out requests that haven't come in yet if (current->time <= time) {
if (closest == NULL) { // If there is no closest yet, set it to the current if (closest == NULL) {
closest = current; closest = current;
} else { } else {
int closestDistance = closest->position - position; // Distance from the closest to the current position, negative means down (bad) int closestDistance = closest->position - position;
int currentDistance = current->position - position; // Distance from the current to the current position, negative means down (bad) int currentDistance = current->position - position;
if (currentDistance > 0) { // If the current is up if (currentDistance > 0) {
if (currentDistance < closestDistance) { // If the current is closer than the closest if (currentDistance < closestDistance) {
closest = current; closest = current;
} }
} }
@ -102,5 +101,5 @@ DiskRequest* findClosest(DiskQueue *queue, int position, double time) {
if (closest == NULL) { if (closest == NULL) {
return NULL; return NULL;
} }
return closest; return delete(queue, *closest);
} }

View File

@ -19,11 +19,11 @@ DiskQueue *createDiskQueue();
void enqueue(DiskQueue *queue, int time, int position); void enqueue(DiskQueue *queue, int time, int position);
void delete(DiskQueue *queue, DiskRequest request); DiskRequest *delete(DiskQueue *queue, DiskRequest request);
DiskRequest peek(DiskQueue *queue); DiskRequest peek(DiskQueue *queue);
DiskRequest *dequeue(DiskQueue *queue); DiskRequest dequeue(DiskQueue *queue);
DiskRequest *findClosest(DiskQueue *queue, int position, double time); DiskRequest *findClosest(DiskQueue *queue, int position, double time);

View File

@ -25,23 +25,17 @@ double timeToProcessRequest(int position, int destination) {
return time; return time;
} }
int diskMovement(int position, int destination) {
int distance = destination - position;
return abs(distance);
}
// Your simulated disk is of size 10000, numbered from 0 to 9999. // Your simulated disk is of size 10000, numbered from 0 to 9999.
// In first come first the time the request comes in is irrelevant // In first come first the time the request comes in is irrelevant
void fcfs(int start) { void fcfs(int start) {
int position = start; int position = start;
while (queue->size > 0) { while (queue->size > 0) {
DiskRequest *request = dequeue(queue); DiskRequest request = dequeue(queue);
while (seekTime < request->time) { seekTime++; } while (seekTime < request.time) { seekTime++; }
seekTime += timeToProcessRequest(position, request->position); seekTime += timeToProcessRequest(position, request.position);
movement += diskMovement(position, request->position); movement += abs(position - request.position);
position = request->position; position = request.position;
free(request);
} }
} }
@ -53,22 +47,18 @@ void cscan(int start) {
if (request == NULL) { if (request == NULL) {
seekTime++; seekTime++;
} else { } else {
// There is a bug here, will need to revisit
if (request->position < position) { if (request->position < position) {
// + 1 simulates the time it takes to move to the end of the disk (it is a circular disk) //seekTime += timeToProcessRequest(position, 9999);
seekTime += timeToProcessRequest(position, 9999 + 1); //seekTime += timeToProcessRequest(9999, 0);
movement += diskMovement(position, 9999 + 1); //movement += abs(position - 9999);
//movement += abs(9999 - 0);
position = 0; position = 0;
// Rescan for closest, so we can efficiently handle requests
request = findClosest(queue, position, seekTime);
} }
seekTime += timeToProcessRequest(position, request->position); seekTime += timeToProcessRequest(position, request->position);
movement += diskMovement(position, request->position); movement += abs(position - request->position);
position = request->position; position = request->position;
} }
if (request != NULL) {
delete(queue, *request);
}
//printf("Movement: %i Time:%.1lf\n", movement, seekTime);
} }
} }