private void TickTimer_Tick(object sender, EventArgs e) { maxOperationsCouldBeDone += allPerformance; for (int i = 0; i < computeUnits.Count; i++) { computeUnits[i].Tick(); } if (wasTaskTaken && probabilityGenerator.Generate()) { taskToDo = new Task(); shuffeledAbleUnits = new List <int>(taskToDo.GetUnitsFit()); ListViewItem taskListViewItem = new ListViewItem(new string[] { taskToDo.Task_id.ToString(), taskToDo.Complexity.ToString(), String.Join(", ", taskToDo.GetUnitsFit()) }); TasksListView.Items.Add(taskListViewItem); shuffeledAbleUnits.Shuffle(); wasTaskTaken = false; } if (!wasTaskTaken) { for (int i = 0; i < shuffeledAbleUnits.Count; i++) { if (computeUnits[shuffeledAbleUnits[i] - 1].AddTaskFIFO(taskToDo.Complexity)) { ListViewItem unitListViewItem = new ListViewItem(new string[] { taskToDo.Task_id.ToString(), taskToDo.Complexity.ToString(), String.Join(", ", taskToDo.GetUnitsFit()) }); switch (shuffeledAbleUnits[i]) { case 1: unitListView1.Items.Add(unitListViewItem); break; case 2: unitListView2.Items.Add(unitListViewItem); break; case 3: unitListView3.Items.Add(unitListViewItem); break; case 4: unitListView4.Items.Add(unitListViewItem); break; case 5: unitListView5.Items.Add(unitListViewItem); break; } wasTaskTaken = true; return; } } } }
private void TickTimer_Tick(object sender, EventArgs e) { maxOperationsCouldBeDone += allPerformance; for (int i = 0; i < computeUnits.Count; i++) { computeUnits[i].Tick(); } if (wasTaskTaken && probabilityGenerator.Generate()) { taskToDo = new Task(); AbleUnits = new List <int>(taskToDo.GetUnitsFit()); ListViewItem taskListViewItem = new ListViewItem(new string[] { taskToDo.Task_id.ToString(), taskToDo.Complexity.ToString(), String.Join(", ", taskToDo.GetUnitsFit()) }); TasksListView.Items.Add(taskListViewItem); wasTaskTaken = false; } if (!wasTaskTaken) { List <int> Schedule_unit_num = new List <int>() { SchedUnitPos + 1 }; ScheduleTask = new Task(0, Schedule_unit_num); computeUnits[SchedUnitPos].AddTaskSchedWeak(ScheduleTask.Complexity); ListViewItem unitListViewItem1 = new ListViewItem(new string[] { ScheduleTask.Task_id.ToString(), ScheduleTask.Complexity.ToString(), String.Join(", ", ScheduleTask.GetUnitsFit()) }); switch (SchedUnitPos + 1) { case 1: unitListView1.Items.Add(unitListViewItem1); break; case 2: unitListView2.Items.Add(unitListViewItem1); break; case 3: unitListView3.Items.Add(unitListViewItem1); break; case 4: unitListView4.Items.Add(unitListViewItem1); break; case 5: unitListView5.Items.Add(unitListViewItem1); break; } int freest_unit_pos = 0; for (int i = 0; i < AbleUnits.Count; i++) { if (computeUnits[AbleUnits[i] - 1].GetWorkload() < computeUnits[freest_unit_pos].GetWorkload() && i != SchedUnitPos) { freest_unit_pos = i; } } if (freest_unit_pos == SchedUnitPos) { wasTaskTaken = false; return; } computeUnits[freest_unit_pos].AddTaskSchedWeak(taskToDo.Complexity); ListViewItem unitListViewItem2 = new ListViewItem(new string[] { taskToDo.Task_id.ToString(), taskToDo.Complexity.ToString(), String.Join(", ", taskToDo.GetUnitsFit()) }); switch (freest_unit_pos + 1) { case 1: unitListView1.Items.Add(unitListViewItem2); break; case 2: unitListView2.Items.Add(unitListViewItem2); break; case 3: unitListView3.Items.Add(unitListViewItem2); break; case 4: unitListView4.Items.Add(unitListViewItem2); break; case 5: unitListView5.Items.Add(unitListViewItem2); break; } wasTaskTaken = true; return; } }