public static WarehouseResult Optimize(WarehouseParameters warehouseParameters, CancellationToken ct, Random random) { WarehouseManager warehouseManager = new WarehouseManager(); double[][] distancesMatrix = warehouseManager.CreateWarehouseDistancesMatrix(warehouseParameters.WarehousePath); Distances.Create(distancesMatrix); Orders orders = new Orders(warehouseParameters.OrdersPath, warehouseManager.WarehouseSize); GeneticWarehouse geneticWarehouse = new GeneticWarehouse(warehouseParameters.WarehouseGeneticAlgorithmParameters, warehouseManager.WarehouseSize, (population) => { double[] fitness = new double[population.Length]; warehouseParameters.FitnessGeneticAlgorithmParameters.WriteCsv = false; Parallel.For(0, population.Length, i => { var results = Fitness.CalculateAllOrdersFitness(orders, population[i], warehouseParameters.FitnessGeneticAlgorithmParameters, random); fitness[i] = results.Sum(x => x.Fitness); }); return(fitness); }, ct, random); var z = geneticWarehouse.Run(); var result = Fitness.CalculateAllOrdersFitness(orders, z.BestChromosome, warehouseParameters.FitnessGeneticAlgorithmParameters, random); z.FinalFitness = result.Sum(x => x.Fitness); z.FinalOrderPaths = result.Select(x => x.Path).ToArray(); return(z); }
public static WarehouseResult WarehouseOptimization(WarehouseParameters warehouseParameters, CancellationToken ct, int seed = 0) { seed = GetSeed(seed); var random = new Random(seed); var result = WarehouseOptimizer.Optimize(warehouseParameters, ct, random); result.Seed = seed; return(result); }