public Annealing(string path) { seatInfo = new SeatInfo(); seatInfo.ReadFile(path); bestSoFar = new SeatingChart(seatInfo); bestSoFar.RandomChart(); }
public static void Copy(SeatingChart src, out SeatingChart desc) { desc = new SeatingChart(src.seatInfo); Array.Copy(src.chart, desc.chart, src.size + 1); desc.score = src.score; desc.score = src.score; }
public Annealing(string path) { seatInfo = new SeatInfo(); seatInfo.ReadFile(path); bestSoFar = new SeatingChart(seatInfo); bestSoFar.RandomChart(); }
public static void Copy(SeatingChart src, out SeatingChart desc) { desc = new SeatingChart(src.seatInfo); Array.Copy(src.chart, desc.chart, src.size + 1); desc.score = src.score; desc.score = src.score; }
public SeatingChart Anneal() { DateTime due = DateTime.Now.AddMinutes(1); System.IO.StreamWriter debug = new System.IO.StreamWriter(@"..\..\debug.txt"); SeatingChart current = null; while (DateTime.Now <= due) { double temp = INITIAL_TEMP; if (current == null) { current = new SeatingChart(seatInfo); current.RandomChart(); } if (bestSoFar.score > current.score) { SeatingChart.Copy(bestSoFar, out current); } else { SeatingChart.Copy(current, out bestSoFar); } while (temp > FINAL_TEMP) { //Console.WriteLine("Temp = " + temp); for (int i = 0; i < STEPS_PER_CHANGE; ++i) { //debug.Write(temp + "; "); bool accepted = false; SeatingChart working; SeatingChart.Copy(current, out working); working.SmallTweak(); if (working.score > current.score) { accepted = true; } else { accepted = LoveMeNot(working.score, current.score, temp); } if (accepted) { SeatingChart.Copy(working, out current); if (current.score > bestSoFar.score) { SeatingChart.Copy(current, out bestSoFar); } } //debug.WriteLine(working.ToString() + " " + accepted); } temp = temp * ALPHA; } } debug.Close(); return(bestSoFar); }
public SeatingChart Anneal() { DateTime due = DateTime.Now.AddMinutes(1); System.IO.StreamWriter debug = new System.IO.StreamWriter(@"..\..\debug.txt"); SeatingChart current = null; while (DateTime.Now <= due) { double temp = INITIAL_TEMP; if (current == null) { current = new SeatingChart(seatInfo); current.RandomChart(); } if (bestSoFar.score > current.score) { SeatingChart.Copy(bestSoFar, out current); } else { SeatingChart.Copy(current, out bestSoFar); } while (temp > FINAL_TEMP) { //Console.WriteLine("Temp = " + temp); for (int i = 0; i < STEPS_PER_CHANGE; ++i) { //debug.Write(temp + "; "); bool accepted = false; SeatingChart working; SeatingChart.Copy(current, out working); working.SmallTweak(); if (working.score > current.score) { accepted = true; } else { accepted = LoveMeNot(working.score, current.score, temp); } if (accepted) { SeatingChart.Copy(working, out current); if (current.score > bestSoFar.score) { SeatingChart.Copy(current, out bestSoFar); } } //debug.WriteLine(working.ToString() + " " + accepted); } temp = temp * ALPHA; } } debug.Close(); return bestSoFar; }
public Annealing(SeatInfo si) { seatInfo = si; bestSoFar = new SeatingChart(si); bestSoFar.InitializeChart(); }
public Annealing(SeatInfo si) { seatInfo = si; bestSoFar = new SeatingChart(si); bestSoFar.InitializeChart(); }
static void Main(string[] args) { DateTime start = DateTime.Now; if (args.Length == 0) { Console.WriteLine("Argument: "); Console.WriteLine("c <file>: complete space state search using seating info from <file>"); Console.WriteLine("l <file>: local search using seating info from <file>"); Console.WriteLine("s <file>: stimulated annealing using seating info from <file>"); Console.WriteLine("a <file>: auto mode. Will try the most suitable search method"); return; } SeatInfo si = new SeatInfo(); si.ReadFile(args[1]); chart = new int[si.size + 1]; score = 0; switch (args[0]) { case "c": Console.Write("Complete search..."); CompleteSearch(si); break; case "l": Console.Write("Local search... "); StochasticSearch(si); break; case "s": Console.WriteLine("Stimulated annealing... "); Annealing sa = new Annealing(si); SeatingChart sc = sa.Anneal(); Array.Copy(sc.chart, chart, sc.size + 1); score = sc.score; break; case "a": if (si.size <= 11) { Console.Write("Complete search..."); CompleteSearch(si); } else { Console.Write("Local search... "); StochasticSearch(si); } break; default: Console.WriteLine("Argument: "); Console.WriteLine("c <file>: complete space state search using seating info from <file>"); Console.WriteLine("l <file>: local search using seating info from <file>"); Console.WriteLine("s <file>: stimulated annealing using seating info from <file>"); Console.WriteLine("a <file>: auto mode. Will try the most suitable search method"); return; } if (debug) { si.Display(); } Console.WriteLine(" finished!"); DisplaySeatingChart(chart, score); Console.WriteLine("Run time: " + (DateTime.Now - start)); //int[] a = AssignRandomSeat(10); //for (int i = 1; i <= 10; ++i) //{ // Console.Write(a[i] + ", "); //} Console.ReadLine(); }