Exemplo n.º 1
0
        static void Main(string[] args)
        {
            random         = new Random();
            validClass     = new ClassOfTimetable[13];
            validClass[0]  = new ClassOfTimetable(idClass: "T-1", idLecture: "1", lesson: TOAN_LESSON, idSubject: "Math");
            validClass[1]  = new ClassOfTimetable(idClass: "L-1", idLecture: "1", lesson: LY_LESSON, idSubject: "Physics");
            validClass[2]  = new ClassOfTimetable(idClass: "H-1", idLecture: "3", lesson: HOA_LESSON, idSubject: "Chemistry");
            validClass[3]  = new ClassOfTimetable(idClass: "S-1", idLecture: "5", lesson: Biology_LESSON, idSubject: "Biology");
            validClass[4]  = new ClassOfTimetable(idClass: "V-1", idLecture: "1", lesson: VAN_LESSON, idSubject: "Literature");
            validClass[5]  = new ClassOfTimetable(idClass: "LS-1", idLecture: "1", lesson: SU_LESSON, idSubject: "History");
            validClass[6]  = new ClassOfTimetable(idClass: "Đ-1", idLecture: "6", lesson: DIA_LESSON, idSubject: "Geography");
            validClass[7]  = new ClassOfTimetable(idClass: "A-1", idLecture: "6", lesson: ANH_LESSON, idSubject: "English");
            validClass[8]  = new ClassOfTimetable(idClass: "GDCD-1", idLecture: "6", lesson: GDCD_LESSON, idSubject: "Civic Education");
            validClass[9]  = new ClassOfTimetable(idClass: "CN-1", idLecture: "6", lesson: CONGNGHE_LESSON, idSubject: "Technology");
            validClass[10] = new ClassOfTimetable(idClass: "TD-1", idLecture: "6", lesson: THEDUC_LESSON, idSubject: "Physical Education");
            validClass[11] = new ClassOfTimetable(idClass: "MT-1", idLecture: "6", lesson: MYTHUAT_LESSON, idSubject: "Fine Art");
            validClass[12] = new ClassOfTimetable(idClass: "TC-1", idLecture: "6", lesson: TUCHON_LESSON, idSubject: "Free");

            timetable = new ClassOfTimetable[MAX_DAY, MAX_LESSON];
            Console.WriteLine(MAX_DAY * MAX_LESSON);

            A : genericAlgorithm = new GeneticAlgorithm(populationSize : populationSize, dnaSize : 30, random, getRandomGene,
                                                        fitnessFunction, elitism, mutationRate);



            while (!genericAlgorithm.isStop)
            {
                Update();
            }
            outGene(genericAlgorithm.BestGenes);
            export(genericAlgorithm.BestGenes);

            ConsoleKeyInfo keyinfo;

            do
            {
                keyinfo = Console.ReadKey();
                Console.WriteLine(keyinfo.Key + " was pressed");
                if (keyinfo.Key == ConsoleKey.Enter)
                {
                    genericAlgorithm.isStop = false;
                    goto A;
                }
                else if (keyinfo.Key == ConsoleKey.Escape)
                {
                    break;
                }
            }while (keyinfo.Key != ConsoleKey.X);
            Console.ReadLine();
        }
Exemplo n.º 2
0
        static bool validDay(ClassOfTimetable class1, ClassOfTimetable class2,
                             ClassOfTimetable class3, ClassOfTimetable class4, ClassOfTimetable class5)
        {
            int toan = 0, ly = 0, hoa = 0, van = 0,
                su = 0, dia = 0, Biology = 0, anh = 0,
                gdcn = 0, theduc = 0, tuchon = 0,
                congnghe = 0, mythuat = 0, Biologyhoat = 0;

            switch (class1.idClass)
            {
            case "T-1":
                toan++;
                break;

            case "L-1":
                ly++;
                break;

            case "H-1":
                hoa++;
                break;

            case "V-1":
                van++;
                break;

            case "LS-1":
                su++;
                break;

            case "Đ-1":
                dia++;
                break;

            case "S-1":
                Biology++;
                break;

            case "A-1":
                anh++;
                break;

            case "GDCD-1":
                gdcn++;
                break;

            case "CN-1":
                congnghe++;
                break;

            case "TD-1":
                theduc++;
                break;

            case "TC-1":
                tuchon++;
                break;

            case "SH-1":
                Biologyhoat++;
                break;

            case "MT-1":
                mythuat++;
                break;
            }
            switch (class2.idClass)
            {
            case "T-1":
                toan++;
                break;

            case "L-1":
                ly++;
                break;

            case "H-1":
                hoa++;
                break;

            case "V-1":
                van++;
                break;

            case "LS-1":
                su++;
                break;

            case "Đ-1":
                dia++;
                break;

            case "S-1":
                Biology++;
                break;

            case "A-1":
                anh++;
                break;

            case "GDCD-1":
                gdcn++;
                break;

            case "CN-1":
                congnghe++;
                break;

            case "TD-1":
                theduc++;
                break;

            case "TC-1":
                tuchon++;
                break;

            case "SH-1":
                Biologyhoat++;
                break;

            case "MT-1":
                mythuat++;
                break;
            }
            switch (class3.idClass)
            {
            case "T-1":
                toan++;
                break;

            case "L-1":
                ly++;
                break;

            case "H-1":
                hoa++;
                break;

            case "V-1":
                van++;
                break;

            case "LS-1":
                su++;
                break;

            case "Đ-1":
                dia++;
                break;

            case "S-1":
                Biology++;
                break;

            case "A-1":
                anh++;
                break;

            case "GDCD-1":
                gdcn++;
                break;

            case "CN-1":
                congnghe++;
                break;

            case "TD-1":
                theduc++;
                break;

            case "TC-1":
                tuchon++;
                break;

            case "SH-1":
                Biologyhoat++;
                break;

            case "MT-1":
                mythuat++;
                break;
            }

            switch (class4.idClass)
            {
            case "T-1":
                toan++;
                break;

            case "L-1":
                ly++;
                break;

            case "H-1":
                hoa++;
                break;

            case "V-1":
                van++;
                break;

            case "LS-1":
                su++;
                break;

            case "Đ-1":
                dia++;
                break;

            case "S-1":
                Biology++;
                break;

            case "A-1":
                anh++;
                break;

            case "GDCD-1":
                gdcn++;
                break;

            case "CN-1":
                congnghe++;
                break;

            case "TD-1":
                theduc++;
                break;

            case "TC-1":
                tuchon++;
                break;

            case "SH-1":
                Biologyhoat++;
                break;

            case "MT-1":
                mythuat++;
                break;
            }
            switch (class5.idClass)
            {
            case "T-1":
                toan++;
                break;

            case "L-1":
                ly++;
                break;

            case "H-1":
                hoa++;
                break;

            case "V-1":
                van++;
                break;

            case "LS-1":
                su++;
                break;

            case "Đ-1":
                dia++;
                break;

            case "S-1":
                Biology++;
                break;

            case "A-1":
                anh++;
                break;

            case "GDCD-1":
                gdcn++;
                break;

            case "CN-1":
                congnghe++;
                break;

            case "TD-1":
                theduc++;
                break;

            case "TC-1":
                tuchon++;
                break;

            case "SH-1":
                Biologyhoat++;
                break;

            case "MT-1":
                mythuat++;
                break;
            }
            if (toan > 2 || van > 2 || ly > 1 || hoa > 1 || van > 1 ||
                su > 1 || dia > 1 || Biology > 1 || anh > 1 ||
                gdcn > 1 || theduc > 1 || tuchon > 1 ||
                congnghe > 1 || mythuat > 1 || Biologyhoat > 1)
            {
                return(false);
            }
            if (toan == 2 || van == 2)
            {
                if (!(class1.idClass == class2.idClass || class2.idClass == class3.idClass || class3.idClass == class4.idClass || class4.idClass == class5.idClass))
                {
                    return(false);
                }
            }
            return(true);
        }