Ejemplo n.º 1
0
 public GenoTypeFactory(IEaGeneExpressionParameters eaGeneExpressionParameters, IUniformRandomGenerator uniformRandomGenerator, IParameterTerminalFactory parameterTerminalFactory)
 {
     EaGeneExpressionParameters = eaGeneExpressionParameters;
     UniformRandomGenerator     = uniformRandomGenerator;
     ParameterTerminalFactory   = parameterTerminalFactory;
     NumberOfPossibleFunctions  = EaGeneExpressionParameters.NumberOfPossibleFunctions - 1;
     NumberOfPossibleTerminals  = EaGeneExpressionParameters.NumberOfPossibleTerminals - 1;
 }
Ejemplo n.º 2
0
        public static List <Individual> PerformCrossOver(List <Individual> population, IUniformRandomGenerator randomGenerator, IGenoTypeCrossoverator crossOverator)
        {
            var returnObject = new List <Individual>();

            do
            {
                var leftIndex      = randomGenerator.GetIntegerRandomNumber(0, population.Count - 1);
                var leftIndividual = population[leftIndex];
                population.RemoveAt(leftIndex);

                Individual rightIndividual = null;
                if (population.Count > 0)
                {
                    var rightIndex = randomGenerator.GetIntegerRandomNumber(0, population.Count - 1);
                    rightIndividual = population[rightIndex];
                    population.RemoveAt(rightIndex);
                }

                if (rightIndividual != null)
                {
                    crossOverator.PerformCrossover(ref leftIndividual.GenoType, ref rightIndividual.GenoType);
                    returnObject.Add((Individual)rightIndividual.Clone());
                }
                returnObject.Add((Individual)leftIndividual.Clone());
            } while (population.Count >= 1);

            if (population.Count == 1)
            {
                returnObject.Add(population[0]);
            }

            return(returnObject);
        }
Ejemplo n.º 3
0
 public GenoTypeCrossoveratorBasic1(IUniformRandomGenerator uniformRandomGenerator, IEaGeneExpressionParameters eaGeneExpressionParameters)
 {
     UniformRandomGenerator     = uniformRandomGenerator;
     EaGeneExpressionParameters = eaGeneExpressionParameters;
 }
Ejemplo n.º 4
0
 public ParameterTerminalFactory(IEaGeneExpressionParameters eAGeneExpressionParameters, IUniformRandomGenerator uniformRandomGenerator)
 {
     UniformRandomGenerator         = uniformRandomGenerator;
     EaGeneExpressionParameters     = eAGeneExpressionParameters;
     PossibleConstantsCountMinusOne = EaGeneExpressionParameters.PossibleConstants.Count - 1;
 }
Ejemplo n.º 5
0
 public GenoTypeMutatorBasic1(IUniformRandomGenerator uniformRandomGenerator, IEaGeneExpressionParameters eaGeneExpressionParameters, IGenoTypeFactory genoTypeFactory)
 {
     UniformRandomGenerator     = uniformRandomGenerator;
     EaGeneExpressionParameters = eaGeneExpressionParameters;
     GenoTypeFactory            = genoTypeFactory;
 }
Ejemplo n.º 6
0
        public static List <IObjectiveValues> PerformSelection(int tournamentSize, List <IObjectiveValues> originalObjectiveValues, IUniformRandomGenerator randomGenerator)
        {
            originalObjectiveValues = originalObjectiveValues.Where(x => x.Invalid == false).ToList();

            var populationSize = originalObjectiveValues.Count;

            originalObjectiveValues = Nsga2Ranker.Rank(originalObjectiveValues);
            originalObjectiveValues = Nsga2Crowder.CalculateCrowdingDistances(originalObjectiveValues);
            var newPopulationObjectiveValues = new List <IObjectiveValues>();

            do
            {
                var indices = new List <int>();
                var pickedObjectiveValues = new List <IObjectiveValues>();
                do
                {
                    var index = randomGenerator.GetIntegerRandomNumber(0, originalObjectiveValues.Count - 1);
                    if (indices.Contains(index))
                    {
                        continue;
                    }
                    indices.Add(index);
                    pickedObjectiveValues.Add(originalObjectiveValues[index]);
                } while (indices.Count() < tournamentSize);

                pickedObjectiveValues = pickedObjectiveValues.OrderBy(i => i.Rank).ToList();

                if (pickedObjectiveValues[0].Rank == pickedObjectiveValues[1].Rank)
                {
                    if (pickedObjectiveValues[1].CrowdingDistance > pickedObjectiveValues[0].CrowdingDistance)
                    {
                        newPopulationObjectiveValues.Add(pickedObjectiveValues[1]);
                    }
                    else
                    {
                        newPopulationObjectiveValues.Add(pickedObjectiveValues[0]);
                    }
                }
                else
                {
                    newPopulationObjectiveValues.Add(pickedObjectiveValues[0]);
                }
            } while (newPopulationObjectiveValues.Count < populationSize);

            return(newPopulationObjectiveValues);
        }