Ejemplo n.º 1
0
        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 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);
        }