コード例 #1
0
ファイル: Population.cs プロジェクト: jswk/GA-BO
 public bool containsIndividual(IIndividual ind)
 {
     foreach (var i in individuals)
         if (i.GetHashCode() == ind.GetHashCode())
             return true;
     return false;
 }
コード例 #2
0
ファイル: Island.cs プロジェクト: jswk/GA-BO
        private void swapPopulation(IIndividual individual) // change the worst individual in population to another individual
        {
            IIndividual worstIndividual = null;

            lock (currentPopulation)
            {
                foreach (IIndividual ind in currentPopulation.individuals)
                {
                    if (ind.GetHashCode() == individual.GetHashCode()) //if we already have such individual, do not let him in
                    {
                        return;
                    }
                    if (worstIndividual == null)
                    {
                        worstIndividual = ind;
                    }
                    if (ind.value() > worstIndividual.value())
                    {
                        worstIndividual = ind;
                    }
                }
                var i = currentPopulation.individuals.IndexOf(worstIndividual);
                currentPopulation.individuals[i] = individual; //changing the worst for new.
                //but using this way we could add a lot of weak Individuals and change only one in population if addaing individuals are weak than existing on the island
            }
        }
コード例 #3
0
ファイル: Population.cs プロジェクト: jswk/GA-BO
 public bool containsIndividual(IIndividual ind)
 {
     foreach (var i in individuals)
     {
         if (i.GetHashCode() == ind.GetHashCode())
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #4
0
ファイル: Island.cs プロジェクト: jswk/GA-BO
 // change the worst individual in population to another individual
 private void swapPopulation(IIndividual individual)
 {
     IIndividual worstIndividual = null;
     lock (currentPopulation)
     {
         foreach (IIndividual ind in currentPopulation.individuals)
         {
             if (ind.GetHashCode() == individual.GetHashCode()) //if we already have such individual, do not let him in
                 return;
             if (worstIndividual == null)
             {
                 worstIndividual = ind;
             }
             if (ind.value() > worstIndividual.value())
             {
                 worstIndividual = ind;
             }
         }
         var i = currentPopulation.individuals.IndexOf(worstIndividual);
         currentPopulation.individuals[i] = individual; //changing the worst for new.
         //but using this way we could add a lot of weak Individuals and change only one in population if addaing individuals are weak than existing on the island
     }
 }