コード例 #1
0
        public IDNA <CSingleAssignment> CoinCrossover(IDNA <CSingleAssignment> objPartner)
        {
            CTaamAssignment Child = new CTaamAssignment(false);

            for (int i = 0; i < this.Genes.Length; i++)
            {
                CTaamAssignment Selected = Shared.Coin() ? this : objPartner as CTaamAssignment;
                Child[i] = Selected[i].Clone() as CSingleAssignment;
            }

            return(Child);
        }
コード例 #2
0
        public override IDNA <CSingleAssignment> Clone()
        {
            CTaamAssignment Copy = new CTaamAssignment(false);

            Copy.Fitness = this.Fitness;
            for (int i = 0; i < this.Genes.Length; i++)
            {
                Copy[i] = this[i].Clone() as CSingleAssignment;
            }

            return(Copy);
        }
コード例 #3
0
        public IDNA <CSingleAssignment> PartialGenomeCrossover(IDNA <CSingleAssignment> objPartner)
        {
            CTaamAssignment child   = new CTaamAssignment(false);
            CTaamAssignment partner = (CTaamAssignment)objPartner;

            int        nStart             = Shared.Next(this.Genes.Length / 2) + 1;
            int        nEnd               = nStart + Shared.Next(this.Genes.Length / 2);
            List <int> colPassedGenesUIDs = new List <int>();

            for (int i = nStart; i < nEnd; i++)
            {
                child[i] = partner[i].Clone();
                colPassedGenesUIDs.Add(partner[i].UID);
            }

            int nGeneInsertionPos = 0;

            for (int i = 0; i < this.Genes.Length; i++)
            {
                if (nGeneInsertionPos == nStart)
                {
                    nGeneInsertionPos = nEnd;
                }

                if (colPassedGenesUIDs.Contains(this.Genes[i].UID))
                {
                    continue;
                }

                child[nGeneInsertionPos] = this.Genes[i].Clone();
                nGeneInsertionPos++;
            }

            child.Mutate();

            return(child);
        }