public GeneticPathFinding(int[] order, OptimizationParameters parameters, DelegateFitness.CalcFitness calcFitness, CancellationToken ct, Random random) { var populationInitialization = new StandardPathInitialization(random); var population = populationInitialization.InitializePopulation(order, parameters.PopulationSize, 0); _genetic = new BaseGenetic(parameters, population, calcFitness, ct, random); }
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); }
public GeneticWarehouse(OptimizationParameters optimizationParameters, int warehouseSize, DelegateFitness.CalcFitness calcFitness, CancellationToken ct, Random random) { _warehouseSize = warehouseSize; int[] itemsToSort = new int[_warehouseSize]; for (int i = 1; i < _warehouseSize; i++) { itemsToSort[i - 1] = i; } var populationInitialization = new StandardPathInitialization(random); var population = populationInitialization.InitializePopulation(itemsToSort, optimizationParameters.PopulationSize, 0); _genetic = new BaseGenetic(optimizationParameters, population, calcFitness, ct, random); wm = new WarehouseModule(); _genetic.LoadModule(wm); }
public GeneticTSP(int[] order, OptimizationParameters parameters, DelegateFitness.CalcFitness calcFitness, CancellationToken ct, Random random) { _use2opt = parameters.Use2opt; var populationInitialization = GeneticFactory.CreatePopulationInitialization(parameters.PopulationInitializationMethod, random); var population = populationInitialization.InitializePopulation(order, parameters.PopulationSize, parameters.StartingId); _genetic = new BaseGenetic(parameters, population, calcFitness, ct, random); if (parameters.StopAfterEpochsWithoutChange) { _genetic.LoadModule(new TerminationModule(parameters.StopAfterEpochCount)); } if (parameters.EnableCataclysm) { _genetic.LoadModule(new CataclysmModule(populationInitialization, parameters.DeathPercentage, parameters.CataclysmEpoch)); } _tspModule = new TSPModule(); _tspModule.LoadCrossoverOperator(_genetic.Crossover); _genetic.LoadModule(_tspModule); }
public static double Find(int[] order, OptimizationParameters optimizationParameters, DelegateFitness.CalcFitness calcFitness, CancellationToken ct, Random random) { IPathFinder algorithmPathFinding = optimizationParameters.OptimizationMethod switch { OptimizationMethod.Permutations => new Permutations(optimizationParameters), OptimizationMethod.NearestNeighbor => new NearestNeighbor(optimizationParameters), OptimizationMethod.GeneticAlgorithm => new GeneticPathFinding(order, optimizationParameters, calcFitness, ct, random), _ => throw new ArgumentException("Incorrect optimization method in config file") }; int[] objectOrder = algorithmPathFinding.FindShortestPath(order); double pathLength = Fitness.CalculateFitness(objectOrder); if (optimizationParameters.ResultToFile) { Log log = new Log(optimizationParameters); log.SaveResult(objectOrder, pathLength); } return(pathLength); }