Пример #1
0
        public static double FindShortestPath(OptimizationParameters optimizationParameters, CancellationToken ct, int seed = 0)
        {
            seed = GetSeed(seed);
            var random = new Random(seed);
            var matrix = Files.ReadArray(optimizationParameters.DataPath);

            Distances.Create(matrix);
            return(PathFinding.ShortestPath.Find(PointsArrayGenerator.GeneratePointsToVisit(matrix.Length), optimizationParameters, ct, random));
        }
Пример #2
0
        public static void FindShortestPath(OptimizationParameters optimizationParameters,
                                            DelegateFitness.CalcFitness calcFitness, int seed = 0)
        {
            seed = GetSeed(seed);
            var random = new Random(seed);
            var matrix = Files.ReadArray(optimizationParameters.DataPath);

            Distances.Create(matrix);
            PathFinding.ShortestPath.Find(PointsArrayGenerator.GeneratePointsToVisit(matrix.Length), optimizationParameters, calcFitness, CancellationToken.None, random);
        }
Пример #3
0
        public static TSPResult TSP(OptimizationParameters optimizationParameters, CancellationToken ct, int seed = 0)
        {
            seed = GetSeed(seed);
            var random = new Random(seed);

            var matrix = Files.ReadArray(optimizationParameters.DataPath);

            Distances.Create(matrix);
            var tsp = new GeneticTSP(PointsArrayGenerator.GeneratePointsToVisit(matrix.Length), optimizationParameters,
                                     (population) =>
            {
                double[] fitness = new double[population.Length];
                for (int i = 0; i < population.Length; i++)
                {
                    fitness[i] = Fitness.CalculateFitness(population[i]);
                }
                return(fitness);
            }, ct, random);
            var result = tsp.Run();

            result.Seed = seed;
            return(result);
        }