Beispiel #1
0
        /// <summary>
        ///  Sets up the genetic algorithm to be ready for the evolutionary search.
        /// </summary>
        /// <param name="randomSeed">The random seed to be used for the RNG of the
        /// genetic algorithm. When left empty, a seed is generated based on the
        /// current date and time.</param>
        void initializeGA(int?randomSeed = null)
        {
            if (randomSeed == null)
            {
                randomSeed = DateTime.Now.GetHashCode();
            }
            ga = new GeneticAnnealingAlgorithm(fitnessFunction, new Random(randomSeed.Value));

            Console.WriteLine("Search space dimension: " + searchSpaceBase.Count);

            int populationSize = (int)(populationModifier * searchSpaceBase.Count);

            maxGeneration = (int)(durationModifier * searchSpaceBase.Count);
            int dnaLength = searchSpaceBase.Count; // Just being verbose.

            ga.InitializeEvolution(populationSize, maxGeneration, dnaLength);
        }
Beispiel #2
0
        /// <summary>
        ///  Tells the genetic algorithm to advance one generation and processes
        ///  the resulting (possibly) improved solution.
        /// </summary>
        public void EvolutionStep()
        {
            if (!_initialized)
            {
                throw new InvalidOperationException("Solver not initialized!");
            }

            ga.NewGeneration();

            if ((_bestDNA == null) || (GeneticAnnealingAlgorithm.SetBits(ga.GetBestDNA().Xor(_bestDNA)) != 0))
            {
                _bestDNA = ga.GetBestDNA();
                MinimalSpanningTree bestMst = dnaToMst(_bestDNA);
                bestMst.Span(startFrom: startNodes);

                // #DEBUG#: Pass true to show the used steiner nodes.
                BestSolution = SpannedMstToSkillnodes(bestMst, false);
            }
        }
Beispiel #3
0
        /// <summary>
        ///  Sets up the genetic algorithm to be ready for the evolutionary search.
        /// </summary>
        /// <param name="randomSeed">The random seed to be used for the RNG of the
        /// genetic algorithm. When left empty, a seed is generated based on the
        /// current date and time.</param>
        void initializeGA(int? randomSeed = null)
        {
            if (randomSeed == null) randomSeed = DateTime.Now.GetHashCode();
            ga = new GeneticAnnealingAlgorithm(fitnessFunction, new Random(randomSeed.Value));

            Console.WriteLine("Search space dimension: " + searchSpaceBase.Count);

            int populationSize = (int)(populationModifier * searchSpaceBase.Count);
            maxGeneration = (int)(durationModifier * searchSpaceBase.Count);
            int dnaLength = searchSpaceBase.Count; // Just being verbose.

            ga.InitializeEvolution(populationSize, maxGeneration, dnaLength);
        }