Esempio n. 1
0
        public TSPSolution solve(TSPInput input)
        {
            TSPSolution best = null;

            for (int r = 0; r < 5; ++r)
            {
                Console.WriteLine($@"== RUN:{r} ==");
                population.Clear();
                for (int i = 0; i < PopulationSize; ++i)
                {
                    population.Add(getRandomSolution(input));
                }
                run();

                var tmp = GetBest();
                Console.WriteLine($@"Distance: {tmp.totalDistance}");

                if (best == null || tmp.totalDistance < best.totalDistance)
                {
                    best = tmp;
                }
            }
            visualizer.draw(best);
            return(best);
        }
Esempio n. 2
0
        public TSPSolution solve(TSPInput input)
        {
            Console.WriteLine("Hill climbing started");
            current     = initialize(input);
            currentBest = current.convertToTSPSol();
            visualizer.draw(currentBest);
            stop = false;
            int steps = 0;

            while (!stop)
            {
                steps++;
                goOneStep();
                if (steps % 10 == 0)
                {
                    currentBest = current.convertToTSPSol();
                    visualizer.draw(currentBest);
                    Console.WriteLine("Steps: " + steps + " Best distance: " + currentBest.totalDistance);
                }
            }
            Console.WriteLine("Search ended");
            currentBest = current.convertToTSPSol();
            visualizer.draw(currentBest);
            Console.WriteLine("Steps: " + steps + " Best distance: " + currentBest.totalDistance);
            return(currentBest);
        }
Esempio n. 3
0
File: Form1.cs Progetto: vvancak/ai
 private void button1_Click(object sender, EventArgs e)
 {
     inp = TSPGenerator.generateUniform(int.Parse(NodesCount_textBox.Text));
     vis.draw(inp);
 }