static public void chooseCandidate() { //shortcut? chosen = new candidate(0); Boolean repeat = true; foreach (candidate c in candList.OrderBy(x => x.objFunc)) { if (!repeat) { break; } foreach (tabuEntry te in tabuList) { if ((c.swap1 == te.swap1 && c.swap2 == te.swap2) || (c.swap1 == te.swap2 && c.swap2 == te.swap1)) { break; } chosen = c.copyTo(chosen); //chosen.objFunc = 0; repeat = false; } } if (chosen.id == 0) { chosen = candList.OrderBy(x => x.objFunc).First(); } Console.WriteLine("Iteration number " + iterNum + " Testing " + chosen.id + " :" + chosen.objFunc + " listLength = " + candList.Count + " " + candList.OrderByDescending(x => x.objFunc).First().objFunc); tabuEntry t = new tabuEntry(iterNum, chosen.swap1, chosen.swap2, tabuCount); tabuList.Add(t); /* * foreach(candidate cc in candList.OrderBy(x => x.objFunc)) * { * Console.WriteLine("Testing " + cc.id + " :" + cc.objFunc + " listLenght = " + candList.Count); * if (chosen.id == -1) * { * chosen = cc; * //cc.tabu = tabuCount; * } * } */ //reduce the candidate list to maintain size if (candList.Count > tabuCount) { int extra = candList.OrderByDescending(x => x.objFunc).First().id; candList.RemoveAt(candList.FindIndex(x => x.id == extra)); } }
static public void swapAssign() { candidate temp = chosen; int s1 = 0; int s2 = 0; if (tabuList.Count == 0) { s1 = chosen.jsOrder[r.Next(0, (jobs - 1))]; s2 = s1; while (s2 != s1) { s2 = chosen.jsOrder[r.Next(0, (jobs - 1))]; } } else { bool repeat = true; while (repeat) { s1 = chosen.jsOrder[r.Next(0, (jobs - 1))]; s2 = s1; while (s2 == s1) { s2 = chosen.jsOrder[r.Next(0, (jobs - 1))]; } //make sure that the values do no exist in the tabu list foreach (tabuEntry te in tabuList) { if ((s1 == te.swap1 && s2 == te.swap2) || (s1 == te.swap2 && s2 == te.swap1)) { break; } repeat = false; } } } tabuEntry t = new tabuEntry(iterNum, s1, s2, tabuCount); tabuList.Add(t); theSwap(s1, s2); }