Example #1
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);
        }