Exemple #1
0
        /// <summary>
        /// Constructs a list of binary crossovers operators.
        /// </summary>
        /// <param name="crossoverOptions">The binary crossover options.</param>
        /// <param name="weight">The crossover weight.</param>
        /// <returns>The constructed binary crossovers operators.</returns>
        public static List <ICrossover> ConstructBinaryCrossoverOperators(BinaryCrossover crossoverOptions, double weight = 1)
        {
            var crossovers = new List <ICrossover>();

            if ((crossoverOptions & BinaryCrossover.SinglePoint) == BinaryCrossover.SinglePoint)
            {
                crossovers.Add(new SinglePointCrossover(weight));
            }
            if ((crossoverOptions & BinaryCrossover.TwoPoint) == BinaryCrossover.TwoPoint)
            {
                crossovers.Add(new TwoPointCrossover(weight));
            }
            if ((crossoverOptions & BinaryCrossover.Uniform) == BinaryCrossover.Uniform)
            {
                crossovers.Add(new UniformCrossover(weight));
            }
            if ((crossoverOptions & BinaryCrossover.NoOp) == BinaryCrossover.NoOp)
            {
                crossovers.Add(new NoOpBinaryCrossover(weight));
            }
            if (crossovers.Count == 0)
            {
                throw new ArgumentException("Error! Invalid binary crossover selection.");
            }

            return(crossovers);
        }
Exemple #2
0
        private BinaryChromosome GetCrossover(BinaryChromosome x, BinaryChromosome y, BinaryCrossover crossover)
        {
            var rator = GeneticFactory.ConstructBinaryCrossoverOperators(crossover).First();

            return(rator.Invoke(x, y) as BinaryChromosome);
        }