예제 #1
0
 public Annealing(string path)
 {
     seatInfo = new SeatInfo();
     seatInfo.ReadFile(path);
     bestSoFar = new SeatingChart(seatInfo);
     bestSoFar.RandomChart();
 }
예제 #2
0
 public Annealing(string path)
 {
     seatInfo = new SeatInfo();
     seatInfo.ReadFile(path);
     bestSoFar = new SeatingChart(seatInfo);
     bestSoFar.RandomChart();
 }
예제 #3
0
        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);
        }
예제 #4
0
        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;
        }