Example #1
0
        public void addComp(Comp c)
        {
            if (kT != Program.nTiles)
            {
                cov[kT] = c;

                //size += c.getSize();
                kT++;

            }
            else
            {
                throw new ArrayOutOfBoundException();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="k"></param>
        /// <param name="i"></param>
        private void microssover(int p1, int p2, int k, int i)
        {
            //test1++;
            if (false)//individual[p1].getComp(k).getCol() == individual[p2].getComp(k).getCol() && individual[p1].getComp(k).getRow() == individual[p2].getComp(k).getRow())
            {
                macrossover(p1, p2, k, i, (Program.rnd.NextDouble() < 0.5));

            }
            else
            {
                bool[] temp1 = new bool[Program.col];
                bool[] temp2 = new bool[Program.col];

                for (int j = 0; j < Program.col; j++)
                {
                    if (Program.rnd.NextDouble() >= 0.5)
                    {
                        temp1[j] = individual[p1].getComp(k).getGene(j);
                        temp2[j] = individual[p2].getComp(k).getGene(j);
                    }
                    else
                    {
                        temp1[j] = individual[p2].getComp(k).getGene(j);
                        temp2[j] = individual[p1].getComp(k).getGene(j);
                    }
                    if (mu / Program.col > Program.rnd.NextDouble())
                    {
                        temp1[j] = !temp1[j];
                    }
                    if (mu / Program.col > Program.rnd.NextDouble())
                    {
                        temp2[j] = !temp2[j];
                    }

                }
                Comp tempComp1 = new Comp(temp1, offspring[i].getFp());
                Comp tempComp2 = new Comp(temp2, offspring[i+1].getFp());
                offspring[i].addComp(tempComp1);
                offspring[i + 1].addComp(tempComp2);
            }
        }
Example #3
0
        protected void initSeed(double seed)
        {
            for (int k = 0; k < Program.nTiles; k++)
            {
                kT++;
                cov[k] = new Comp(seed, 0);
                for (int j = 0; j < Program.col; j++)
                {
                    if (cov[k].getGene(j))
                    {
                        nGenes[j]++;
                    }
                }
                for (int i = 0; i < Program.rows; i++)
                {
                    if (cov[k].getPheno(i))
                    {
                        nPheno[i]++;
                    }
                }
                //size += cov[k].getSize();

            }
        }