public ActionResult RegisterforDOC()
        {
            CollegeDatabaseEntities10 db = new CollegeDatabaseEntities10();

            //var depts = db.Departments.ToList();
            return(View());
        }
Example #2
0
        public static int EnterDataForCourser()
        {
            CollegeDatabaseEntities10 db1 = new CollegeDatabaseEntities10();
            var course_list = (from x in db1.Courses
                               select x.ID).ToList();
            var Ava_time = (from x in db1.Doctor_Available_Time
                            select x.Course_id).ToList();
            int enter = 0;

            for (int i = 0; i < course_list.Count(); i++)
            {
                for (int j = 0; j < Ava_time.Count(); j++)
                {
                    if (course_list[i] == Ava_time[j])
                    {
                        enter++;
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            return(enter);
        }
Example #3
0
        public static List <KeyValuePair <string, int> > HallsData()
        {
            List <KeyValuePair <string, int> > final = new List <KeyValuePair <string, int> >();
            CollegeDatabaseEntities10          db1   = new CollegeDatabaseEntities10();
            var rooms_list = (from x in db1.Rooms
                              where x.RoomType_id == 1
                              select new { x.ID, x.Name }).ToList();
            var lecture_rooms = (from x in db1.LectureTimes
                                 select x.Room_id).ToList();



            for (int i = 0; i < rooms_list.Count(); i++)
            {
                int counter = 0;
                for (int j = 0; j < lecture_rooms.Count(); j++)
                {
                    if (rooms_list[i].ID == lecture_rooms[j])
                    {
                        counter++;
                    }
                }
                if (counter != 0)
                {
                    final.Add(new KeyValuePair <string, int>(rooms_list[i].Name, counter));
                }
            }
            return(final);
        }
Example #4
0
        public static int totalHoursForEachTa()
        {
            CollegeDatabaseEntities10 db = new CollegeDatabaseEntities10();
            // total Hours for Courses
            var courseInfo = (from x in db.Courses
                              select new { x.AcademicYear_id, x.SectionHours, x.LabHours }).ToList();
            int courseTotal = 0;

            for (int i = 0; i < courseInfo.Count; i++)
            {
                int courseHour = Convert.ToInt32(courseInfo[i].SectionHours);
                int labHour    = Convert.ToInt32(courseInfo[i].LabHours);
                courseTotal += totalHoursForCourse((Convert.ToInt32(courseInfo[i].AcademicYear_id)), courseHour, labHour);
            }
            // tAs Number
            var taList = (from x in db.AspNetUsers
                          where x.type == "Ta"
                          select x.Id);

            int taCount = taList.Count();

            while (courseTotal % taCount != 0)
            {
                courseTotal++;
            }
            int avg_ForEachTa = courseTotal / taCount;

            return(avg_ForEachTa);
        }
Example #5
0
        public static int Not_EnterDataTa()
        {
            CollegeDatabaseEntities10 db1 = new CollegeDatabaseEntities10();
            var ta_list = (from x in db1.AspNetUsers
                           where x.type == "Ta"
                           select x.Id).ToList();
            var wishes = (from x in db1.Ta_Wishes
                          select x.Ta_Id).ToList();
            int not_enter = 0;



            for (int i = 0; i < ta_list.Count(); i++)
            {
                bool check = false;
                for (int j = 0; j < wishes.Count(); j++)
                {
                    if (ta_list[i] == wishes[j])
                    {
                        check = true;
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                if (check == false)
                {
                    not_enter++;
                }
            }
            return(not_enter);
        }
Example #6
0
        // rturn list of string b IDs elvictims
        static List <string> Victims()
        {
            CollegeDatabaseEntities10 db      = new CollegeDatabaseEntities10();
            List <string>             victims = new List <string>();
            // bgeb id elyear w elsemseter ely fat
            var years = (from x in db.Years
                         select x.ID).ToList();
            List <int> yearss = new List <int>();
            int        lastyear;

            if (years.Count() == 1)
            {
                return(victims);
            }
            else
            {
                for (int i = 0; i < years.Count(); i++)
                {
                    yearss.Add(years[i]);
                }

                lastyear = yearss[years.Count() - 2];
            }
            // hgeb victim elterm ely fat
            var victim = (from x in db.VictimHistories
                          where x.Year_id == lastyear
                          select x.Ta_id).ToList();

            for (int i = 0; i < victim.Count(); i++)
            {
                victims.Add(victim[i]);
            }

            return(victims);
        }
Example #7
0
        public static int Not_EnterDataCourse()
        {
            CollegeDatabaseEntities10 db1 = new CollegeDatabaseEntities10();
            var course_list = (from x in db1.Courses

                               select x.ID).ToList();
            var avai_time = (from x in db1.Doctor_Available_Time
                             select x.Course_id).ToList();
            int not_enter = 0;



            for (int i = 0; i < course_list.Count(); i++)
            {
                bool check = false;
                for (int j = 0; j < avai_time.Count(); j++)
                {
                    if (course_list[i] == avai_time[j])
                    {
                        check = true;
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                if (check == false)
                {
                    not_enter++;
                }
            }
            return(not_enter);
        }
Example #8
0
        private static List <SectionTimeTable> SectionTimeTableIntialize(List <GroupModel> GrpList)
        {
            CollegeDatabaseEntities10 db = new CollegeDatabaseEntities10();
            var sections = db.Sections.ToList();
            List <SectionTimeTable> list = new List <SectionTimeTable>();

            foreach (var item in sections)
            {
                list.Add(new SectionTimeTable(item.Grp_id.Value, item.Year_id, item.ID));

                var grp_timetable = GrpList.Where(x => x.GrpId == item.Grp_id).Single();
                for (int i = 0; i < grp_timetable.Week.Count(); i++)
                {
                    for (int j = 0; j < 12; j++)
                    {
                        if (grp_timetable.Week[i].Slots[j] == true)
                        {
                            list.Last().Week[i].Slots[j] = true;
                        }
                        else
                        {
                            list.Last().Week[i].Slots[j] = false;
                        }
                        //list.Last().Week[i].Slots = grp_timetable.Week[i].Slots;
                    }
                    list.Last().Week[i].GetNoHours();
                }
            }
            return(list);
        }
Example #9
0
        // GET: Home
        //public ActionResult profile()
        //{
        //    //AspNetUser  Aspuser =new
        //    //    (from c in db.AspNetUsers
        //    //            where c.Id == User.Identity.GetUserId()
        //    //            select c).ToList();
        //    return View();
        //}

        public ActionResult About()
        {
            ViewBag.Message = "The generation done successfully";
            CollegeDatabaseEntities10 _db = new CollegeDatabaseEntities10();

            var del = (from x in db.LectureTimes
                       select x);

            db.LectureTimes.RemoveRange(del);

            var dell = (from x in db.SectionTimes
                        select x);

            db.SectionTimes.RemoveRange(dell);
            // var res = functions.Generatelecandsec()
            List <GroupModel> GrpList = new List <GroupModel>();
            functions         func    = new functions();
            var res          = func.Generate_lect(ref GrpList);
            var assin        = func.generatesecs(GrpList);
            var lecTimeTable = new LectureTime();

            foreach (var item in res)
            {
                var crs_id = _db.Courses.Where(x => x.Name == item.CourseName).Select(x => x.ID).Single();
                lecTimeTable = new LectureTime()
                {
                    Course_id = crs_id, Room_id = item.RoomId, DayOfWeek = item.Day, Grp_id = item.GrpId, StartHour = item.StartHour
                };
                _db.LectureTimes.Add(lecTimeTable);
                _db.SaveChanges();
                Console.WriteLine("{0} : {1} : {2}", item.CourseName, item.StartHour, item.Day.ToString());
            }
            foreach (var item in assin)
            {
                if (item.RoomId != -1)

                {
                    SectionTime x = new SectionTime();
                    x.Course_id  = item.CourseId;
                    x.Section_id = item.SectionId;
                    x.Room_id    = item.RoomId;
                    x.DayOfWeek  = item.Day;
                    x.StartHour  = item.Start;
                    x.isLab      = item.IsLab;
                    x.isSection  = item.IsSection;
                    // if(item.Tasids)
                    x.Ta_id = item.Tasids[0];
                    _db.SectionTimes.Add(x);
                    _db.SaveChanges();
                }
            }


            return(View());
        }
Example #10
0
        private static bool isConsistent(int roomid, Doctor_Available_Time doctor_Available_Time, List <Assignement> assignment, GroupModel GrpTable, List <string> doc_ids)
        {
            CollegeDatabaseEntities10 _db = new CollegeDatabaseEntities10();

            //var s = _db.lin
            // var num = _db.doctor_Available_Time.Course_id;
            foreach (var item in assignment)
            {
                for (int i = 0; i < doc_ids.Count; i++)
                {
                    if ((doctor_Available_Time.DayOfWeek == item.Day) && ((doctor_Available_Time.StartHour >= item.StartHour && doctor_Available_Time.StartHour < item.EndHour) ||
                                                                          (doctor_Available_Time.StartHour + doctor_Available_Time.Course.Hours > item.StartHour &&
                                                                           doctor_Available_Time.StartHour + doctor_Available_Time.Course.Hours <= item.EndHour) ||
                                                                          (item.StartHour >= doctor_Available_Time.StartHour && item.StartHour < doctor_Available_Time.StartHour + doctor_Available_Time.Course.Hours) ||
                                                                          (item.EndHour > doctor_Available_Time.StartHour && item.EndHour <= doctor_Available_Time.StartHour + doctor_Available_Time.Course.Hours)) &&
                        (item.RoomId == roomid || item.Doc_ids.Contains(doc_ids[i]) || GrpTable.GrpId == item.GrpId))
                    {
                        return(false);
                    }
                }
            }
            GrpTable.Week[doctor_Available_Time.DayOfWeek - 1].addinterval(doctor_Available_Time.Course.ID, roomid, doctor_Available_Time.StartHour,
                                                                           doctor_Available_Time.StartHour + doctor_Available_Time.Course.Hours);
            //CollegeDatabaseEntities2 _db = new CollegeDatabaseEntities2();

            //var adminConstraints = _db.AcademicYears.Where(x => x.ID == doctor_Available_Time.Course.AcademicYear_id).Single();
            if (GrpTable.FreeDaysCount() < 1)
            {
                GrpTable.Week[doctor_Available_Time.DayOfWeek - 1].Removeinterval(doctor_Available_Time.Course.ID);
                return(false);
            }


            /*if (GrpTable.Week[doctor_Available_Time.DayOfWeek - 1].NumfHours > doctor_Available_Time.Course.AcademicYear.DayWorkHours)
             * {
             *  GrpTable.Week[doctor_Available_Time.DayOfWeek - 1].Removeinterval(doctor_Available_Time.Course.ID);
             *  return false;
             * }*/

            var TempSecHours = _db.Courses.OrderBy(x => x.SectionHours).Select(x => x.SectionHours).Where(x => x.HasValue).Take(1).Single();/* Select(x=>x.SectionHours).Take(1).Last();*/
            var TempLabHours = _db.Courses.OrderBy(x => x.LabHours).Select(x => x.LabHours).Where(x => x.HasValue).Take(1).Single();


            if (GrpTable.Week[doctor_Available_Time.DayOfWeek - 1].Gap > doctor_Available_Time.Course.AcademicYear.AllowedGapHours)
            {
                var GapAfterSecs = GrpTable.Week[doctor_Available_Time.DayOfWeek - 1].Gap % TempSecHours;
                var GapAfterLabs = GrpTable.Week[doctor_Available_Time.DayOfWeek - 1].Gap % TempLabHours;
                if (GapAfterSecs > doctor_Available_Time.Course.AcademicYear.AllowedGapHours && GapAfterLabs > doctor_Available_Time.Course.AcademicYear.AllowedGapHours)
                {
                    GrpTable.Week[doctor_Available_Time.DayOfWeek - 1].Removeinterval(doctor_Available_Time.Course.ID);
                    return(false);
                }
            }
            return(true);
        }
Example #11
0
        public static int totalHoursForCourse(int acadmicYear_id, int courseHour, int labHour)
        {
            CollegeDatabaseEntities10 db = new CollegeDatabaseEntities10();
            var sectionsCount            = (from x in db.AcademicYears
                                            where x.ID == acadmicYear_id
                                            select x.SectionCount).Single();
            int totalHours = Convert.ToInt32(sectionsCount) * (courseHour + (labHour * 2));


            return(totalHours);
        }
Example #12
0
        private static List <TaTimetable> Mo3eeeeed()
        {
            CollegeDatabaseEntities10 db = new CollegeDatabaseEntities10();
            var roles = db.AspNetRoles.Where(x => x.Name == "TA").ToList();
            var mo3ed = roles[0].AspNetUsers.ToList();
            List <TaTimetable> talist = new List <TaTimetable>();

            foreach (var item in mo3ed)
            {
                var crsformo3edd = db.LinkDoctorCourses.Where(x => x.Doctor_id == item.Id).ToList();
                List <KeyValuePair <int, int?> > hosam = new List <KeyValuePair <int, int?> >();
                foreach (var itemo in crsformo3edd)
                {
                    hosam.Add(new KeyValuePair <int, int?>(itemo.Course_id, itemo.hours));
                }
                talist.Add(new TaTimetable(item.Id, hosam));
            }

            return(talist);
        }
Example #13
0
        /// <summary>
        /// //sectionnnnnnnnnnnn
        /// </summary>
        /// <param name="sortedTAList"></param>
        /// <param name="courseList"></param>
        /// <param name="taForCourse"></param>
        ///

        private static List <SectionsVariables> SectionIntialize()
        {
            CollegeDatabaseEntities10 db         = new CollegeDatabaseEntities10();
            List <SectionsVariables>  SectionVar = new List <SectionsVariables>();


            var list = (from
                        course in db.Courses
                        where (course.Doctor_Available_Time.Any() && course.AcademicYear_id == 2)
                        select new { course }).ToList();



            foreach (var crs in list)
            {
                if (crs.course.HaveLab || crs.course.HaveSection)
                {
                    var grps = crs.course.AcademicYear.Groups.ToList();

                    foreach (var grp in grps)
                    {
                        var sections = db.Sections.Where(x => x.Grp_id == grp.ID).ToList();
                        for (int i = 0; i < sections.Count; i++)
                        {
                            if (crs.course.HaveLab)
                            {
                                SectionVar.Add(new SectionsVariables(sections[i].ID, crs.course.ID, grp.ID, crs.course.HaveLab, false, crs.course.LabHours.Value, 0));
                            }
                            if (crs.course.HaveSection)
                            {
                                SectionVar.Add(new SectionsVariables(sections[i].ID, crs.course.ID, grp.ID, false, crs.course.HaveSection, 0, crs.course.SectionHours.Value));
                            }
                        }
                    }
                }
            }
            return(SectionVar);
        }
Example #14
0
        private static List <RoomsTimeTables> Roominit(List <GroupModel> GrpList)
        {
            CollegeDatabaseEntities10 db  = new CollegeDatabaseEntities10();
            List <RoomsTimeTables>    rom = new List <RoomsTimeTables>();
            // List<RoomDay> romd = new List<RoomDay>();
            var rooms = db.Rooms.ToList();

            foreach (var item in rooms)
            {
                rom.Add(new RoomsTimeTables(item.ID, item.RoomType_id));
            }
            foreach (var item in GrpList)
            {
                foreach (var item2 in item.Week)
                {
                    foreach (var item3 in item2.CourseStartEnd)
                    {
                        var ind = rom.IndexOf(rom.Where(x => x.Roomid == item3.Value.RoomId).Single());
                        rom[ind].Week[item2.Id].ReserveInterval(item3.Value.Start - 8, item3.Value.End - 1 - 8);
                    }
                }
            }
            return(rom);
        }
Example #15
0
        public static void MainAlgo()
        {
            CollegeDatabaseEntities10 db = new CollegeDatabaseEntities10();
            // Declare lists
            List <course>      courseList  = new List <course>();
            List <ta>          taList      = new List <ta>();
            List <TaForCourse> taForCourse = new List <TaForCourse>();
            // load data from database in course List
            var courseListdb = (from x in db.Courses
                                select new { x.ID, x.LabHours, x.SectionHours, x.AcademicYear_id }).ToList();

            for (int i = 0; i < courseListdb.Count(); i++)
            {
                if (courseListdb[i].LabHours != null || courseListdb[i].SectionHours != null)
                {
                    int courseHour = Convert.ToInt32(courseListdb[i].SectionHours);
                    int labHour    = Convert.ToInt32(courseListdb[i].LabHours);
                    int total      = totalHoursForCourse(courseListdb[i].AcademicYear_id, courseHour, labHour);
                    courseList.Add(new course((Convert.ToInt32(courseListdb[i].ID)), courseHour, total, labHour));
                }
            }

            // load data from database in ta list
            var taInfo = (from x in db.AspNetUsers
                          where x.type == "Ta"
                          select new { x.Id, x.Experience }).ToList();

            var tawishesList = (from x in db.Ta_Wishes
                                select new { x.Ta_Id, x.Course_Id, x.Priority }).ToList();

            for (int i = 0; i < taInfo.Count(); i++)
            {
                int wish1 = 0;
                int wish2 = 0;
                for (int j = 0; j < tawishesList.Count(); j++)
                {
                    string ta_info_id  = Convert.ToString(taInfo[i].Id);
                    string ta_wish_id  = Convert.ToString(tawishesList[j].Ta_Id);
                    int    ta_wish_pri = Convert.ToInt32(tawishesList[j].Priority);
                    if (ta_info_id == ta_wish_id)
                    {
                        if (ta_wish_pri == 1)
                        {
                            wish1 = Convert.ToInt32(tawishesList[j].Course_Id);
                        }
                        else if (ta_wish_pri == 2)
                        {
                            //if (wish1 == 0)
                            //{
                            //    j = 0;
                            //    continue;
                            //}
                            wish2 = Convert.ToInt32(tawishesList[j].Course_Id);
                        }
                        else if (ta_wish_pri == 3)
                        {
                            //if (wish2 == 0)
                            //{
                            //    j = 0;
                            //    continue;
                            //}
                            taList.Add(new ta(tawishesList[j].Ta_Id, wish1, wish2, Convert.ToInt32(tawishesList[j].Course_Id), totalHoursForEachTa(), (Convert.ToInt32(taInfo[i].Experience))));
                            break;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }

            // choose victim from list
            List <ta>     victimList    = new List <ta>();
            List <ta>     nonVictimList = new List <ta>();
            List <string> temp          = Victims();

            for (int i = 0; i < taList.Count(); i++)
            {
                bool check = false;
                for (int j = 0; j < temp.Count(); j++)
                {
                    if (temp[j] == taList[i].id)
                    {
                        victimList.Add(new ta(taList[i].id, taList[i].wish1, taList[i].wish2, taList[i].wish3, taList[i].remain_hours, taList[i].experiance));
                        check = true;
                        break;
                    }
                }
                if (check == false)
                {
                    nonVictimList.Add(new ta(taList[i].id, taList[i].wish1, taList[i].wish2, taList[i].wish3, taList[i].remain_hours, taList[i].experiance));
                }
            }
            // sort taList by experiance
            List <ta> sortedTAList = new List <ta>();

            sortedTAList = sortList(victimList);
            // algorithm elawl ll victim
            TaForEachCourse(sortedTAList, courseList, taForCourse);
            // algorithm l sana 4
            List <ta>     remain_ta     = new List <ta>();
            List <course> remain_course = new List <course>();

            for (int i = 0; i < sortedTAList.Count(); i++)
            {
                remain_ta.Add(new ta(sortedTAList[i].id, sortedTAList[i].wish1, sortedTAList[i].wish2, sortedTAList[i].wish3, sortedTAList[i].remain_hours, sortedTAList[i].experiance));
            }
            sortedTAList = new List <ta>();
            sortedTAList = sortList(nonVictimList);
            // choose mwad sana 4
            var academic_4_id = (from x in db.AcademicYears
                                 where x.AcademicYear1 == 4
                                 select x.ID).SingleOrDefault();
            int acad_4     = Convert.ToInt32(academic_4_id);
            var academic_4 = (from x in db.Courses
                              where x.AcademicYear_id == acad_4
                              select x.ID).ToList();
            List <int> academic_list = new List <int>();

            for (int i = 0; i < academic_4.Count(); i++)
            {
                academic_list.Add(academic_4[i]);
            }
            List <course> courses_4    = new List <course>();
            List <course> coursesNot_4 = new List <course>();

            for (int i = 0; i < courseList.Count(); i++)
            {
                bool check = false;
                for (int j = 0; j < academic_list.Count(); j++)
                {
                    if (academic_list[j] == courseList[i].id)
                    {
                        courses_4.Add(new course(courseList[i].id, courseList[i].course_hours, courseList[i].remain_hours, courseList[i].lab_hours));

                        check = true;
                        break;
                    }
                }
                if (check == false)
                {
                    coursesNot_4.Add(new course(courseList[i].id, courseList[i].course_hours, courseList[i].remain_hours, courseList[i].lab_hours));
                }
            }

            TaForEachCourse(sortedTAList, courses_4, taForCourse);
            for (int i = 0; i < courses_4.Count(); i++)
            {
                remain_course.Add(new course(courses_4[i].id, courses_4[i].course_hours, courses_4[i].remain_hours, courses_4[i].lab_hours));
            }
            TaForEachCourse(sortedTAList, coursesNot_4, taForCourse);
            for (int i = 0; i < sortedTAList.Count(); i++)
            {
                remain_ta.Add(new ta(sortedTAList[i].id, sortedTAList[i].wish1, sortedTAList[i].wish2, sortedTAList[i].wish3, sortedTAList[i].remain_hours, sortedTAList[i].experiance));
            }

            for (int i = 0; i < coursesNot_4.Count(); i++)
            {
                remain_course.Add(new course(coursesNot_4[i].id, coursesNot_4[i].course_hours, coursesNot_4[i].remain_hours, coursesNot_4[i].lab_hours));
            }
            // elyear ely ana feha 3shan a add elvictim
            var years = (from x in db.Years
                         select x.ID).ToList();
            List <int> yearss = new List <int>();
            int        year;

            if (years.Count() == 1)
            {
                year = 1;
            }
            else
            {
                for (int i = 0; i < years.Count(); i++)
                {
                    yearss.Add(years[i]);
                }

                year = yearss[years.Count() - 1];
            }

            var victim = (from x in db.VictimHistories
                          where x.Year_id == year
                          select x.Ta_id).ToList();

            for (int i = 0; i < remain_ta.Count(); i++)
            {
                VictimHistory victim1 = new VictimHistory();
                victim1.Ta_id   = remain_ta[i].id;
                victim1.Year_id = year;
                db.VictimHistories.Add(victim1);
                db.SaveChanges();
            }
            remain_ta = sortList(remain_ta);
            // lw remain ta = remain course
            for (int i = 0; i < remain_ta.Count(); i++)
            {
                for (int j = 0; j < remain_course.Count(); j++)
                {
                    if (remain_ta[i].remain_hours == remain_course[j].remain_hours)
                    {
                        if (remain_ta[i].remain_hours != 0)
                        {
                            LinkDoctorCourse link = new LinkDoctorCourse();
                            link.Course_id = remain_course[j].id;
                            link.Doctor_id = remain_ta[i].id;
                            link.hours     = remain_ta[i].remain_hours;

                            db.LinkDoctorCourses.Add(link);
                            db.SaveChanges();
                        }
                        remain_ta.Remove(remain_ta[i]);
                        if (i > 0 && i != remain_ta.Count() - 1)
                        {
                            i--;
                        }
                        else if (i == 0)
                        {
                            i = 0;
                        }
                        remain_course.Remove(remain_course[j]);
                        if (j > 0 && j != remain_course.Count() - 1)
                        {
                            j--;
                        }
                        else if (j == 0)
                        {
                            j = 0;
                        }
                    }
                }
            }
            // lw remain ta >< remain course
            for (int i = 0; i < remain_ta.Count(); i++)
            {
                for (int j = 0; j < remain_course.Count(); j++)
                {
                    if (remain_ta[i].remain_hours > remain_course[j].remain_hours)
                    {
                        if (remain_course[j].course_hours != 0 && remain_ta[i].remain_hours % remain_course[j].course_hours != 0)
                        {
                            while (remain_ta[i].remain_hours % remain_course[j].course_hours != 0)
                            {
                                remain_ta[i].remain_hours--;
                            }
                        }
                        if (remain_course[j].lab_hours != 0 && remain_ta[i].remain_hours % remain_course[j].lab_hours != 0)
                        {
                            while (remain_ta[i].remain_hours % remain_course[j].lab_hours != 0)
                            {
                                remain_ta[i].remain_hours--;
                            }
                        }
                        if (remain_course[j].remain_hours != 0)
                        {
                            LinkDoctorCourse link = new LinkDoctorCourse();
                            link.Course_id = remain_course[j].id;
                            link.Doctor_id = remain_ta[i].id;
                            link.hours     = remain_course[j].remain_hours;
                            db.LinkDoctorCourses.Add(link);
                            db.SaveChanges();
                        }
                        remain_ta[i].remain_hours -= remain_course[j].remain_hours;
                        remain_course.Remove(remain_course[j]);
                        if (j > 0 && j != remain_course.Count() - 1)
                        {
                            j--;
                        }
                        else if (j == 0)
                        {
                            j = 0;
                        }
                    }
                    // lw course hours > ta hours
                    else
                    {
                        if (remain_course[j].course_hours != 0 && remain_ta[i].remain_hours % remain_course[j].course_hours != 0)
                        {
                            while (remain_ta[i].remain_hours % remain_course[j].course_hours != 0)
                            {
                                remain_ta[i].remain_hours++;
                            }
                        }
                        if (remain_course[j].lab_hours != 0 && remain_ta[i].remain_hours % remain_course[j].lab_hours != 0)
                        {
                            while (remain_ta[i].remain_hours % remain_course[j].lab_hours != 0)
                            {
                                remain_ta[i].remain_hours++;
                            }
                        }
                        if (remain_ta[i].remain_hours != 0)
                        {
                            LinkDoctorCourse link = new LinkDoctorCourse();
                            link.Course_id = remain_course[j].id;
                            link.Doctor_id = remain_ta[i].id;
                            link.hours     = remain_ta[i].remain_hours;
                            db.LinkDoctorCourses.Add(link);
                            db.SaveChanges();
                        }
                        remain_course[j].remain_hours -= remain_ta[i].remain_hours;
                        remain_ta.Remove(remain_ta[i]);
                        if (i > 0 && i != remain_ta.Count() - 1)
                        {
                            i--;
                        }
                        else if (i == 0)
                        {
                            i = 0;
                        }
                    }
                }
            }
        }
Example #16
0
        private static List <Assignement> Recursive_Backtracking_Search(List <Assignement> assignment, List <Variables> variables, ref List <GroupModel> GrpList)

        {
            CollegeDatabaseEntities10 db = new CollegeDatabaseEntities10();

            if (assignment.Count == variables.Count)
            {
                return(assignment);
            }
            var          unSelectedVar     = Select_UnAssigned_Course(assignment, variables);
            var          allDeptsForCourse = db.LinkCourseDepts.Where(x => x.Course_id == unSelectedVar.course.ID).ToList();
            List <Group> allgroups         = new List <Group>();

            if (allDeptsForCourse.Count > 1)
            {
                foreach (var dept in allDeptsForCourse)
                {
                    var grpsfordept = db.Groups.Where(x => x.Department_id == dept.Department_id).ToList();
                    foreach (var item in grpsfordept)
                    {
                        allgroups.Add(item);
                    }
                }
            }
            //   var domain_Values_for_unselctedVar = Domain.Where(x => x.RoomId == unSelectedVar).ToList();
            for (int i = 0; i < unSelectedVar.Rooms.Count; i++)
            {
                for (int j = 0; j < unSelectedVar.DocAvailTime.Count; j++)
                {
                    if (allDeptsForCourse.Count > 1)
                    {
                        if (isConsistentForDepts(unSelectedVar.Rooms[i].ID, unSelectedVar.DocAvailTime[j], assignment, GrpList, allgroups, unSelectedVar.Doc_ids))

                        {
                            foreach (var item in allgroups)
                            {
                                assignment.Add(new Assignement(unSelectedVar.course.Name, item.ID, unSelectedVar.course.AcademicYear_id
                                                               , unSelectedVar.DocAvailTime[j].DayOfWeek, unSelectedVar.DocAvailTime[j].StartHour,
                                                               unSelectedVar.DocAvailTime[j].StartHour + unSelectedVar.course.Hours,
                                                               unSelectedVar.Rooms[i].ID, unSelectedVar.course.ID, unSelectedVar.Doc_ids));
                            }
                            var result = Recursive_Backtracking_Search(assignment, variables, ref GrpList);

                            if (result[0].CourseName != "Failure")
                            {
                                return(result);
                            }
                            else
                            {
                                foreach (var item in allgroups)
                                {
                                    assignment.Remove(assignment.Where(x => x.Course_id == unSelectedVar.course.ID && x.GrpId == item.ID).Single());
                                    GrpList.Where(x => x.GrpId == item.ID).Single().Week[unSelectedVar.DocAvailTime[j].DayOfWeek - 1].Removeinterval(unSelectedVar.course.ID);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (isConsistent(unSelectedVar.Rooms[i].ID, unSelectedVar.DocAvailTime[j], assignment, GrpList.Where(x => x.GrpId == unSelectedVar.GroupId).Single(), unSelectedVar.Doc_ids))
                        {
                            assignment.Add(new Assignement(unSelectedVar.course.Name, unSelectedVar.GroupId, unSelectedVar.course.AcademicYear_id
                                                           , unSelectedVar.DocAvailTime[j].DayOfWeek, unSelectedVar.DocAvailTime[j].StartHour,
                                                           unSelectedVar.DocAvailTime[j].StartHour + unSelectedVar.course.Hours,
                                                           unSelectedVar.Rooms[i].ID, unSelectedVar.course.ID, unSelectedVar.Doc_ids));



                            var result = Recursive_Backtracking_Search(assignment, variables, ref GrpList);

                            if (result[0].CourseName != "Failure")
                            {
                                return(result);
                            }
                            else
                            {
                                assignment.Remove(assignment.Where(x => x.Course_id == unSelectedVar.course.ID && x.GrpId == unSelectedVar.GroupId).Single());
                                GrpList.Where(x => x.GrpId == unSelectedVar.GroupId).Single().Week[unSelectedVar.DocAvailTime[j].DayOfWeek - 1].Removeinterval(unSelectedVar.course.ID);
                            }
                        }
                    }
                }
            }



            return(new List <Assignement> {
                new Assignement("Failure", 2, 2, 2, 2, 2, 2, 46, unSelectedVar.Doc_ids)
            });
        }
Example #17
0
        private static bool isConsistentForSection(int start, int end, int day, int SecId, ref List <SectionTimeTable> allSecsTable, List <TaTimetable> TaTable,
                                                   SectionsVariables UNsection, ref List <RoomsTimeTables> rooms, ref int roomid, ref List <string> tasids)
        {
            CollegeDatabaseEntities10 db = new CollegeDatabaseEntities10();
            int  indexrom = 0;
            int  indexsec = allSecsTable.IndexOf(allSecsTable.Where(x => x.Sectionid == SecId).Single());
            bool islab    = false;

            if (UNsection.HaveLab)
            {
                islab = true;
            }
            else
            {
                islab = false;
            }
            int roomId = findRoom(start, end, day, rooms, ref indexrom, islab);

            if (roomId == -1)
            {
                return(false);
            }
            roomid = roomId;
            for (int i = start; i <= end; i++)
            {
                if (allSecsTable[indexsec].Week[day].Slots[i] == true)
                {
                    return(false);
                }
            }
            //TA
            var tas = db.LinkDoctorCourses.Where(x => x.Course_id == UNsection.CourseId && x.AspNetUser.type == "Ta").ToList();
            List <TaTimetable> tasforcrs = new List <TaTimetable>();

            foreach (var item in tas)
            {
                TaTimetable query = TaTable.Where(x => x.Id == item.Doctor_id).SingleOrDefault();
                tasforcrs.Add(query);
            }
            List <string> ta_assigned = new List <string>();
            int           count       = 0;
            int           noftas      = 1;

            /*if (UNsection.HaveLab)
             *  noftas = 2;
             * else
             *  noftas++;*/

            for (int i = 0; i < tasforcrs.Count; i++)
            {
                var tatimetable = tasforcrs[i].Course_hours.Where(x => x.Key == UNsection.CourseId).Single();
                if (tatimetable.Value >= (end - start + 1))
                {
                    bool f = true;
                    for (int o = start; o <= end; o++)
                    {
                        if (tasforcrs[i].Week[day].Slots[o] == true)
                        {
                            f = false;
                            break;
                        }
                    }
                    if (f)
                    {
                        var allowedhourss = db.Groups.Where(x => x.ID == UNsection.GroupId).Select(x => x.AcademicYear).Single();
                        var ind           = TaTable.IndexOf(TaTable.Where(x => x.Id == tasforcrs[i].Id).Single());
                        TaTable[ind].Week[day].addinterval(start, end);

                        /*if ((TaTable[ind].Week[day].Gap > allowedhourss.AllowedGapHours || TaTable[ind].Week[day].NumfHours > allowedhourss.DayWorkHours) || TaTable[ind].FreeDaysCount() < 1)
                         * {
                         *  TaTable[ind].Week[day].Removeinterval(start, end);
                         *
                         * }
                         * else
                         * {*/

                        var h = TaTable[ind].Course_hours.IndexOf(TaTable[ind].Course_hours.Where(x => x.Key == UNsection.CourseId).Single());
                        KeyValuePair <int, int?> temppair = new KeyValuePair <int, int?>(TaTable[ind].Course_hours[h].Key, TaTable[ind].Course_hours[h].Value - (end - start + 1));

                        TaTable[ind].Course_hours.RemoveAt(h);
                        TaTable[ind].Course_hours.Add(temppair);
                        ta_assigned.Add(tasforcrs[i].Id);
                        count++;
                        //}
                    }
                }
                if (count == noftas)
                {
                    break;
                }
            }

            if (count < noftas)
            {
                for (int g = 0; g < count; g++)
                {
                    var ind = TaTable.IndexOf(TaTable.Where(x => x.Id == ta_assigned[g]).Single());
                    var h   = TaTable[ind].Course_hours.IndexOf(TaTable[ind].Course_hours.Where(x => x.Key == UNsection.CourseId).Single());
                    KeyValuePair <int, int?> temppair = new KeyValuePair <int, int?>(TaTable[ind].Course_hours[h].Key, TaTable[ind].Course_hours[h].Value + end - start + 1);
                    TaTable[ind].Week[day].Removeinterval(start, end);
                    TaTable[ind].Course_hours.RemoveAt(h);
                    TaTable[ind].Course_hours.Add(temppair);
                }
                ta_assigned.Clear();
                return(false);
            }
            allSecsTable[indexsec].Week[day].Addslots(start, end);
            rooms[indexrom].Week[day].ReserveInterval(start, end);
            //var allowedHours = db.Groups.Where(x => x.ID == UNsection.GroupId).Select(x => x.AcademicYear).Single();

            /*if (allSecsTable[indexsec].Week[day].Gap > allowedHours.AllowedGapHours || allSecsTable[indexsec].Week[day].NumfHours > allowedHours.DayWorkHours)
             * {
             *  allSecsTable[indexsec].Week[day].Removeslots(start, end);
             *  return false;
             * }*/
            /*if (allSecsTable[indexsec].FreeDaysCount() < 1)
             * {
             *  allSecsTable[indexsec].Week[day].Removeslots(start, end);
             *
             *  return false;
             *
             * }*/
            tasids = ta_assigned;
            return(true);
        }
Example #18
0
        private static bool isConsistentForDepts(int roomid, Doctor_Available_Time doctor_Available_Time, List <Assignement> assignment, List <GroupModel> GrpTable, List <Group> allGrps, List <string> doc_ids)
        {
            CollegeDatabaseEntities10 _db = new CollegeDatabaseEntities10();

            //var s = _db.lin
            // var num = _db.doctor_Available_Time.Course_id;
            foreach (var item in assignment)
            {
                /*if ((doctor_Available_Time.DayOfWeek == item.Day) && (doctor_Available_Time.StartHour >= item.StartHour || doctor_Available_Time.StartHour <= item.EndHour) && item.RoomId == roomid)
                 * {
                 *  return false;
                 *
                 * }*/
                for (int j = 0; j < allGrps.Count; j++)
                {
                    for (int i = 0; i < doc_ids.Count; i++)
                    {
                        if ((doctor_Available_Time.DayOfWeek == item.Day) && ((doctor_Available_Time.StartHour >= item.StartHour && doctor_Available_Time.StartHour < item.EndHour) ||
                                                                              (doctor_Available_Time.StartHour + doctor_Available_Time.Course.Hours > item.StartHour &&
                                                                               doctor_Available_Time.StartHour + doctor_Available_Time.Course.Hours <= item.EndHour) ||
                                                                              (item.StartHour >= doctor_Available_Time.StartHour && item.StartHour < doctor_Available_Time.StartHour + doctor_Available_Time.Course.Hours) ||
                                                                              (item.EndHour > doctor_Available_Time.StartHour && item.EndHour <= doctor_Available_Time.StartHour + doctor_Available_Time.Course.Hours)) &&
                            (item.RoomId == roomid || item.Doc_ids.Contains(doc_ids[i]) || allGrps[j].ID == item.GrpId))
                        {
                            return(false);
                        }
                    }
                }
            }

            List <GroupModel> grps = new List <GroupModel>();

            for (int i = 0; i < allGrps.Count; i++)
            {
                GrpTable.Where(x => x.GrpId == allGrps[i].ID).Single().Week[doctor_Available_Time.DayOfWeek - 1].addinterval(doctor_Available_Time.Course.ID, roomid,
                                                                                                                             doctor_Available_Time.StartHour, doctor_Available_Time.StartHour + doctor_Available_Time.Course.Hours);

                grps.Add(GrpTable.Where(x => x.GrpId == allGrps[i].ID).Single());
                //
            }

            for (int j = 0; j < grps.Count; j++)
            {
                if (grps[j].FreeDaysCount() < 1)
                {
                    foreach (var item in grps)
                    {
                        GrpTable.Where(x => x.GrpId == item.GrpId).Single().Week[doctor_Available_Time.DayOfWeek - 1].Removeinterval(doctor_Available_Time.Course.ID);
                    }
                    return(false);
                }


                if (grps[j].Week[doctor_Available_Time.DayOfWeek - 1].NumfHours > doctor_Available_Time.Course.AcademicYear.DayWorkHours)
                {
                    foreach (var item in grps)
                    {
                        GrpTable.Where(x => x.GrpId == item.GrpId).Single().Week[doctor_Available_Time.DayOfWeek - 1].Removeinterval(doctor_Available_Time.Course.ID);
                    }
                    return(false);
                }

                var TempSecHours = _db.Courses.OrderBy(x => x.SectionHours).Select(x => x.SectionHours).Take(1).Single();/* Select(x=>x.SectionHours).Take(1).Last();*/
                var TempLabHours = _db.Courses.OrderBy(x => x.LabHours).Select(x => x.LabHours).Take(1).Single();


                if (grps[j].Week[doctor_Available_Time.DayOfWeek - 1].Gap > doctor_Available_Time.Course.AcademicYear.AllowedGapHours)
                {
                    var GapAfterSecs = grps[j].Week[doctor_Available_Time.DayOfWeek - 1].Gap % TempSecHours;
                    var GapAfterLabs = grps[j].Week[doctor_Available_Time.DayOfWeek - 1].Gap % TempLabHours;
                    if (GapAfterSecs > doctor_Available_Time.Course.AcademicYear.AllowedGapHours && GapAfterLabs > doctor_Available_Time.Course.AcademicYear.AllowedGapHours)
                    {
                        foreach (var item in grps)
                        {
                            GrpTable.Where(x => x.GrpId == item.GrpId).Single().Week[doctor_Available_Time.DayOfWeek - 1].Removeinterval(doctor_Available_Time.Course.ID);
                        }

                        return(false);
                    }
                }
            }
            return(true);
        }
Example #19
0
        public static void TaForEachCourse(List <ta> sortedTAList, List <course> courseList, List <TaForCourse> taForCourse)
        {
            CollegeDatabaseEntities10 db = new CollegeDatabaseEntities10();

            // wish 1
            for (int i = 0; i < sortedTAList.Count(); i++)
            {
                for (int j = 0; j < courseList.Count(); j++)
                {
                    if (courseList[j].id == sortedTAList[i].wish1)
                    {
                        // lw hours elcourse > hours el ta
                        if (courseList[j].remain_hours > sortedTAList[i].remain_hours)
                        {
                            if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                                {
                                    sortedTAList[i].remain_hours++;
                                }
                            }
                            if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                                {
                                    sortedTAList[i].remain_hours++;
                                }
                            }


                            int x = sortedTAList[i].remain_hours;

                            //  sortedTAList[i].remain_hours = courseList[j].remain_hours - x;
                            courseList[j].remain_hours = courseList[j].remain_hours - x;
                            taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
                            // insert record in linkDoctorCourse
                            if (x != 0)
                            {
                                LinkDoctorCourse link = new LinkDoctorCourse();
                                link.Course_id = courseList[j].id;
                                link.Doctor_id = sortedTAList[i].id;
                                link.hours     = x;
                                db.LinkDoctorCourses.Add(link);
                                db.SaveChanges();
                            }
                            // lw elta hours b2t zero aw 22l yshelo mn ellist
                            sortedTAList.Remove(sortedTAList[i]);
                            if (i > 0 && i != sortedTAList.Count() - 1)
                            {
                                i--;
                            }
                            else if (i == 0)
                            {
                                i = 0;
                            }

                            if (courseList[j].remain_hours <= 0)
                            {
                                courseList.Remove(courseList[j]);
                                if (j > 0 && j != courseList.Count() - 1)
                                {
                                    j--;
                                }
                                else if (j == 0)
                                {
                                    j = 0;
                                }
                            }
                            break;
                        }
                        // lw hours ellecture <= hours el ta
                        else
                        {
                            if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                                {
                                    sortedTAList[i].remain_hours--;
                                }
                            }
                            if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                                {
                                    sortedTAList[i].remain_hours--;
                                }
                            }

                            int x = courseList[j].remain_hours;
                            sortedTAList[i].remain_hours = sortedTAList[i].remain_hours - courseList[j].remain_hours;
                            // courseList[j].remain_hours = courseList[j].remain_hours - x;
                            taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
                            // insert record in linkDoctorCourse
                            if (x != 0)
                            {
                                LinkDoctorCourse link = new LinkDoctorCourse();
                                link.Course_id = courseList[j].id;
                                link.Doctor_id = sortedTAList[i].id;
                                link.hours     = x;
                                db.LinkDoctorCourses.Add(link);
                                db.SaveChanges();
                            }

                            if (sortedTAList[i].remain_hours <= 0)
                            {
                                sortedTAList.Remove(sortedTAList[i]);
                                if (i > 0 && i != sortedTAList.Count() - 1)
                                {
                                    i--;
                                }
                                else if (i == 0)
                                {
                                    i = 0;
                                }
                            }


                            courseList.Remove(courseList[j]);
                            if (j > 0 && i != courseList.Count() - 1)
                            {
                                j--;
                            }
                            else if (j == 0)
                            {
                                j = 0;
                            }
                        }
                    }
                }
            }
            //wish2
            for (int i = 0; i < sortedTAList.Count(); i++)
            {
                for (int j = 0; j < courseList.Count(); j++)
                {
                    if (courseList[j].id == sortedTAList[i].wish2)
                    {
                        // lw hours elcourse > hours el ta
                        if (courseList[j].remain_hours > sortedTAList[i].remain_hours)
                        {
                            if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                                {
                                    sortedTAList[i].remain_hours++;
                                }
                            }
                            if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                                {
                                    sortedTAList[i].remain_hours++;
                                }
                            }

                            int x = sortedTAList[i].remain_hours;

                            //sortedTAList[i].remain_hours = courseList[j].remain_hours - x;
                            courseList[j].remain_hours = courseList[j].remain_hours - x;
                            taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
                            // insert record in linkDoctorCourse
                            if (x != 0)
                            {
                                LinkDoctorCourse link = new LinkDoctorCourse();
                                link.Course_id = courseList[j].id;
                                link.Doctor_id = sortedTAList[i].id;
                                link.hours     = x;
                                db.LinkDoctorCourses.Add(link);
                                db.SaveChanges();
                            }
                            // lw elta hours b2t zero aw 22l yshelo mn ellist
                            sortedTAList.Remove(sortedTAList[i]);
                            if (i > 0 && i != sortedTAList.Count() - 1)
                            {
                                i--;
                            }
                            else if (i == 0)
                            {
                                i = 0;
                            }

                            if (courseList[j].remain_hours <= 0)
                            {
                                courseList.Remove(courseList[j]);
                                if (j > 0 && j != courseList.Count() - 1)
                                {
                                    j--;
                                }
                                else if (j == 0)
                                {
                                    j = 0;
                                }
                            }
                            break;
                        }
                        // lw hours ellecture <= hours el ta
                        else
                        {
                            if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                                {
                                    sortedTAList[i].remain_hours--;
                                }
                            }
                            if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                                {
                                    sortedTAList[i].remain_hours--;
                                }
                            }

                            int x = courseList[j].remain_hours;
                            sortedTAList[i].remain_hours = sortedTAList[i].remain_hours - courseList[j].remain_hours;
                            //  courseList[j].remain_hours = courseList[j].remain_hours - x;
                            taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
                            // insert record in linkDoctorCourse
                            if (x != 0)
                            {
                                LinkDoctorCourse link = new LinkDoctorCourse();
                                link.Course_id = courseList[j].id;
                                link.Doctor_id = sortedTAList[i].id;
                                link.hours     = x;
                                db.LinkDoctorCourses.Add(link);
                                db.SaveChanges();
                            }

                            if (sortedTAList[i].remain_hours <= 0)
                            {
                                sortedTAList.Remove(sortedTAList[i]);
                                if (i > 0 && i != sortedTAList.Count() - 1)
                                {
                                    i--;
                                }
                                else if (i == 0)
                                {
                                    i = 0;
                                }
                            }


                            courseList.Remove(courseList[j]);
                            if (j > 0 && i != courseList.Count() - 1)
                            {
                                j--;
                            }
                            else if (j == 0)
                            {
                                j = 0;
                            }
                        }
                    }
                }
            }
            // wish 3
            //for (int i = 0; i < sortedTAList.Count(); i++)
            //{

            //    for (int j = 0; j < courseList.Count(); j++)
            //    {
            //        if (courseList[j].id == sortedTAList[i].wish3)
            //        {
            //            if (courseList[j].remain_hours > sortedTAList[i].remain_hours)
            //            {
            //                if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
            //                {
            //                    while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
            //                        sortedTAList[i].remain_hours++;
            //                }
            //                else if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
            //                {
            //                    while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
            //                        sortedTAList[i].remain_hours++;
            //                }

            //                int x = sortedTAList[i].remain_hours;
            //                sortedTAList[i].remain_hours = x - sortedTAList[i].remain_hours;
            //                taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
            //                // insert record in linkDoctorCourse
            //                LinkDoctorCourse link = new LinkDoctorCourse();
            //                link.Course_id = courseList[j].id;
            //                link.Doctor_id = sortedTAList[i].id;
            //                link.hours = x;
            //                db.LinkDoctorCourses.Add(link);
            //                db.SaveChanges();
            //                // lw elta hours b2t zero aw 22l yshelo mn ellist
            //                if (sortedTAList[i].remain_hours <= 0)
            //                {
            //                    sortedTAList.Remove(sortedTAList[i]);
            //                    if (i > 0)
            //                        i--;
            //                    else
            //                        i = 0;
            //                }
            //                courseList[j].remain_hours = courseList[j].remain_hours - x;
            //                if (courseList[j].remain_hours == 0)
            //                {
            //                    courseList.Remove(courseList[j]);
            //                    if (j > 0)
            //                        j--;
            //                    else
            //                        j = 0;
            //                }

            //                break;
            //            }
            //            else
            //            {
            //                int x = courseList[j].remain_hours;
            //                sortedTAList[i].remain_hours = courseList[j].remain_hours - sortedTAList[i].remain_hours;
            //                courseList[j].remain_hours = courseList[j].remain_hours - x;
            //                // insert record in linkDoctorCourse
            //                LinkDoctorCourse link = new LinkDoctorCourse();
            //                link.Course_id = courseList[j].id;
            //                link.Doctor_id = sortedTAList[i].id;
            //                link.hours = x;
            //                db.LinkDoctorCourses.Add(link);
            //                db.SaveChanges();

            //                if (sortedTAList[i].remain_hours <= 0)
            //                {
            //                    sortedTAList.Remove(sortedTAList[i]);
            //                    if (i > 0)
            //                        i--;
            //                    else
            //                        i = 0;
            //                }
            //                courseList[j].remain_hours = courseList[j].remain_hours - x;
            //                if (courseList[j].remain_hours == 0)
            //                {
            //                    courseList.Remove(courseList[j]);
            //                    if (j > 0)
            //                        j--;
            //                    else
            //                        j = 0;
            //                }

            //            }
            //        }
            //    }

            //}
            for (int i = 0; i < sortedTAList.Count(); i++)
            {
                for (int j = 0; j < courseList.Count(); j++)
                {
                    if (courseList[j].id == sortedTAList[i].wish3)
                    {
                        // lw hours elcourse > hours el ta
                        if (courseList[j].remain_hours > sortedTAList[i].remain_hours)
                        {
                            if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                                {
                                    sortedTAList[i].remain_hours++;
                                }
                            }
                            if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                                {
                                    sortedTAList[i].remain_hours++;
                                }
                            }

                            int x = sortedTAList[i].remain_hours;

                            // sortedTAList[i].remain_hours = courseList[j].remain_hours - x;
                            courseList[j].remain_hours = courseList[j].remain_hours - x;
                            taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
                            // insert record in linkDoctorCourse
                            LinkDoctorCourse link = new LinkDoctorCourse();
                            link.Course_id = courseList[j].id;
                            link.Doctor_id = sortedTAList[i].id;
                            link.hours     = x;
                            db.LinkDoctorCourses.Add(link);
                            db.SaveChanges();
                            // lw elta hours b2t zero aw 22l yshelo mn ellist
                            sortedTAList.Remove(sortedTAList[i]);
                            if (i > 0 && i != sortedTAList.Count() - 1)
                            {
                                i--;
                            }
                            else if (i == 0)
                            {
                                i = 0;
                            }

                            if (courseList[j].remain_hours <= 0)
                            {
                                courseList.Remove(courseList[j]);
                                if (j > 0 && j != courseList.Count() - 1)
                                {
                                    j--;
                                }
                                else if (j == 0)
                                {
                                    j = 0;
                                }
                            }
                            break;
                        }
                        // lw hours ellecture <= hours el ta
                        else
                        {
                            if (courseList[j].course_hours != 0 && sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].course_hours != 0)
                                {
                                    sortedTAList[i].remain_hours--;
                                }
                            }
                            if (courseList[j].lab_hours != 0 && sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                            {
                                while (sortedTAList[i].remain_hours % courseList[j].lab_hours != 0)
                                {
                                    sortedTAList[i].remain_hours--;
                                }
                            }

                            int x = courseList[j].remain_hours;
                            sortedTAList[i].remain_hours = sortedTAList[i].remain_hours - courseList[j].remain_hours;
                            courseList[j].remain_hours   = courseList[j].remain_hours - x;
                            taForCourse.Add(new TaForCourse(sortedTAList[i].id, courseList[j].id));
                            // insert record in linkDoctorCourse
                            if (x != 0)
                            {
                                LinkDoctorCourse link = new LinkDoctorCourse();
                                link.Course_id = courseList[j].id;
                                link.Doctor_id = sortedTAList[i].id;
                                link.hours     = x;
                                db.LinkDoctorCourses.Add(link);
                                db.SaveChanges();
                            }

                            if (sortedTAList[i].remain_hours <= 0)
                            {
                                sortedTAList.Remove(sortedTAList[i]);
                                if (i > 0 && i != sortedTAList.Count() - 1)
                                {
                                    i--;
                                }
                                else if (i == 0)
                                {
                                    i = 0;
                                }
                            }


                            courseList.Remove(courseList[j]);
                            if (j > 0 && i != courseList.Count() - 1)
                            {
                                j--;
                            }
                            else if (j == 0)
                            {
                                j = 0;
                            }
                        }
                    }
                }
            }
        }
Example #20
0
        public List <Assignement> Generate_lect(ref List <GroupModel> GrpsAfterLecs)
        {
            List <GroupModel>         GrpList   = new List <GroupModel>();
            CollegeDatabaseEntities10 _db       = new CollegeDatabaseEntities10();
            List <Variables>          variables = new List <Variables>();
            //   List<CSPModel> CSP = new List<CSPModel>();
            //  List<GroupModel> GrpList = new List<GroupModel>();

            var grps = _db.Groups.ToList();

            for (int i = 0; i < grps.Count; i++)
            {
                GrpList.Add(new GroupModel(grps[i].ID, grps[i].Name, grps[i].AcadmicYear_id));
            }



            var list = (from
                        course in _db.Courses
                        where course.Doctor_Available_Time.Any()
                        select new { course, AcademicYear_id = course.AcademicYear.ID, availTime = _db.Doctor_Available_Time.Where(x => x.Course_id == course.ID).ToList() }).ToList();



            foreach (var item in list)
            {
                var grpid = (from x in _db.Groups
                             where x.AcadmicYear_id == item.AcademicYear_id
                             //where x.Department_id == null
                             // where x.Name == item.course.Department.Name
                             select x).ToList();

                // hna lw el sna 1 , 2 , 3  ha3ml course L kol group  , lw sana rab3a fa ha3ml course l kol group f nfs el dept ;
                if (grpid[0].Department_id == null)
                {
                    var rooms = (from room in _db.Rooms
                                 join rType in _db.RoomTypes on room.RoomType_id equals rType.ID
                                 where (rType.Name == "Hall")
                                 where (room.Capacity >= (item.course.AcademicYear.StudentsCount / item.course.AcademicYear.GroupCount))
                                 select room).ToList();

                    var doctors = _db.LinkDoctorCourses.Where(x => x.Course_id == item.course.ID).Select(x => x.Doctor_id).ToList();

                    foreach (var item2 in grpid)
                    {
                        variables.Add(new Variables(rooms, item2.ID, item.course, item.availTime, doctors));
                    }
                }
                else
                {
                    var depts = _db.LinkCourseDepts.Where(x => x.Course_id == item.course.ID).ToList();
                    foreach (var item2 in depts)
                    {
                        var grpsForSameDept = grpid.Where(x => x.Department_id == item2.Department_id).ToList();



                        var deptCapacity = grpsForSameDept[0].Department.Capacity;
                        var rooms        = (from room in _db.Rooms
                                            join rType in _db.RoomTypes on room.RoomType_id equals rType.ID
                                            where (rType.Name == "Hall")
                                            where (room.Capacity >= (deptCapacity / grps.Count))
                                            select room).ToList();
                        var doctors = _db.LinkDoctorCourses.Where(x => x.Course_id == item.course.ID).Select(x => x.Doctor_id).ToList();

                        foreach (var item3 in grpsForSameDept)
                        {
                            variables.Add(new Variables(rooms, item3.ID, item.course, item.availTime, doctors));
                        }
                    }
                }
            }


            List <Assignement> finalresult = new List <Assignement>();

            finalresult   = Recursive_Backtracking_Search(new List <Assignement>(), variables, ref GrpList);
            GrpsAfterLecs = GrpList;
            return(finalresult);
        }