private void crossOver(int childCount)
        {
            for (int j = 0; j < childCount; j++)
            {
                int        randomIndexOne = rnd.Next(parent.Count);
                int        randomIndexTwo = rnd.Next(parent.Count);
                chromosome tempOne        = new chromosome();
                chromosome tempTwo        = new chromosome();

                for (int i = 0; i < length * length; i++)
                {
                    if (i < (length * length / 2))
                    {
                        tempOne.chrome[i] = parent[randomIndexOne].chrome[i];
                        tempTwo.chrome[i] = parent[randomIndexTwo].chrome[i];
                    }
                    else
                    {
                        tempOne.chrome[i] = parent[randomIndexTwo].chrome[i];
                        tempTwo.chrome[i] = parent[randomIndexOne].chrome[i];
                    }
                }
                tempOne.fitnessValue = fittnessCalculate(tempOne.chrome);
                tempTwo.fitnessValue = fittnessCalculate(tempTwo.chrome);
                socity.Add(tempOne);
                socity.Add(tempTwo);
            }
            socityAggregationFitness();
        }
 public chromosome(chromosome copy)
 {
     this.fitnessValue = copy.fitnessValue;
     this.chrome       = new int[copy.chrome.Length];
     for (int i = 0; i < copy.chrome.Length; i++)
     {
         this.chrome[i] = copy.chrome[i];
     }
     this.aggregationFittness = 0;
 }
        public void purgingSocity(int socityCount)
        {
            int itemToremove = socity.Count - socityCount;

            for (int i = 0; i < itemToremove; i++)
            {
                chromosome temp = (chromosome)(from x in socity where x.fitnessValue == socity.Min(chrome => chrome.fitnessValue) select x).First();
                socity.Remove(temp);
            }
        }
예제 #4
0
    public Organism(GameObject _body, ann _brain, chromosome _dna, ga _ecosystem)
    {
        body = _body;
        brain = _brain;
        dna = _dna;
        ecosystem = _ecosystem;

        cycleDelay = 0.016f;
        name = "";
    }
 private void createSocity(int socityPopulation)
 {
     for (int i = 0; i < socityPopulation; i++)
     {
         chromosome temp = new chromosome();
         numberPool = new int[] { length, length, length, length };
         for (int j = 0; j < length * length; j++)
         {
             temp.chrome[j] = getNumberOfPool() + 1;
         }
         temp.fitnessValue = fittnessCalculate(temp.chrome);
         socity.Add(temp);
     }
     socityAggregationFitness();
 }
 private void chooseParent(int parentCount)
 {
     parent = new List <chromosome> ();
     for (int i = 0; i < parentCount; i++)
     {
         double chance = rnd.NextDouble() * socity[socity.Count - 1].aggregationFittness;
         for (int j = 0; j < socity.Count; j++)
         {
             if (chance <= socity[j].aggregationFittness)
             {
                 chromosome temp = new chromosome(socity[i]);
                 parent.Add(temp);
                 break;
             }
         }
     }
 }
예제 #7
0
 private Organism CreateOrganism(string name)
 {
     GameObject body = AddTank();
     Vector3 inputVal = UnityTools.ClosestWithTag(tank, "point").transform.position;
     ann brain = new ann(6, 3, 2, 5, new List<float>() { tank.transform.position.x,
                                                             tank.transform.position.y,
                                                             tank.transform.position.z,
                                                             inputVal.x,
                                                             inputVal.y,
                                                             inputVal.z});
     chromosome dna = new chromosome(24, ecosystem);
     Organism thisOrg = new Organism(body, brain, dna, ecosystem);
     thisOrg.name = name;
     body.name = name;
     totalPopulation++;
     StartCoroutine(thisOrg.BodyClock());
     Log.Add(name + "was born.");
     return thisOrg;
 }
예제 #8
0
파일: ga.cs 프로젝트: Devcon4/ANN-Published
    public List<float> Decode(chromosome chromosomeToDecode)
    {
        List<float> returnVal = new List<float>();

        foreach (byte key in chromosomeToDecode.genes) {
            float val;
            if (codex.TryGetValue(key, out val)) {
                returnVal.Add(val);
            } else {
                returnVal.Add(0);
            }
        }
        return returnVal;
    }