예제 #1
0
        //------------------------------------------------------------------------------
        // similar to depth first search algorithm. Does the action of searching through
        // network and scheduling prerequisites before scheduling the class
        //
        //------------------------------------------------------------------------------
        private void ScheduleCourse(Job job)
        {
            if (IsScheduled(job))
            {
                return;
            }
            int num = job.GetID();
            List <CourseNode> groups = network.FindShortPath(num);        //find prerequisite group

            if (PrereqsExist(groups) && !job.GetPrerequisitesScheduled()) //if j does not have prerequisites (OR its prerequisites have been scheduled) schedule j
            //schedule j's prerequisites by geting shortest group and whatnot
            {
                int shortest                        = GetShortestGroup(groups);//so now we have the shortest list
                List <CourseNode> group             = groups[shortest].prereqs;
                List <Job>        jobsToBeScheduled = new List <Job>();
                for (int j = 0; j < group.Count; j++)
                {
                    Job myJob = new Job(group[j].prerequisiteID);
                    jobsToBeScheduled.Add(myJob);
                }//now we have a list full of jobs to be scheduled

                for (int k = 0; k < jobsToBeScheduled.Count; k++)   //schedule them all here
                {
                    ScheduleCourse(jobsToBeScheduled[k]);
                }//now they are scheduled
                job.SetPrerequisitesScheduled(true);
            }
            PutCourseOnMachine(job, groups);
            if (!job.GetScheduled())   //figure out what to do if it wasn't able to be scheduled, make this a function later
            {
                unableToSchedule.Add(job);
            }
        }
        //------------------------------------------------------------------------------
        // Uses recursive calls to schedule prerequisites of the passed job before
        // scheduling the job itself.
        //
        // If for some reason a course cannot be scheduled (due to scheduling conflicts)
        // then that course is added a supplmentary list of unscheduled coursees.
        //------------------------------------------------------------------------------
        private void ScheduleCourse(Job job, bool preferShortest)
        {
            #region ENDCASE
            if (IsScheduled(job)) //CHECK IF CLASS IS SCHEDULED
            {
                return;           //IF SCHEDULED; FINISH
            }
            #endregion

            #region RECURSIVE SCHEDULING CALL
            int num = job.GetID();                                 //ID OF COURSE BEING SCHEDULED
            List <CourseNode> groups = network.FindShortPath(num); //FINDS PREREQUISITE COURSES FOR THE GIVEN COURSE
            if (PrereqsExist(groups) && !job.GetPrerequisitesScheduled())
            {                                                      //if j does not have prerequisites (OR its prerequisites have been scheduled) schedule j
                //schedule j's prerequisites by getting shortest group and whatnot
                int selectedGroup;
                if (preferShortest)
                {
                    selectedGroup = GetShortestGroup(groups); //FIND GROUP WITH LEAST PREREQUISITES
                }
                else
                {
                    selectedGroup = GetAnyGroup(groups); //Find any group is OK
                }

                List <CourseNode> group = groups[selectedGroup].prereqs; //GET LIST OF PREREQUISITES

                List <Job> jobsToBeScheduled = new List <Job>();
                for (int j = 0; j < group.Count; j++)  //TRANSFER PREREQUSITE LIST INTO MORE JOBS
                {
                    // TODO: Store the credits in the JOB from the course network
                    Job myJob = new Job(group[j].PrerequisiteCourseID, group[j].credits, false);
                    jobsToBeScheduled.Add(myJob);
                }//now we have a list full of jobs to be scheduled

                for (int k = 0; k < jobsToBeScheduled.Count; k++) //SCHEDULE THE PREREQUISITES
                { //schedule them all here
                    ScheduleCourse(jobsToBeScheduled[k], preferShortest);
                }//now they are scheduled
                job.SetPrerequisitesScheduled(true);
            }
            #endregion

            #region SCHEDULE COURSE
            PutCourseOnMachine(job, groups); //SCHEDULE COURSE
            #endregion

            #region Error Messages
            if (!job.GetScheduled())
            { //figure out what to do if it wasn't able to be scheduled, make this a function later
                unableToSchedule.Add(job);
            }
            #endregion
        }