Example #1
0
        public static void Apop(SortedDictionary <double, int[]> p, Random rand)
        {
            //SortedDictionary<double, int[]> vre = new SortedDictionary<double,int[]>();
            List <int[]> po = new List <int[]>();

            int[] CH1   = new int[5];
            int[] CH2   = new int[5];
            int[] CH3   = new int[5];
            int[] CH4   = new int[5];
            int[] CHD   = new int[5];
            int   count = 0;

            //List<int[]> allvid = new List<int[]>();
            double[] h = new double[4];
            //double[] nol = new double[]{0,0,0,0,0};

            int o = 0;


            while (count < 4)
            {
                foreach (var fg in p.Keys)
                {
                    h[o] = fg;
                    o++;
                }

                //CHD = p[h[3]];
                CHD = p[h[o - 1]];
                po  = Crossover.Cross(p, rand, count);
                CH1 = po[0];
                CH2 = po[1];
                CH3 = po[2];
                CH4 = po[3];

                double summa1 = Sum.Summa(CH1);
                double summa2 = Sum.Summa(CH2);
                double summa3 = Sum.Summa(CH3);
                double summa4 = Sum.Summa(CH4);
                double summaD = Sum.Summa(CHD);
                double allp   = Sum.OverallSum(summa1, summa2, summa3, summa4);
                double srt    = summa1 + summa2 + summa3;
                summa1 = Sum.Coeff(summa1, allp);
                summa2 = Sum.Coeff(summa2, allp);
                summa3 = Sum.Coeff(summa3, allp);
                summa4 = Sum.Coeff(summa4, allp);
                //summaD = Sum.Coeff(summaD, allp);
                //int[] pustoi = new int[] { 0, 0, 0, 0, 0 };
                //foreach (double h in vre.Keys.Cast<double>().ToArray())
                //    vre[h] = pustoi;

                //vre = Inspection.Insp(vre, summa1, CH1);

                //vre = Inspection.Insp(vre, summa2, CH2);


                //vre = Inspection.Insp(vre, summa3, CH3);

                //vre = Inspection.Insp(vre, summa4, CH4);



                p = dob.dd(summa1, summa2, summa3, summa4, srt, summaD, CH1, CH2, CH3, CH4, CHD);

                count++;
                o   = 0;
                srt = 0;
                //Console.WriteLine("я все еще здесь!{0}",count);
            }
            foreach (var fg in p.Keys)
            {
                h[o] = fg;
                o++;
            }

            int[] anw = new int[C.cc];
            anw          = p[h[0]];
            genetic.fmap = anw;
            double rast1    = looping.startFinish(anw[0].ToString());
            double rast2    = looping.startFinish(anw[anw.Length - 1].ToString());
            double dlinaanw = Sum.Summa(anw);

            dlinaanw = dlinaanw + rast1 + rast2 + 50 * C.cc;
            // Console.WriteLine("Возможный маршрут = ");
            string answerResuit = "";

            for (int i = 0; i < anw.Length; i++)
            {
                answerResuit = answerResuit + "-->" + C.g[anw[i]];
            }

            answerResuit = answerResuit + "-->" + C.start;
            answerResuit = C.start + answerResuit;

            /*
             * for (int i = 0; i < anw.Length; i++)
             * Console.Write("{0}", anw[i]);*/

            // Console.WriteLine("Стоимость данного маршрута = {0}", dlinaanw);
            int adl = (int)dlinaanw;
            //string dli = dlinaanw.ToString();
            string dli = adl.ToString() + "  km";

            // genetic.aaa = genetic.Marsh(genetic.SMA(anw));
            genetic.bbb = genetic.Dlinam(dli);
            genetic.aaa = answerResuit;
        }
Example #2
0
        public static List <int[]> Cross(SortedDictionary <double, int[]> u, Random rand, int gggf)
        {
            List <int[]> ju     = new List <int[]>();
            List <int[]> allvid = new List <int[]>();

            int[] a12 = new int[5];
            int[] a21 = new int[5];
            // Console.WriteLine("здесь");
            double[] yt = new double[4];
            int      i  = 0;

            foreach (double c in u.Keys)
            {
                yt[i] = c;
                i++;
            }

            int[] a1 = u[yt[0]];
            int[] a2 = u[yt[1]];
            int[] a3 = u[yt[2]];
            int[] a4 = u[yt[3]];
            a12 = Crossover.CrossAB(a1, a4);
            a21 = Crossover.CrossBA(a2, a3);
            a12 = Mutation.Mut(a12, rand);
            a21 = Mutation.Mut(a21, rand);
            bool ist = false;
            //while (!ist)
            //{
            //    ist = prov.g(b, a12);
            //    a12 = prov.ft(a12,rand);
            //}
            //ist = false;
            //while (!ist)
            //{
            //    ist = prov.g(b, a21);
            //    a21 = prov.ft(a21,rand);
            //}

            bool kj = false;

            allvid.Add(u[yt[0]]);
            kj = a1.SequenceEqual(a2);
            if (!kj)
            {
                allvid.Add(a2);
            }
            else
            {
                allvid.Add(a4);
            };

            //allvid.Add(u[yt[1]]);
            ist = prov.g(allvid, a12);
            if (!ist)
            {
                allvid.Add(a12);
            }
            else
            {
                a12 = Crossover.CrossAB(a12, u[yt[2]]);
                ist = false;
                while (ist)
                {
                    a12 = prov.ft(a12, rand);
                    ist = prov.g(allvid, a12);
                    if (ist)
                    {
                        break;
                    }
                }
                allvid.Add(a12);
            }
            ist = false;
            ist = prov.g(allvid, a21);
            if (!ist)
            {
                allvid.Add(a21);
            }
            else
            {
                a21 = Crossover.CrossAB(a21, u[yt[3]]);
                ist = false;
                while (ist)
                {
                    a21 = prov.ft(a21, rand);
                    ist = prov.g(allvid, a21);
                    if (ist)
                    {
                        break;
                    }
                }

                allvid.Add(a21);
            }

            //if (allvid.Count != 4)
            //{
            //    allvid.Add(a3);
            //    allvid.Add(a4);
            //}

            return(allvid);
        }