Exemplo n.º 1
0
        public DesignPlan mutation(Random r1, DesignPlan DP, int count_row)//Mutation
        {
            n   = 10 * count_row;
            odd = r1.Next(100);

            if (odd <= 2)//3% mutation rate
            {
                for (int i = 0; i < n; i++)
                {
                    if (r1.Next(100) < 3)//Mutation rate for one gene 3%
                    {
                        if (DP.Chromo.genes[i] == 0)
                        {
                            DP.Chromo.genes[i] = 1;
                        }
                        else
                        {
                            DP.Chromo.genes[i] = 0;
                        }
                    }
                }
                return(DP);
            }
            else
            {
                return(DP);
            }
        }
Exemplo n.º 2
0
        public DesignPlan graetmutation(Random r1, DesignPlan DP, int count_row)   // Large Mutation
        {
            n   = 10 * count_row;                                                  //Gene Length
            odd = r1.Next(100);

            if (odd <= 50)
            {
                for (int i = 0; i < n; i++)
                {
                    if (r1.Next(100) < 50)//Mutation rate for one gene 50%
                    {
                        if (DP.Chromo.genes[i] == 0)
                        {
                            DP.Chromo.genes[i] = 1;
                        }
                        else
                        {
                            DP.Chromo.genes[i] = 0;
                        }
                    }
                }
                return(DP);
            }
            else
            {
                return(DP);
            }
        }
Exemplo n.º 3
0
        public void Best(int count_row, int g_size, Piping_System piping) //Selection of the best individuals from the population
        {
            double F  = 100000;                                           //Evaluation Value
            double F2 = 100000;
            int    A  = 0;
            int    B  = 0;

            for (int i = 0; i < size; i++)
            {
                double fit = designplans[i].Fittness(count_row, g_size, piping);

                if (fit < F)
                {
                    F = fit;
                    B = A;
                    A = i;
                }
                else if (fit < F2)
                {
                    F2 = fit;
                    B  = i;
                }
            }
            best   = designplans[A];
            second = designplans[B];
        }
Exemplo n.º 4
0
        public Population oddCross(Random r1, Population P2, int size, int count_row, int n)  //Number of individuals is an odd number
        {
            Crossover CO2 = new Crossover();

            DesignPlan[] designplans = new DesignPlan[size];

            designplans[0] = P2.DP[0];
            designplans[1] = P2.DP[1];

            s = (size - 1) / 2;
            for (int i = 1; i < s; i++)
            {
                int p = r1.Next(10 * count_row); //To gene length
                int a = i * 2,                   //Odd-numbered
                    b = a + 1;                   //Even-numbered

                DesignPlan[] designplan = CO2.Cross1(P2.DP[a], P2.DP[b], p, count_row);

                designplans[a] = designplan[0];
                designplans[b] = designplan[1];
            }

            int p2 = r1.Next(10 * count_row);//To gene length

            DesignPlan[] designplan2 = CO2.Cross1(P2.DP[size - 1], P2.DP[0], p2, count_row);
            designplans[size - 1] = designplan2[0];

            Population population = new Population(designplans, size, n);

            return(population);
        }
Exemplo n.º 5
0
        public Population evenCross(Random r1, Population P2, int size, int count_row, int n)  //Number of individuals is an even number
        {
            s = size / 2;
            Crossover CO2 = new Crossover();

            DesignPlan[] designplans = new DesignPlan[size];

            designplans[0] = P2.DP[0];
            designplans[1] = P2.DP[1];

            for (int i = 1; i < s; i++)          //Crossover by performing, generating odd-numbered and even-numbered two designplans for loop once
            {
                int p = r1.Next(10 * count_row); //To gene length
                int a = i * 2,                   //Odd-numbered
                    b = a + 1;                   //Even-numbered

                DesignPlan[] designplan = CO2.Cross1(P2.DP[a], P2.DP[b], p, count_row);

                designplans[a] = designplan[0];
                designplans[b] = designplan[1];
            }

            Population population = new Population(designplans, size, n);

            return(population);
        }
Exemplo n.º 6
0
        public void Elite(Population original, int count_row, Deck[] deck_all, Cluster cluster_GA)  //Elite Selection
        {
            DesignPlan DP1 = new DesignPlan(count_row);

            designplans[0] = DP1;
            DesignPlan DP2 = new DesignPlan(count_row);

            designplans[1] = DP2;

            designplans[0].Chromo.genes = original.B.Chromo.genes;
            designplans[0].makeDesignplan2(count_row, deck_all, cluster_GA);

            designplans[1].Chromo.genes = original.S.Chromo.genes;
            designplans[1].makeDesignplan2(count_row, deck_all, cluster_GA);
        }
Exemplo n.º 7
0
        public DesignPlan M(Random r1, DesignPlan C, int aa, int count_row)
        {
            int a = (aa) % 50;//Cause once large mutation in 50 generations

            if (a == 0)
            {
                DesignPlan chromosome = graetmutation(r1, C, count_row);
                return(chromosome);
            }

            else
            {
                DesignPlan chromosome = mutation(r1, C, count_row);
                return(chromosome);
            }
        }
Exemplo n.º 8
0
        public Population Mutation(Random r1, Population P, int count_row)// Mutation
        {
            Mutation DM = new Mutation();

            DesignPlan[] DP1 = new DesignPlan[size];
            DP1[0] = P.DP[0];
            DP1[1] = P.DP[1];

            for (int i = 2; i < size; i++)
            {
                DesignPlan DP2 = DM.M(r1, P.DP[i], n, count_row);
                DP1[i] = DP2;
            }
            Population P3 = new Population(DP1, size, n);

            return(P3);
        }
Exemplo n.º 9
0
        public DesignPlan selectMember(Random r1, DesignPlan[] original, int count_row)  //Selection from 2 individuals
        {
            DesignPlan DP = new DesignPlan(count_row);
            int        a  = r1.Next(size);
            int        b  = r1.Next(size);

            if (original[a].Fit < original[b].Fit)
            {
                DP.Chromo.genes = original[a].Chromo.genes;
                return(DP);
            }

            else
            {
                DP.Chromo.genes = original[b].Chromo.genes;
                return(DP);
            }
        }
Exemplo n.º 10
0
        public void makePopulaiton1(Deck[] deck_GA, int count_row, Cluster cluster_GA, Random r1, Piping_System piping_GA) //First Generation
        {
            designplans = new DesignPlan[size];

            for (int i = 0; i < size; i++) //size: generation size
            {
                DesignPlan C1 = new DesignPlan(count_row);

                C1.makeDesignplan1(count_row, r1, cluster_GA, deck_GA);
                designplans[i] = C1;

                //-----------designplans[i] Initialize after Generation, The deck Information---------------

                Deck deck = new Deck();
                deck.Initialize(deck_GA);

                //------------------------------------------------------------------------
            }
        }
Exemplo n.º 11
0
        public DesignPlan[] Cross1(DesignPlan DP1, DesignPlan DP2, int p, int count_row)//1-point crossover
        {
            DesignPlan[] designplan  = new DesignPlan[2];
            DesignPlan   designplan1 = new DesignPlan(count_row);
            DesignPlan   designplan2 = new DesignPlan(count_row);

            for (int i = 0; i < p; i++)
            {
                designplan1.Chromo.genes[i] = DP1.Chromo.genes[i];
                designplan2.Chromo.genes[i] = DP2.Chromo.genes[i];
            }

            for (int i = p; i < 10 * count_row; i++)//i is range for gene length
            {
                designplan1.Chromo.genes[i] = DP2.Chromo.genes[i];
                designplan2.Chromo.genes[i] = DP1.Chromo.genes[i];
            }

            designplan[0] = designplan1;
            designplan[1] = designplan2;

            return(designplan);
        }