Exemplo n.º 1
0
        public void Start()
        {
            RandomizeLocations();
            State alpha = new State();

            alpha.AddCityToPath(SearchInfo.AllCities[0]);
            switch ((Algorithm)method)
            {
            case Algorithm.BruteForceDSF:
            {
                tspAlg = new BruteForceDFS_TSPAlgorithm(SearchInfo, DrawingBoard);
                break;
            }

            case Algorithm.BruteForceBSF:
            {
                tspAlg = new BruteForceBFS_TSPAlgorithm(SearchInfo, DrawingBoard);
                break;
            }

            case Algorithm.GreedyAlgorithm:
            {
                tspAlg = new TSPGreedyAlgorithm(SearchInfo, DrawingBoard);
                break;
            }

            case Algorithm.GeneticAlgorithm:
            {
                tspAlg = new TSPGeneticAlgorithm(SearchInfo, DrawingBoard);
                break;
            }
            }
            states = tspAlg.ChildStates(alpha);
        }
 public AlgorithmExecutor(TSPAlgorithm algorithm, int numberOfExecutions)
 {
     NumberOfExecutions = numberOfExecutions;
     ArrayOfBestResults = new double[numberOfExecutions];
     Algorithm          = algorithm;
     Informations.AppendLine(algorithm.GetInformations());
     AlgorithmStatistics = new double[numberOfExecutions][];
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            int              populationSize        = 10;
            int              numberOfEpoch         = 50;
            int              numberOfExecution     = 1;
            double           probabilityOfMutation = 0.1;
            string           file            = @"WesternSahara.txt";
            Cities           testCities      = new Cities(file);
            IParentSelection parentSelection = new TournamentSelection();
            ICrossover       crossover       = new PMX();
            IMutation        mutation        = new InsertionMutation(probabilityOfMutation);
            string           filename        = DateTime.Now.ToString("yyyy-MM-dd HH;mm");

            //Test 1 - PMX
            TSPAlgorithm      tsp = new TSPAlgorithm(numberOfEpoch, populationSize, testCities, parentSelection, mutation, crossover);
            AlgorithmExecutor AE  = new AlgorithmExecutor(tsp, numberOfExecution);

            AE.Start();
            AE.SaveInformations(filename + ".txt");
            //AE.ExportStatisticsToCsv(filename + "_stats.csv");



            /* Test 2 - CX
             * crossover = new CX();
             * tsp = new TSPAlgorithm(numberOfEpoch, populationSize, testCities, parentSelection, mutation, crossover);
             * AE = new AlgorithmExecutor(tsp, numberOfExecution);
             * AE.Start();
             * AE.SaveInformations(filename + ".txt");
             * AE.ExportStatisticsToCsv(filename + "_stats.csv");
             *
             * // Test 3 - OX
             * crossover = new OX();
             * tsp = new TSPAlgorithm(numberOfEpoch, populationSize, testCities, parentSelection, mutation, crossover);
             * AE = new AlgorithmExecutor(tsp, numberOfExecution);
             * AE.Start();
             * AE.SaveInformations(filename + ".txt");
             * AE.ExportStatisticsToCsv(filename + "_stats.csv");
             *
             * // Test 4 - AEX
             * crossover = new AEX();
             * tsp = new TSPAlgorithm(numberOfEpoch, populationSize, testCities, parentSelection, mutation, crossover);
             * AE = new AlgorithmExecutor(tsp, numberOfExecution);
             * AE.Start();
             * AE.SaveInformations(filename + ".txt");
             * AE.ExportStatisticsToCsv(filename + "_stats.csv");
             *
             * // Test 5 - SCC
             * crossover = new SCC();
             * tsp = new TSPAlgorithm(numberOfEpoch, populationSize, testCities, parentSelection, mutation, crossover);
             * AE = new AlgorithmExecutor(tsp, numberOfExecution);
             * AE.Start();
             * AE.SaveInformations(filename + ".txt");
             * AE.ExportStatisticsToCsv(filename + "_stats.csv");
             *
             * //Test 6 - SCC
             * crossover = new ClassicalCrossover();
             * mutation = new ClassicMutationInOrdinalRepresentation(probabilityOfMutation);
             * tsp = new TSPAlgorithm(numberOfEpoch, populationSize, testCities, parentSelection, mutation, crossover);
             * AE = new AlgorithmExecutor(tsp, numberOfExecution);
             * AE.Start();
             * //AE.SaveInformations(filename + ".txt");
             * //AE.ExportStatisticsToCsv(filename + "_stats.csv");
             */
            Console.ReadKey();
        }