private static void SwapPoorWatingSlot(ref Maintainance schedule, List <ColumnRank> improveColumns, ref bool isChanged) { foreach (var i in improveColumns.Where(f => f.IsPoor.Value == true)) //Take poor ranks { #if true int countPoor = improveColumns.Count(f => f.IsPoor.Value == true); #endif List <ColumnRank> destCols = improveColumns.FindAll(f => f.ColumnIndex != i.ColumnIndex && f.IsPoor.Value == true); if (destCols.Count > 0) { int selectedPoorIndex = new Random(Guid.NewGuid().GetHashCode()).Next(0, destCols.Count - 1); if (destCols.Count == 2) { selectedPoorIndex = Convert.ToInt32(Math.Abs(Guid.NewGuid().GetHashCode() % 2)); } ColumnRank swapCol = destCols.ElementAt(selectedPoorIndex); if (schedule.Slot[swapCol.ColumnIndex] != null && schedule.Slot[i.ColumnIndex] != null) { //Swap objects Program.SwapRef(ref schedule.Slot[swapCol.ColumnIndex], ref schedule.Slot[i.ColumnIndex]); isChanged = true; i.IsPoor = false; break; } } else { Trace.WriteLine("Poor column were not found!"); } } }
public static List <ColumnRank> GetRankedColumns(List <Maintainance> sourceSchedules) { List <Maintainance> schedules = sourceSchedules.ToList(); List <EmptySlot> cFixation = new List <EmptySlot>(); List <ColumnRank> cColumnRank = new List <ColumnRank>(); //Ranking matrix for (int i = 0; i < schedules.Count; i++) { for (int j = 0; j < Program.MAX_AIR; j++) { cFixation.Add(new EmptySlot() { Row = i, Col = j, IsEmpty = schedules[i].Slot[j] == null }); } } for (int j = 0; j < Program.MAX_AIR; j++) { ColumnRank jColumnRank = new ColumnRank() { ColumnIndex = j }; for (int i = 0; i < schedules.Count; i++) { jColumnRank.TotalAir += schedules[i].Slot[j] == null ? 0 : 1; jColumnRank.TotalWating += schedules[i].Slot[j] == null ? 0 : schedules[i].Slot[j].WaitingDurationLog; } cColumnRank.Add(jColumnRank); } cColumnRank = (from r in cColumnRank orderby r.TotalWating descending select r).ToList(); int count = 0; for (int i = 0; i < cColumnRank.Count; i++) { ColumnRank iColumnRank = cColumnRank[i]; iColumnRank.IsPoor = count++ < Program.MAX_AIR / 2; } return(cColumnRank.ToList()); }
private static Maintainance SwapSlot(Maintainance schedule, List <ColumnRank> improveColumns, List <ColumnRank> allRankedColumns) { foreach (var i in improveColumns) { List <ColumnRank> destCols = allRankedColumns.FindAll(f => { return(!improveColumns.Exists(g => g.ColumnIndex == f.ColumnIndex)); }); if (destCols.Count > 0) { int selectedPoorIndex = new Random(Guid.NewGuid().GetHashCode()).Next(0, destCols.Count - 1); if (destCols.Count == 2) { selectedPoorIndex = Convert.ToInt32(Math.Abs(Guid.NewGuid().GetHashCode() % 2)); } else if (destCols.Count == 1) { } ColumnRank swapCol = destCols.ElementAt(selectedPoorIndex); Air iDestAir = schedule.Slot[swapCol.ColumnIndex]; if (iDestAir != null) { //Clone Air object from destination array then remove it. Air sourceAir = schedule.Slot[swapCol.ColumnIndex]; schedule.Slot[swapCol.ColumnIndex] = null; //Assign cloning object to improve index. schedule.Slot[i.ColumnIndex] = sourceAir; } } else { Trace.WriteLine("Poor column were not found!"); } } return(schedule); }