public Annealing(string path) { seatInfo = new SeatInfo(); seatInfo.ReadFile(path); bestSoFar = new SeatingChart(seatInfo); bestSoFar.RandomChart(); }
public Annealing(string path) { seatInfo = new SeatInfo(); seatInfo.ReadFile(path); bestSoFar = new SeatingChart(seatInfo); bestSoFar.RandomChart(); }
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; }