Exemplo n.º 1
0
 public AlgorithmExecutor(
     List<City> cities,
     City depot,
     int numberOfDrones,
     int numberOfGenerations,
     int populationSize,
     double crossoverProbability,
     double mutationProbability,
     bool fitnessConsidersPartitions,
     bool isCalibration)
 {
     CITIES = cities;
     DEPOT = depot;
     NUMBER_OF_CITIES = cities.Count;
     NUMBER_OF_DRONES = numberOfDrones;
     NUMBER_OF_GENERATIONS = numberOfGenerations;
     POPULATION_SIZE = populationSize;
     CROSSOVER_PROBABILITY = crossoverProbability;
     MUTATION_PROBABILITY = mutationProbability;
     FITNESS_CONSIDERS_PARTITIONS = fitnessConsidersPartitions;
     IS_CALIBRATION = isCalibration;
 }
Exemplo n.º 2
0
 public PartitionAlgorithm(List<City> TSPSequence, City depot, int numberOfDrones)
 {
     cities = TSPSequence;
     this.depot = depot;
     this.numberOfDrones = numberOfDrones;
 }
Exemplo n.º 3
0
        // Runs the GA with the given parameters.
        private static void runGAWithParams(
            string fileName,
            int numberOfDrones,
            bool fitnessConsidersPartitions,
            int population,
            double crossover,
            double mutation,
            int numberOfGenerations)
        {
            NUMBER_OF_DRONES = numberOfDrones;
            var lines = File.ReadAllLines(fileName + ".txt");
            foreach (var line in lines)
            {
                string[] coords = line.Split(' ');
                if (coords[0].Equals("1"))
                {
                    DEPOT = new City("Depot", double.Parse(coords[1]), double.Parse(coords[2]));
                }
                else
                {
                    CITIES.Add(new City("City " + coords[0], double.Parse(coords[1]), double.Parse(coords[2])));
                }
            }

            AlgorithmExecutor executor = new AlgorithmExecutor(
                CITIES, DEPOT, NUMBER_OF_DRONES, numberOfGenerations, population, crossover, mutation,
                    fitnessConsidersPartitions, false /* isCalibration */);
            executor.RunGAInstance();

            // Write the results from the simulation with the given number of drones
            // to the specified file.
            Utils.writeResultsToFile(fileName, numberOfDrones);

            CITIES.Clear();
        }
Exemplo n.º 4
0
        private static void Main(string[] args)
        {
            CITIES = new List<City>();

            Console.WriteLine("To run the calibration mode (100 random instances), press 'C' or 'c' and then ENTER.");
            Console.WriteLine("The results will then be stored as 'output_strat1.txt' and 'output_strat2.txt'.");
            Console.WriteLine("Otherwise, press just ENTER and the application will run the 3 sample instances.");

            // Read user input.
            string input = Console.ReadLine();

            if (input != "c" && input != "C")
            {
                List<string> inputFiles = new List<string>();
                // Add the input files.
                inputFiles.Add("eil51");
                inputFiles.Add("eil76");
                inputFiles.Add("rat99");

                for (int i = 0; i < inputFiles.Count; i++)
                {
                    string inputFile = inputFiles[i];

                    // Run GA with selected parameters three times: for 2, 3 and 5 travelers.

                    // Running for the case that fitness calculates the cost of TSP.
                    runGAWithParams(inputFile, 2, false, 200, 0.6, 0.1, NUMBER_OF_GENERATIONS_STRAT_1);
                    runGAWithParams(inputFile, 3, false, 200, 0.6, 0.1, NUMBER_OF_GENERATIONS_STRAT_1);
                    runGAWithParams(inputFile, 5, false, 200, 0.6, 0.1, NUMBER_OF_GENERATIONS_STRAT_1);

                    // Running for the case that fitness calculates the cost of mTSP
                    // using the greedy algorithm.
                    runGAWithParams(inputFile, 2, true, 200, 1, 0, NUMBER_OF_GENERATIONS_STRAT_2);
                    runGAWithParams(inputFile, 3, true, 200, 1, 0, NUMBER_OF_GENERATIONS_STRAT_2);
                    runGAWithParams(inputFile, 5, true, 200, 1, 0, NUMBER_OF_GENERATIONS_STRAT_2);
                }
            }
            else
            {
                DEPOT = new City("Depot", 0.0, 0.0);
                CITIES = Utils.CreateCities().ToList();

                // 100 test cases runs for both approaches.
                calibrateGA(false /* fitnessConsidersPartitions */, NUMBER_OF_GENERATIONS_CALIBRATION_STRAT_1);
                calibrateGA(true /* fitnessConsidersPartitions */, NUMBER_OF_GENERATIONS_CALIBRATION_STRAT_2);
            }

            Console.WriteLine("SIMULATION ENDED.");
            Console.ReadLine();
        }
Exemplo n.º 5
0
 public GreedyAlgorithm(List<City> TSPSequence, City depot, int numberOfDrones)
     : base(TSPSequence, depot, numberOfDrones)
 {
 }