private void run_task_non_pre(task running) { if (running.arrival_time > Timer) { Timer = running.arrival_time; } running.start_time = Timer; bool fi_task_gya_w_enta_48al = false; do//lw fi task gya w enta 43'al { if (tasks_map.Count != 0) { if (Timer + running.duration >= tasks_map.First().Key) { fi_task_gya_w_enta_48al = true; update_current_tasks(); } else { fi_task_gya_w_enta_48al = false; } } else { break; } } while (fi_task_gya_w_enta_48al); Timer += running.duration; running.finish_time = Timer; running.finished = true; task temp = new task(running); finished_tasks.Add(temp); }
private void run_preemptive() { if (running_task.arrival_time > Timer) { Timer = running_task.arrival_time; } running_task.start_time = Timer; if (tasks_map.Count != 0) { running_task.start_time = Timer; if (tasks_map.First().Key <= (Timer + running_task.remaining_time))//lw fi task gya w hya 43'ala { preempt(); } else { running_task.start_time = Timer; Timer = Timer + running_task.remaining_time; running_task.finish_time = Timer; running_task.finished = true; task temp = new task(running_task); finished_tasks.Add(temp); } } else//ya3ni mafi4 7ad hyege gded 4a3'al eli 3ndk beltartib bta3k { Timer = Timer + running_task.remaining_time; running_task.finish_time = Timer; running_task.finished = true; task temp = new task(running_task); finished_tasks.Add(temp); } }
public void schedul() { no_tasks = tasks.Count; if (mode == "FCFS") { sort_by = "arrival_time";//so Sort function will sort according the arrival time tasks.Sort(); foreach (task t in tasks) { if (t.arrival_time > Timer) { Timer = t.arrival_time; } t.start_time = Timer; Timer += t.duration; t.finish_time = Timer; t.finished = true; finished_tasks.Add(t); } } if (mode == "SJF") { fill_tasks_map(); float First_key = tasks_map.Keys.First(); // current_tasks = tasks_map[First_key]; //tasks_map.Remove(First_key); update_current_tasks(); if (tasks_map.Count != 0) { First_key = tasks_map.Keys.First(); } while (current_tasks.Count != 0) { if (tasks_map.Count != 0) { First_key = tasks_map.Keys.First(); } running_task = current_tasks.First(); current_tasks.RemoveAt(0); run_task_non_pre(running_task); if ((current_tasks.Count == 0) && (tasks_map.Count != 0)) { update_current_tasks(); } } } if (mode == "Priority") { fill_tasks_map(); float First_key = tasks_map.Keys.First(); // current_tasks = tasks_map[First_key]; //tasks_map.Remove(First_key); // mode = "SJF"; update_current_tasks(); mode = "Priority"; while (current_tasks.Count != 0) { if (tasks_map.Count != 0) { First_key = tasks_map.Keys.First(); } running_task = current_tasks.First(); current_tasks.RemoveAt(0); run_task_non_pre(running_task);//run the running task if ((current_tasks.Count == 0) && (tasks_map.Count != 0)) { update_current_tasks(); } } } if (mode == "SJF-Preemptive") { fill_tasks_map(); float First_key = tasks_map.Keys.First(); // current_tasks = tasks_map[First_key]; // tasks_map.Remove(First_key); update_current_tasks(); if (tasks_map.Count != 0) { First_key = tasks_map.Keys.First(); } while (current_tasks.Count != 0) { running_task = current_tasks.First(); current_tasks.RemoveAt(0); run_preemptive();//run the running task if ((current_tasks.Count == 0) && (tasks_map.Count != 0)) { update_current_tasks(); } } } if (mode == "Priority-Preemptive") { fill_tasks_map(); float First_key = tasks_map.Keys.First(); // current_tasks = tasks_map[First_key]; // tasks_map.Remove(First_key); update_current_tasks(); if (tasks_map.Count != 0) { First_key = tasks_map.Keys.First(); } while (current_tasks.Count != 0) { running_task = current_tasks.First(); current_tasks.RemoveAt(0); run_preemptive(); //run the running task if ((current_tasks.Count == 0) && (tasks_map.Count != 0)) //|| ((tasks_map.Count != 0) && Timer + current_tasks.First().duration > First_key)) { update_current_tasks(); } } } if (mode == "Round_Robin") { fill_tasks_map(); update_queue(); while (round_robin_queue.Count != 0) { running_task = round_robin_queue.Dequeue(); run_round(); if ((round_robin_queue.Count == 0) && (tasks_map.Count != 0)) { update_queue(); } } } }
private void preempt() { bool eli_geh_ahm = false; bool fi_task_gya_w_hya_48ala = true; // for(int i=0;i<tasks_map.Count;i++) while (fi_task_gya_w_hya_48ala) { if (tasks_map.Count != 0) { if (mode == "SJF-Preemptive") { if (tasks_map.First().Value.First().remaining_time < (running_task.remaining_time - tasks_map.First().Key)) { eli_geh_ahm = true; } } else// (mode == "Priority-Preemptive") { if (tasks_map.First().Value.First().priority < running_task.priority) { eli_geh_ahm = true; } } if (eli_geh_ahm)//lw eli geh 2at3 { eli_geh_ahm = false; float First_key = tasks_map.Keys.First(); running_task.start_time = Timer; Timer = First_key; //running the current task till the new one come running_task.finish_time = Timer; running_task.remaining_time = running_task.remaining_time - (Timer - running_task.start_time); //set remaining time if (running_task.remaining_time == 0) //lw 5lst matrg3ha4 le el current_tasks { running_task.finished = true; task Temp = new task(running_task); finished_tasks.Add(Temp); } else { task temp2 = new task(running_task); current_tasks.Add(temp2); task Temp = new task(running_task); finished_tasks.Add(Temp); } update_current_tasks(); return; } else//lw eli geh ma2t34 { //eli_geh_ma2t34 = true; update_current_tasks(); if (tasks_map.Count != 0) { if (Timer + running_task.remaining_time < tasks_map.First().Key) { fi_task_gya_w_hya_48ala = false; } } else { fi_task_gya_w_hya_48ala = false; } running_task.start_time = Timer; } } else { break;//ya3ni mafi4 7aga gya tani w enta 43'al } } //kda yeb2a el task 5lst w mfi4 7aga gat aham running_task.start_time = Timer; Timer = Timer + running_task.remaining_time; running_task.finish_time = Timer; running_task.finished = true; running_task.remaining_time = 0; task temp = new task(running_task); finished_tasks.Add(temp); }
private void button1_Click(object sender, EventArgs e)//insr=ert_task { float arrival_time = 0; int priority = 0; float duration = 0; float RRBTX = 0; string name = ""; dataGridView1.Visible = true; if (String.IsNullOrEmpty(Nametx.Text)) { Nametx.Text = "task" + (sc.tasks.Count + 1); } else { name = Nametx.Text; } if (String.IsNullOrEmpty(arrivaltx.Text)) { arrival_time = 0; } else { arrival_time = Convert.ToSingle(arrivaltx.Text); } if (String.IsNullOrEmpty(prioritytx.Text)) { priority = 0; } else { priority = Convert.ToInt32(prioritytx.Text); } if (String.IsNullOrEmpty(dutx.Text)) { duration = 0; } else { duration = Convert.ToSingle(dutx.Text); } if (String.IsNullOrEmpty(RRBtx.Text)) { if (sc.mode == "Round_Robin") { RRBTX = sc.burst; } else { RRBTX = 0; } } else { RRBTX = Convert.ToSingle(RRBtx.Text); sc.burst = RRBTX; } dt.Rows.Add(Nametx.Text, arrival_time, priority, duration, RRBTX); this.dataGridView1.DataSource = dt; task t = new task(duration, arrival_time, priority, Nametx.Text); sc.tasks.Add(t); sc.no_tasks++; Nametx.Clear(); arrivaltx.Clear(); dutx.Clear(); RRBtx.Clear(); prioritytx.Clear(); }