private void PriorityPlaninig_Click(object sender, EventArgs e) { if (!CreateProccess()) { return; } noActive(); PriorityPlaninig.BackColor = activeColor; int tact; List <Proccess> readyProccess = new List <Proccess>(); int count_ready_proccess = 0; for (tact = 0; count_ready_proccess < 5;) { for (int i = 0; i < stack.Count; i++) { if (stack[i].tacts_to_ready <= 0 && stack[i].end_work_tact == 0) { readyProccess.Add(stack[i]); } } if (readyProccess.Count > 1) { readyProccess.Sort(delegate(Proccess P1, Proccess P2) { return(P1.priority.CompareTo(P2.priority)); }); } else if (readyProccess.Count == 0) { tact++; for (int i = 0; i < stack.Count; i++) { stack[i].tacts_to_ready--; } continue; } Proccess curProc = stack.Find(delegate(Proccess proc) { return(proc.name == readyProccess[0].name); }); readyProccess.Clear(); curProc.start_work_tact = tact; curProc.tacts_of_wait = tact - curProc.start_ready_tact; tact += curProc.tacts_of_work; curProc.end_work_tact = tact; for (int i = 0; i < stack.Count; i++) { stack[i].tacts_to_ready -= curProc.tacts_of_work; } count_ready_proccess++; } drowResultDiagramm(tact); }
private void FCFS_Click(object sender, EventArgs e) { if (!CreateProccess()) { return; } noActive(); FCFS.BackColor = activeColor; stack.Sort( delegate(Proccess P1, Proccess P2) { return(P1.start_ready_tact.CompareTo(P2.start_ready_tact)); } ); int count_ready_proccess = 0; int tact = 0; while (count_ready_proccess < 5) { Proccess curProc = null; for (int i = 0; i < stack.Count; i++) { if (stack[i].tacts_to_ready <= 0 && stack[i].end_work_tact == 0) { curProc = stack[i]; break; } } if (curProc == null) { tact++; continue; } curProc.start_work_tact = tact; curProc.tacts_of_wait = curProc.start_work_tact - curProc.start_ready_tact; if (curProc.start_ready_tact > tact) { tact += curProc.start_ready_tact; } tact += curProc.tacts_of_work; curProc.end_work_tact = tact; for (int i = 0; i < stack.Count; i++) { stack[i].tacts_to_ready -= curProc.tacts_of_work; } count_ready_proccess++; } drowResultDiagramm(tact); }