Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private ArrayList getUnallowedTSForTeacher(Teacher teacher)
        {
            ArrayList teacherUnallowedTS = new ArrayList();

            int[]     roomRestrictions = null;
            ArrayList rr = teacher.getAllowedRoomsList();

            if (rr != null && rr.Count > 0)
            {
                roomRestrictions = new int[rr.Count];
                int rri = 0;
                foreach (Room room in rr)
                {
                    int roomIndex = _sortedRoomsRelCapacityList.IndexOf(room);
                    roomRestrictions[rri] = roomIndex;
                    rri++;
                }
            }


            ArrayList tempUnallowedTSList = new ArrayList();
            int       wtuts = 0;

            for (int k = 0; k < AppForm.CURR_OCTT_DOC.getNumberOfDays(); k++)
            {
                for (int j = 0; j < AppForm.CURR_OCTT_DOC.IncludedTerms.Count; j++)
                {
                    wtuts++;
                    if (teacher.getAllowedTimeSlots()[j, k] == false)
                    {
                        for (int qq = 0; qq < NUM_OF_ROOMS; qq++)
                        {
                            tempUnallowedTSList.Add(qq * NUM_OF_SLOTS_PER_ROOM + wtuts);
                        }
                    }
                }
            }

            //Console.WriteLine(tempUnallowedTSList.Count);

            int[] unallowedTS = new int[tempUnallowedTSList.Count];
            int   tss         = 0;

            //Console.WriteLine("New teacher");
            foreach (int tsindex in tempUnallowedTSList)
            {
                unallowedTS[tss] = tsindex;
                tss++;
            }

            foreach (int unallTS in unallowedTS)
            {
                teacherUnallowedTS.Add(unallTS);
            }

            if (roomRestrictions != null && roomRestrictions.GetLength(0) > 0)
            {
                ArrayList rrList = new ArrayList();
                foreach (int rrcc in roomRestrictions)
                {
                    rrList.Add(rrcc);
                }

                for (int rsroom = 0; rsroom < NUM_OF_ROOMS; rsroom++)
                {
                    if (!rrList.Contains(rsroom))
                    {
                        for (int rs = 0; rs < NUM_OF_SLOTS_PER_ROOM; rs++)
                        {
                            int newitem = rsroom * NUM_OF_SLOTS_PER_ROOM + rs + 1;
                            if (!teacherUnallowedTS.Contains(newitem))
                            {
                                teacherUnallowedTS.Add(newitem);
                            }
                        }
                    }
                }
            }
            //

            return(teacherUnallowedTS);
        }
Ejemplo n.º 3
0
        private static void createTableRow(XGraphics gfx, Teacher teacher)
        {
            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            XBrush          brush   = XBrushes.Black;
            XStringFormat   format  = new XStringFormat();

            format.LineAlignment = XLineAlignment.Center;

            XPen   xpen   = new XPen(XColors.Black, 0.5);
            XBrush xbrush = XBrushes.Bisque;

            XRect rect;
            XFont font;

            int currX = X_START - 30;

            string ordinalNum = ROW_COUNTER.ToString() + ".";

            rect             = new XRect(currX, CURR_Y, 28, ROW_HEIGHT);
            font             = new XFont("Arial", 10, XFontStyle.Regular, options);
            format.Alignment = XStringAlignment.Far;
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(ordinalNum, font, brush, rect, format);

            currX = X_START;

            string teacherLastName = teacher.getLastName();

            rect             = new XRect(currX, CURR_Y, COL_WIDTH[0], ROW_HEIGHT);
            font             = new XFont("Arial", 10, XFontStyle.Regular, options);
            format.Alignment = XStringAlignment.Near;
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherLastName, font, brush, rect, format);

            currX += COL_WIDTH[0] + COL_GAP;

            string teacherName = teacher.getName();

            rect = new XRect(currX, CURR_Y, COL_WIDTH[1], ROW_HEIGHT);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherName, font, brush, rect, format);

            currX += COL_WIDTH[1] + COL_GAP;

            string teacherTitle = teacher.getTitle();

            rect = new XRect(currX, CURR_Y, COL_WIDTH[2], ROW_HEIGHT);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherTitle, font, brush, rect, format);

            currX += COL_WIDTH[2] + COL_GAP;

            string teacherEduRank = teacher.getEduRank();

            rect = new XRect(currX, CURR_Y, COL_WIDTH[3], ROW_HEIGHT);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherEduRank, font, brush, rect, format);

            currX += COL_WIDTH[3] + COL_GAP;

            string teacherExtID = teacher.ExtID;

            rect = new XRect(currX, CURR_Y, COL_WIDTH[4], ROW_HEIGHT);
            //gfx.DrawRectangle(xpen, xbrush, rect);
            gfx.DrawString(teacherExtID, font, brush, rect, format);

            gfx.DrawLine(xpen, X_START - 20, CURR_Y + ROW_HEIGHT + 2, X_START + 475, CURR_Y + ROW_HEIGHT + 2);

            CURR_Y += ROW_HEIGHT + 4;
        }