Пример #1
0
        private Ngay TaoNgay()
        {
            Ngay day = new Ngay();

            for (int i = 0; i < soBua; i++)
            {
                day.Bua.Add(TaoBua());
            }
            return(day);
        }
Пример #2
0
        private void LaiTao()
        {
            int t;
            int k;

            for (int i = 0; i < QTbandau.Count() / 2; i++)
            {
                t = ran.Next(0, QTbandau.Count());
                k = ran.Next(0, QTbandau.Count());
                while (t == k && QTbandau.Count() > 1)
                {
                    t = ran.Next(0, QTbandau.Count());
                    k = ran.Next(0, QTbandau.Count());
                }
                ThucDon ct1  = QTbandau[t];
                ThucDon ct2  = QTbandau[k];
                ThucDon ctc1 = new ThucDon();
                ThucDon ctc2 = new ThucDon();
                for (int j = 0; j < soNgay; j++)
                {
                    Ngay ngay1 = new Ngay();
                    Ngay ngay2 = new Ngay();
                    for (int a = 0; a < soBua; a++)
                    {
                        Bua bua1 = ct1.Ngay[j].Bua[a];
                        Bua bua2 = ct2.Ngay[j].Bua[a];
                        for (int b = 0; b < 3; b++)
                        {
                            MON mon1 = bua1.Mon[b];
                            MON mon2 = bua2.Mon[b];
                            int tyLe = ran.Next(0, 100);
                            if (tyLe < tyLeLaiTao)
                            {
                                bua1.Mon[b] = mon2;
                                bua2.Mon[b] = mon1;
                            }
                        }
                        ngay1.Bua.Add(bua1);
                        ngay2.Bua.Add(bua2);
                    }
                    ctc1.Ngay.Add(ngay1);
                    ctc2.Ngay.Add(ngay2);
                }
                ctc1 = DotBien(ctc1);
                ctc2 = DotBien(ctc2);
                int tyLeSongSot = ran.Next(0, 100);
                if (tyLeSongSot < tyLeSongSot1)
                {
                    QTmoi.Add(ctc1);
                }
                else
                {
                    if (tyLeSongSot < tyLeSongSot2)
                    {
                        QTmoi.Add(ctc2);
                    }
                    else
                    {
                        int o = ran.Next(0, 2);
                        if (o == 0)
                        {
                            QTmoi.Add(ctc1);
                        }
                        else
                        {
                            QTmoi.Add(ctc2);
                        }
                    }
                }
                if (k > t)
                {
                    QTbandau.Remove(QTbandau[k]);
                    QTbandau.Remove(QTbandau[t]);
                }
                else
                {
                    QTbandau.Remove(QTbandau[t]);
                    QTbandau.Remove(QTbandau[k]);
                }
            }
        }