예제 #1
0
        private void prepareDataForHTCourse(Course htCourse, ATeacher at, ACourse startACourse, Hashtable tempUsedEduPrograms, ArrayList allACoursesList)
        {
            if (!htCourse.TempIsPreparedForAutomatedTT)
            {
                ArrayList courseTotalPossibleTS = this.getPossibleTSForCourse(htCourse);

                EduProgram      ep  = (EduProgram)htCourse.Parent;
                EduProgramGroup epg = (EduProgramGroup)ep.Parent;
                //
                AEduProgram aep;
                int         epgIndex = AppForm.CURR_OCTT_DOC.CoursesRootNode.Nodes.IndexOf(epg);
                int         epIndex  = epg.Nodes.IndexOf(ep);
                string      myKey    = epgIndex + "," + epIndex;

                if (!tempUsedEduPrograms.Contains(myKey))
                {
                    aep = new AEduProgram();
                    tempUsedEduPrograms.Add(myKey, aep);
                }
                else
                {
                    aep = (AEduProgram)tempUsedEduPrograms[myKey];
                }

                //

                bool[]  boolPossTS = this.convertTSListToBoolArray(courseTotalPossibleTS);
                ACourse ac         = new ACourse(aep, at, htCourse.getGroupName(), /*courseTotalPossibleTS,*/ boolPossTS, htCourse.getReportName());
                ac.IsHTCourse = true;
                allACoursesList.Add(ac);
                aep.MyCourses.Add(ac);
                startACourse.ACoursesHT.Add(ac);//add HT course

                //courses mapping
                int courseIndex = ep.Nodes.IndexOf(htCourse);
                _coursesMapping.Add(epgIndex + "," + epIndex + "," + courseIndex, ac);
                //

                ALessonNode alnode;
                int         numOfNodesToSolve = 0;

                if (_fromCurrentStateRadioButton.Checked)
                {
                    numOfNodesToSolve = htCourse.getNumberOfUnallocatedLessons();

                    ArrayList myFixedTSList = htCourse.getTimeSlotsOfMyAllocatedLessons();

                    foreach (int fts in myFixedTSList)
                    {
                        //fixed nodes
                        alnode = new ALessonNode(ac, fts, NUM_OF_SLOTS_PER_ROOM * NUM_OF_ROOMS);
                        alnode.PositionInGlobalBestSolution = fts;
                        ac.MyFixedLessonNodes.Add(alnode);
                        at.MyFixedLessonNodes.Add(alnode);
                    }
                }
                else if (_fromStartRadioButton.Checked)
                {
                    numOfNodesToSolve = htCourse.getNumberOfLessonsPerWeek();
                }

                for (int nnode = 0; nnode < numOfNodesToSolve; nnode++)
                {
                    //nodes to solve
                    alnode = new ALessonNode(ac, NUM_OF_SLOTS_PER_ROOM * NUM_OF_ROOMS);
                    ac.MyAllLessonNodesForAllocation.Add(alnode);
                    at.MyTempAllocatedLessonNodes.Add(alnode);
                }

                htCourse.TempIsPreparedForAutomatedTT = true;
            }
        }
예제 #2
0
        private AGlobal prepareDataForAutomatedTT()
        {
            _coursesMapping = new Hashtable();

            int[] buildings = new int[1]; //to do
            buildings[0] = 0;             // to do

            NUM_OF_ROOMS    = AppForm.CURR_OCTT_DOC.RoomsRootNode.Nodes.Count;
            ROOM_CAPACITIES = new int[NUM_OF_ROOMS];
            int[] roomBuildings = new int[NUM_OF_ROOMS];
            ALL_POSSIBLE_TS = new ArrayList();

            NUM_OF_SLOTS_PER_ROOM = AppForm.CURR_OCTT_DOC.getNumberOfDays() * AppForm.CURR_OCTT_DOC.IncludedTerms.Count;

            //
            _sortedRoomsRelCapacityList = this.sortRoomsRelCapacity();

            int n = 0;

            foreach (Room room in _sortedRoomsRelCapacityList)
            {
                ROOM_CAPACITIES[n] = room.getRoomCapacity();
                roomBuildings[n]   = buildings[0]; //to do

                int wts = 0;
                for (int k = 0; k < AppForm.CURR_OCTT_DOC.getNumberOfDays(); k++)
                {
                    for (int j = 0; j < AppForm.CURR_OCTT_DOC.IncludedTerms.Count; j++)
                    {
                        wts++;
                        if (room.getAllowedTimeSlots()[j, k] == true)
                        {
                            ALL_POSSIBLE_TS.Add(n * NUM_OF_SLOTS_PER_ROOM + wts);
                        }
                    }
                }

                n++;
            }


            //prepare educational programs and courses

            Hashtable tempUsedTeachers    = new Hashtable();
            Hashtable tempUsedEduPrograms = new Hashtable();

            ArrayList allACoursesList = new ArrayList();

            foreach (EduProgramGroup epg in AppForm.CURR_OCTT_DOC.CoursesRootNode.Nodes)
            {
                foreach (EduProgram ep in epg.Nodes)
                {
                    foreach (Course course in ep.Nodes)
                    {
                        if (!course.TempIsPreparedForAutomatedTT)
                        {
                            ArrayList courseTotalPossibleTS = this.getPossibleTSForCourse(course);

                            Teacher teacher = (Teacher)course.getTeacher();

                            int      teacherIndex = AppForm.CURR_OCTT_DOC.TeachersRootNode.Nodes.IndexOf(teacher);
                            ATeacher at;
                            if (!tempUsedTeachers.Contains(teacherIndex))
                            {
                                at = new ATeacher();
                                tempUsedTeachers.Add(teacherIndex, at);

                                //1
                                object[] args1 = new object[2];
                                args1[1] = Settings.SC_TEACHER_MAX_HOURS_DAILY_WEIGHT;

                                if (teacher.SCMaxHoursDaily != -1)
                                {
                                    args1[0] = teacher.SCMaxHoursDaily;
                                }
                                else
                                {
                                    args1[0] = SCBaseSettings.TEACHER_MAX_HOURS_DAILY;
                                }

                                SCTeacherMaxHoursDaily sctmhd = new SCTeacherMaxHoursDaily(at, args1, null);
                                at.MySoftConstraints.Add(sctmhd);

                                //2
                                object[] args2 = new object[2];
                                args2[1] = Settings.SC_TEACHER_MAX_HOURS_CONTINUOUSLY_WEIGHT;

                                if (teacher.SCMaxHoursContinously != -1)
                                {
                                    args2[0] = teacher.SCMaxHoursContinously;
                                }
                                else
                                {
                                    args2[0] = SCBaseSettings.TEACHER_MAX_HOURS_CONTINUOUSLY;
                                }

                                SCTeacherMaxHoursContinuously sctmhc = new SCTeacherMaxHoursContinuously(at, args2, null);
                                at.MySoftConstraints.Add(sctmhc);

                                //3
                                object[] args3 = new object[2];
                                args3[1] = Settings.SC_TEACHER_MAX_DAYS_PER_WEEK_WEIGHT;

                                if (teacher.SCMaxDaysPerWeek != -1)
                                {
                                    args3[0] = teacher.SCMaxDaysPerWeek;
                                }
                                else
                                {
                                    args3[0] = SCBaseSettings.TEACHER_MAX_DAYS_PER_WEEK;
                                }

                                SCTeacherMaxDaysPerWeek sctmdpw = new SCTeacherMaxDaysPerWeek(at, args3, null);
                                at.MySoftConstraints.Add(sctmdpw);
                            }
                            else
                            {
                                at = (ATeacher)tempUsedTeachers[teacherIndex];
                            }

                            //
                            AEduProgram aep;
                            int         epgIndex = AppForm.CURR_OCTT_DOC.CoursesRootNode.Nodes.IndexOf(epg);
                            int         epIndex  = epg.Nodes.IndexOf(ep);
                            string      myKey    = epgIndex + "," + epIndex;

                            if (!tempUsedEduPrograms.Contains(myKey))
                            {
                                aep = new AEduProgram();
                                tempUsedEduPrograms.Add(myKey, aep);
                            }
                            else
                            {
                                aep = (AEduProgram)tempUsedEduPrograms[myKey];
                            }

                            //
                            bool[]  boolPossTS = this.convertTSListToBoolArray(courseTotalPossibleTS);
                            ACourse ac         = new ACourse(aep, at, course.getGroupName(), boolPossTS, course.getReportName());
                            allACoursesList.Add(ac);
                            aep.MyCourses.Add(ac);
                            if (course.getGroupName() != null && course.getGroupName() != "")
                            {
                                if (!aep.MyIncludedGroups.Contains(course.getGroupName()))
                                {
                                    aep.MyIncludedGroups.Add(course.getGroupName());
                                }
                            }

                            //sc for course
                            if (course.getNumberOfLessonsPerWeek() > 1)
                            {
                                int    numOfLessPerWeek = course.getNumberOfLessonsPerWeek();
                                string clKey;
                                if (numOfLessPerWeek <= 9)
                                {
                                    clKey = numOfLessPerWeek.ToString();
                                }
                                else
                                {
                                    clKey = "default";
                                }

                                int[] lessonBlocksParam;

                                if (course.SCLessonBlocksParameters != null)
                                {
                                    lessonBlocksParam = course.SCLessonBlocksParameters;
                                }
                                else
                                {
                                    lessonBlocksParam = (int[])SCBaseSettings.COURSE_LESSON_BLOCKS[clKey];
                                }

                                object[] args = new object[2];

                                args[0] = lessonBlocksParam;
                                args[1] = Settings.SC_COURSE_LESSON_BLOCKS_WEIGHT;

                                SCCourseLessonBlocks scclb = new SCCourseLessonBlocks(ac, args, null);
                                ac.MySoftConstraints.Add(scclb);
                            }



                            //


                            //courses mapping
                            int courseIndex = ep.Nodes.IndexOf(course);
                            _coursesMapping.Add(epgIndex + "," + epIndex + "," + courseIndex, ac);
                            //

                            ALessonNode alnode;
                            int         numOfNodesToSolve = 0;

                            if (_fromCurrentStateRadioButton.Checked)
                            {
                                numOfNodesToSolve = course.getNumberOfUnallocatedLessons();

                                ArrayList myFixedTSList = course.getTimeSlotsOfMyAllocatedLessons();

                                foreach (int fts in myFixedTSList)
                                {
                                    //fixed nodes
                                    alnode = new ALessonNode(ac, fts, NUM_OF_SLOTS_PER_ROOM * NUM_OF_ROOMS);
                                    alnode.PositionInGlobalBestSolution = fts;
                                    ac.MyFixedLessonNodes.Add(alnode);
                                    at.MyFixedLessonNodes.Add(alnode);
                                }
                            }
                            else if (_fromStartRadioButton.Checked)
                            {
                                numOfNodesToSolve = course.getNumberOfLessonsPerWeek();
                            }


                            for (int nnode = 0; nnode < numOfNodesToSolve; nnode++)
                            {
                                //nodes to solve
                                alnode = new ALessonNode(ac, NUM_OF_SLOTS_PER_ROOM * NUM_OF_ROOMS);
                                ac.MyAllLessonNodesForAllocation.Add(alnode);
                                at.MyTempAllocatedLessonNodes.Add(alnode);
                            }

                            if (course.getCoursesToHoldTogetherList().Count > 0)
                            {
                                foreach (Course htCourse in course.getCoursesToHoldTogetherList())
                                {
                                    prepareDataForHTCourse(htCourse, at, ac, tempUsedEduPrograms, allACoursesList);
                                }
                            }

                            course.TempIsPreparedForAutomatedTT = true;
                        }
                    } //end of course loop
                }
            }         //end epg loop


            //reset values for course.TempIsPreparedForAutomatedTT to false
            foreach (EduProgramGroup epg in AppForm.CURR_OCTT_DOC.CoursesRootNode.Nodes)
            {
                foreach (EduProgram ep in epg.Nodes)
                {
                    foreach (Course course in ep.Nodes)
                    {
                        course.TempIsPreparedForAutomatedTT = false;
                    }
                }
            }

            ArrayList allATeachersList = new ArrayList();

            foreach (ATeacher ateacher in tempUsedTeachers.Values)
            {
                allATeachersList.Add(ateacher);
            }

            ArrayList allAEduProgramsList = new ArrayList();

            foreach (AEduProgram aEduProg in tempUsedEduPrograms.Values)
            {
                allAEduProgramsList.Add(aEduProg);
            }

            //sc for ep
            foreach (string thisKey in tempUsedEduPrograms.Keys)
            {
                AEduProgram aep = (AEduProgram)tempUsedEduPrograms[thisKey];

                char[] separator = new char[1];
                separator[0] = ',';

                string[] parts    = thisKey.Split(separator, 2);
                int      epgIndex = Int32.Parse(parts[0]);
                int      epIndex  = Int32.Parse(parts[1]);

                EduProgramGroup epg = (EduProgramGroup)AppForm.CURR_OCTT_DOC.CoursesRootNode.Nodes[epgIndex];
                EduProgram      ep  = (EduProgram)epg.Nodes[epIndex];

                //
                if (aep.MyIncludedGroups.Count > 0)
                {
                    foreach (string groupName in aep.MyIncludedGroups)
                    {
                        //1
                        object[] args1 = new object[3];
                        args1[2] = Settings.SC_STUDENT_MAX_HOURS_DAILY_WEIGHT;
                        args1[1] = groupName;

                        if (ep.SCStudentMaxHoursDaily != -1)
                        {
                            args1[0] = ep.SCStudentMaxHoursDaily;
                        }
                        else
                        {
                            args1[0] = SCBaseSettings.EP_STUDENT_MAX_HOURS_DAILY;
                        }

                        SCStudentMaxHoursDaily scsmhd = new SCStudentMaxHoursDaily(aep, args1, null);
                        aep.MySoftConstraints.Add(scsmhd);

                        //2
                        object[] args2 = new object[3];
                        args2[2] = Settings.SC_STUDENT_NO_GAPS_WEIGHT;
                        args2[1] = groupName;

                        if (ep.SCStudentNoGapsGapIndicator != -1)
                        {
                            args2[0] = ep.SCStudentNoGapsGapIndicator;
                        }
                        else
                        {
                            args2[0] = SCBaseSettings.EP_STUDENT_NO_GAPS_GAP_INDICATOR;
                        }

                        SCStudentNoGaps scsng = new SCStudentNoGaps(aep, args2, null);
                        aep.MySoftConstraints.Add(scsng);

                        //3
                        object[] args3 = new object[3];
                        args3[2] = Settings.SC_STUDENT_MAX_HOURS_CONTINUOUSLY_WEIGHT;
                        args3[1] = groupName;

                        if (ep.SCStudentMaxHoursContinuously != -1)
                        {
                            args3[0] = ep.SCStudentMaxHoursContinuously;
                        }
                        else
                        {
                            args3[0] = SCBaseSettings.EP_STUDENT_MAX_HOURS_CONTINUOUSLY;
                        }

                        SCStudentMaxHoursContinuously scsmhc = new SCStudentMaxHoursContinuously(aep, args3, null);
                        aep.MySoftConstraints.Add(scsmhc);

                        //4
                        object[] args4 = new object[3];
                        args4[2] = Settings.SC_TEACHER_MAX_DAYS_PER_WEEK_WEIGHT;
                        args4[1] = groupName;

                        if (ep.SCStudentMaxDaysPerWeek != -1)
                        {
                            args4[0] = ep.SCStudentMaxDaysPerWeek;
                        }
                        else
                        {
                            args4[0] = SCBaseSettings.EP_STUDENT_MAX_DAYS_PER_WEEK;
                        }

                        SCStudentMaxDaysPerWeek scsmdpw = new SCStudentMaxDaysPerWeek(aep, args4, null);
                        aep.MySoftConstraints.Add(scsmdpw);

                        //5
                        object[] args5 = new object[3];
                        args5[2] = Settings.SC_STUDENT_PREFERRED_START_TIME_PERIOD_WEIGHT;
                        args5[1] = groupName;

                        if (ep.SCStudentPreferredStartTimePeriod != -1)
                        {
                            args5[0] = ep.SCStudentPreferredStartTimePeriod;
                        }
                        else
                        {
                            args5[0] = SCBaseSettings.EP_STUDENT_PREFERRED_START_TIME_PERIOD;
                        }

                        SCStudentPreferredStartTimePeriod scspstp = new SCStudentPreferredStartTimePeriod(aep, args5, null);
                        aep.MySoftConstraints.Add(scspstp);
                    }
                }
                else
                {
                    //1
                    object[] args1 = new object[3];
                    args1[2] = Settings.SC_STUDENT_MAX_HOURS_DAILY_WEIGHT;
                    args1[1] = null;

                    if (ep.SCStudentMaxHoursDaily != -1)
                    {
                        args1[0] = ep.SCStudentMaxHoursDaily;
                    }
                    else
                    {
                        args1[0] = SCBaseSettings.EP_STUDENT_MAX_HOURS_DAILY;
                    }

                    SCStudentMaxHoursDaily scsmhd = new SCStudentMaxHoursDaily(aep, args1, null);
                    aep.MySoftConstraints.Add(scsmhd);

                    //2
                    object[] args2 = new object[3];
                    args2[2] = Settings.SC_STUDENT_NO_GAPS_WEIGHT;
                    args2[1] = null;

                    if (ep.SCStudentNoGapsGapIndicator != -1)
                    {
                        args2[0] = ep.SCStudentNoGapsGapIndicator;
                    }
                    else
                    {
                        args2[0] = SCBaseSettings.EP_STUDENT_NO_GAPS_GAP_INDICATOR;
                    }

                    SCStudentNoGaps scsng = new SCStudentNoGaps(aep, args2, null);
                    aep.MySoftConstraints.Add(scsng);

                    //3
                    object[] args3 = new object[3];
                    args3[2] = Settings.SC_STUDENT_MAX_HOURS_CONTINUOUSLY_WEIGHT;
                    args3[1] = null;

                    if (ep.SCStudentMaxHoursContinuously != -1)
                    {
                        args3[0] = ep.SCStudentMaxHoursContinuously;
                    }
                    else
                    {
                        args3[0] = SCBaseSettings.EP_STUDENT_MAX_HOURS_CONTINUOUSLY;
                    }

                    SCStudentMaxHoursContinuously scsmhc = new SCStudentMaxHoursContinuously(aep, args3, null);
                    aep.MySoftConstraints.Add(scsmhc);

                    //4
                    object[] args4 = new object[3];
                    args4[2] = Settings.SC_TEACHER_MAX_DAYS_PER_WEEK_WEIGHT;
                    args4[1] = null;

                    if (ep.SCStudentMaxDaysPerWeek != -1)
                    {
                        args4[0] = ep.SCStudentMaxDaysPerWeek;
                    }
                    else
                    {
                        args4[0] = SCBaseSettings.EP_STUDENT_MAX_DAYS_PER_WEEK;
                    }

                    SCStudentMaxDaysPerWeek scsmdpw = new SCStudentMaxDaysPerWeek(aep, args4, null);
                    aep.MySoftConstraints.Add(scsmdpw);

                    //5
                    object[] args5 = new object[3];
                    args5[2] = Settings.SC_STUDENT_PREFERRED_START_TIME_PERIOD_WEIGHT;
                    args5[1] = null;

                    if (ep.SCStudentPreferredStartTimePeriod != -1)
                    {
                        args5[0] = ep.SCStudentPreferredStartTimePeriod;
                    }
                    else
                    {
                        args5[0] = SCBaseSettings.EP_STUDENT_PREFERRED_START_TIME_PERIOD;
                    }

                    SCStudentPreferredStartTimePeriod scspstp = new SCStudentPreferredStartTimePeriod(aep, args5, null);
                    aep.MySoftConstraints.Add(scspstp);
                }
            }



            Control.CheckForIllegalCrossThreadCalls = false;
            //Console.WriteLine(allATeachersList.Count);
            //Console.WriteLine(allAEduProgramsList.Count);

            AGlobal ag = new AGlobal(AppForm.CURR_OCTT_DOC.getNumberOfDays(), AppForm.CURR_OCTT_DOC.IncludedTerms.Count, NUM_OF_ROOMS, ROOM_CAPACITIES, roomBuildings, buildings, allACoursesList, allATeachersList, allAEduProgramsList);

            return(ag);
        }