/// <summary> /// Initializes a new optimization run. /// </summary> /// <param name="parameters">The parameters to initialize the algorithm with</param> /// <param name="initialSolution">The solution to initialize the population with</param> public void InitializeEvolution(GeneticAlgorithmParameters parameters, BitArray initialSolution = null) { _populationSize = parameters.PopulationSize; MaxGeneration = parameters.MaxGeneration; _dnaLength = parameters.DnaLength; _temperature = parameters.Temperature; _annealingFactor = parameters.AnnealingFactor; _maxMutateClusterSize = parameters.MaxMutateClusterSize; _initialSolution = initialSolution ?? new BitArray(_dnaLength); // Make sure there is a valid solution in case _populationSize is 0. _bestSolution = new Individual(_initialSolution, 0); _population = CreatePopulation(); GenerationCount = 0; UpdateBestSolution(); }
/// <summary> /// Initializes a new optimization run. /// </summary> /// <param name="parameters">The parameters to initialize the algorithm with</param> /// <param name="initialSolution">The solution to initialize the population with</param> public void InitializeEvolution(GeneticAlgorithmParameters parameters, BitArray initialSolution = null) { _populationSize = parameters.PopulationSize; _dnaLength = parameters.DnaLength; _temperature = parameters.Temperature; _initialTemperature = _temperature; _annealingFactor = parameters.AnnealingFactor; _maxMutateClusterSize = parameters.MaxMutateClusterSize; CurrentIteration = 0; _initialSolution = initialSolution ?? new BitArray(_dnaLength); // Make sure there is a valid solution in case _populationSize is 0. _bestSolution = new Individual(_initialSolution, 0); _population = CreatePopulation(); GenerationCount = 0; UpdateBestSolution(); }