From f04c8f52daa299ac7b22c51a74494afe52aff992 Mon Sep 17 00:00:00 2001
From: Syufan <zyf571635687@gmail.com>
Date: Tue, 18 Apr 2023 22:25:09 +1000
Subject: [PATCH] fix fit sjf

---
 allocate.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/allocate.c b/allocate.c
index fb264cb..c9bd0db 100644
--- a/allocate.c
+++ b/allocate.c
@@ -435,10 +435,11 @@ int main(int argc, char *argv[]) {
 
             strcpy(processing->state, "FINISHED");
             free_memory(memory_list,processing);
+
             // move finished process from input list
             move_node(input_list, processing);
             // add all process except this cycle
-            //pickup_input(batch_list, input_list, simulated_time-quantum);
+
             int proc_remaining = count_list(input_list);
             printf("%d,%s,process_name=%s,proc_remaining=%d \n",simulated_time,processing->state,processing->process_name,proc_remaining);
             // add all process
@@ -477,12 +478,12 @@ int allocate_memory(queue_memory* q, process_n* process, int simulated_time){
         }
         memory_n* temp_end = temp;
 
-        //printf("start = %d, end = %d \n",temp_start->number,temp_end->number);
+        // printf("start = %d, end = %d \n",temp_start->number,temp_end->number);
         // printf("count_memory end  = %d \n",temp->number);
-        //printf("count_memory = %d \n",count_memory);
+        // printf("count_memory = %d \n",count_memory);
 
         // check the memeory size
-        if(count_memory < process->memory){
+        if(count_memory < process->memory && min_end == NULL){
             return 0;
         }
         if (count_memory == process->memory){
@@ -508,6 +509,7 @@ int allocate_memory(queue_memory* q, process_n* process, int simulated_time){
             printf("%d,READY,process_name=%s,assigned_at=%d\n",simulated_time, process->process_name, temp_start->number);
             return 1;
         }else if(count_memory > process->memory){
+            //printf("compare\n");
             if(min == -1){
                 min = count_memory;
                 min_start = temp_start;
@@ -522,10 +524,11 @@ int allocate_memory(queue_memory* q, process_n* process, int simulated_time){
             }
         }
     }
+    //printf("min satrt = %d, min end = %d\n",min_start->number, min_end->number);
     //printf("bug2\n");
 
     int position = find_position(min_start,q);
-   // printf("===========min = %d start=%d %d\n", min, position,process->memory);
+   //printf("===========min = %d start=%d %d\n", min, position,process->memory);
     int size = min_end->number - min_start->number + 1;
     if(min != -1){
         //printf("enter min, process size = %d memory size = %d\n",process->memory,size);
@@ -678,6 +681,7 @@ process_n* search_shortest_process(queue_n* q){
 // receive two list, put the process which arrived time is <= simulated_time
 void pickup_input_task3(queue_n* batch_list, queue_n* input_list, int simulated_time, queue_memory* memory_list){
     process_n* temp = batch_list->head;
+    
     while (temp != NULL) {
         //find arrive time <=> simulated-time
         if(temp->arrival_time <= simulated_time){
@@ -685,7 +689,7 @@ void pickup_input_task3(queue_n* batch_list, queue_n* input_list, int simulated_
             int sta = allocate_memory(memory_list,temp,simulated_time);
 
             //cleaprintf("allocate memory: %d \n",temp->memory);
-            // printf("============%d\n", sta);
+            //printf("============%d\n", sta);
             if (sta==1){
                 //1.delete node from current list
                 move_node(batch_list, temp);
-- 
GitLab