//CONFERIR
 public int finalFitnessComparison(IndividualBase i1, IndividualBase i2)
 {
     return i1.FinalFitness < i2.FinalFitness ? // se i1 for menor
         1 : //retorna 1 (i1)
         i2.FinalFitness < i1.FinalFitness ? //se i2 for menor
         -1 : //retorna -1 (i2)
         0; //se for igual, retorna 0
 }
 public static int CrowdedComparison(IndividualBase i1, IndividualBase i2)
 {
     int partial = i1.NonDominationRank < i2.NonDominationRank ? // se i1 for de um front menor
         1 : //retorna 1 (i1)
         i2.NonDominationRank < i1.NonDominationRank ? //se i2 for de um front menor
         -1 : //retorna -1 (i2)
         0; //se for igual, retorna a comparação entre as distâncias
     if (!partial.Equals(0))
         return partial;
     return i1.CrowdingDistance.CompareTo(i2.CrowdingDistance);
 }
        public static void Execute(IndividualBase individual, ProblemBase problem)
        {
            problem.EvaluateIndividual(individual);

            if(!individual.WasEvaluated) {
                individual.ObjectivesValuesForMaximization.Add(double.MaxValue);
                individual.ObjectivesValuesForNormalization.Add(double.MaxValue);
            }

            Objective objective = problem.MonoObjectiveGoal;
            individual.SetFitnessForObjective(objective);
            individual.WasEvaluated = true;
        }
        public override void Execute(PopulationBase population, out IndividualBase chosenIndividual1, out IndividualBase chosenIndividual2)
        {
            IndividualBase[] selectedParents = new IndividualBase[2];

            for (int individualIdx = 0; individualIdx < 2; ++individualIdx) {
                selectedParents[individualIdx] = population.GetRandomIndividual();
                for (int selectionIdx = 1; selectionIdx < tourSize; ++selectionIdx) {
                    IndividualBase randomIndividual = population.GetRandomIndividual();
                    if (randomIndividual.GetFitnessForObjective(Problem.MonoObjectiveGoal) > selectedParents[individualIdx].GetFitnessForObjective(Problem.MonoObjectiveGoal))
                        selectedParents[individualIdx] = randomIndividual;
                }
            }
            chosenIndividual1 = selectedParents[0];
            chosenIndividual2 = selectedParents[1];
        }
        public int CompareToByObjective(IndividualBase another, Objective objective)
        {
            double individualAttributeValue        = GetFitnessForObjective(objective);
            double anotherIndividualAttributeValue = another.GetFitnessForObjective(objective);

            if (anotherIndividualAttributeValue > individualAttributeValue)
            {
                return(-1);
            }
            else if (anotherIndividualAttributeValue == individualAttributeValue)
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }
Beispiel #6
0
        public static void Execute(IndividualBase individual, ProblemBase problem)
        {
            problem.EvaluateIndividual(individual);

            if (!individual.WasEvaluated)
            {
                foreach (Objective objective in problem.MultiObjectiveGoal)
                {
                    individual.ObjectivesValuesForMaximization.Add(double.MaxValue);
                    individual.ObjectivesValuesForNormalization.Add(double.MaxValue);
                }
            }

            foreach (Objective objective in problem.MultiObjectiveGoal)
            {
                individual.SetFitnessForObjective(objective);
            }

            individual.WasEvaluated = true;
        }
        public bool Dominates(IndividualBase another)
        {
            bool dominatesInAnObjective = false;

            foreach (Objective objective in Problem.MultiObjectiveGoal)
            {
                double individualAttributeValue        = GetFitnessForObjective(objective);
                double anotherIndividualAttributeValue = another.GetFitnessForObjective(objective);
                if (individualAttributeValue > anotherIndividualAttributeValue)
                {
                    dominatesInAnObjective = true;
                }
                else if (individualAttributeValue < anotherIndividualAttributeValue)
                {
                    return(false);
                }
            }
            if (dominatesInAnObjective)
            {
                return(true);
            }
            return(false);
        }
 public override void Execute(IndividualBase parent1, IndividualBase parent2, out IndividualBase child1, out IndividualBase child2)
 {
     Problem.CiclicCrossover(parent1, parent2, out child1, out child2);
 }
 private IndividualBase BestByCrowdedComparison(IndividualBase individual1, IndividualBase individual2)
 {
     if (individual1.NonDominationRank < individual2.NonDominationRank)
         return individual1;
     if (individual2.NonDominationRank < individual1.NonDominationRank)
         return individual2;
     // Se Estão no Mesmo Ranking de Não-Dominância
     if (individual1.CrowdingDistance > individual2.CrowdingDistance)
         return individual1;
     if (individual2.CrowdingDistance > individual1.CrowdingDistance)
         return individual2;
     // Se têm a Mesma CrowdingDistance
     if (Aleatoriety.GetRandomInt(2) == 0)
         return individual1;
     else
         return individual2;
 }
 public abstract void Execute(PopulationBase population, out IndividualBase chosenIndividual1, out IndividualBase chosenIndividual2);
        private IndividualBase BinaryTournment(Population_MultiObjective_AG population)
        {
            IndividualBase[] contestants = new IndividualBase[2];

            contestants[0] = population.GetRandomIndividual();
            for (int i = 0; i < 10; ++i) {
                contestants[1] = population.GetRandomIndividual();
                if ((contestants[0] != contestants[1]) || i == 9) {
                    break;
                }
            }
            //do {
            //    contestants[1] = population.GetRandomIndividual();
            //} while (contestants[0] == contestants[1]);

            return finalFitnessComparison(contestants[0], contestants[1]) >= 0 ? contestants[0] : contestants[1];
        }
 public abstract void ValidateIndividual(IndividualBase individual);
 public abstract string NewSerializeIndividual(IndividualBase individualBase);
 public override void Execute(PopulationBase population, out IndividualBase chosenIndividual1, out IndividualBase chosenIndividual2)
 {
     throw new NotImplementedException();
 }
        public int CompareToByObjective(IndividualBase another, Objective objective)
        {
            double individualAttributeValue = GetFitnessForObjective(objective);
            double anotherIndividualAttributeValue = another.GetFitnessForObjective(objective);

            if (anotherIndividualAttributeValue > individualAttributeValue)
                return -1;
            else if (anotherIndividualAttributeValue == individualAttributeValue)
                return 0;
            else
                return 1;
        }
        public bool IsDominatedBy(IndividualBase another)
        {
            bool dominatedInAnObjective = false;

            foreach (Objective objective in Problem.MultiObjectiveGoal) {
                double individualAttributeValue = GetFitnessForObjective(objective);
                double anotherIndividualAttributeValue = another.GetFitnessForObjective(objective);
                if (individualAttributeValue > anotherIndividualAttributeValue)
                    return false;
                else if (individualAttributeValue < anotherIndividualAttributeValue) {
                    dominatedInAnObjective = true;
                }
            }
            if (dominatedInAnObjective)
                return true;
            return false;
        }
 public void AddIndividual(IndividualBase individual)
 {
     Content.Add(individual);
 }
        private double DistanceBetween(IndividualBase i1, IndividualBase i2)
        {
            double distance = 0;

            foreach (Objective objective in i1.Problem.MultiObjectiveGoal) {
                double difference = i1.GetNormalizedValueForObjective(objective) - i2.GetNormalizedValueForObjective(objective); //calcular a distancia parcial como sendo a diferença
                distance += Math.Pow(difference, 2);
            }
            return distance;
        }
 public abstract void Execute(IndividualBase parent1, IndividualBase parent2, out IndividualBase child1, out IndividualBase child2);
 public abstract void EvaluateIndividual(IndividualBase individual);
 public abstract void EvaluateIndividual(IndividualBase individual);
 public abstract void MutateIndividual(IndividualBase individual);
 public abstract void MutateIndividual(IndividualBase individual);
 public abstract void PMXCrossover(IndividualBase parent1, IndividualBase parent2, out IndividualBase child1, out IndividualBase child2);
 public abstract void PMXCrossover(IndividualBase parent1, IndividualBase parent2, out IndividualBase child1, out IndividualBase child2);
 public abstract string SerializeIndividual(IndividualBase individual);
 public abstract void ValidateIndividual(IndividualBase individual);
Beispiel #28
0
 public void AddIndividual(IndividualBase individual)
 {
     Content.Add(individual);
 }
        private IndividualBase BinaryTournment(Population_MultiObjective_AG population)
        {
            IndividualBase[] contestants = new IndividualBase[2];

            contestants[0] = population.GetRandomIndividual();
            do {
                contestants[1] = population.GetRandomIndividual();
            } while (contestants[0] == contestants[1]);

            return BestByCrowdedComparison(contestants[0], contestants[1]);
        }