Пример #1
0
        //------------------------------------------------------------------------------
        // does the actual action of putting a course on a machine; this will be the hub
        // for implementing preferences, not all are implemented at the moment; also,
        // right now unscheduled courses are simply going into a list but if you were to
        // do something else, this function is where it would originate
        //------------------------------------------------------------------------------
        private void PutCourseOnMachine(Job j, List <CourseNode> groups)
        {
            //get most recent prereq
            int mostRecentPrereqYear    = 0;
            int mostRecentPrereqQuarter = 1;
            int start = 0;

            //if no prereqs then schedule at any time
            if (PrereqsExist(groups))   //this is if there are prereqs
            {
                int[] yq = GetMostRecentPrereq(groups);
                mostRecentPrereqYear    = yq[0];
                mostRecentPrereqQuarter = yq[1];
                if (mostRecentPrereqQuarter == -1 || mostRecentPrereqYear == -1)   //has prerequisites but they weren't able to be scheduled
                {
                    unableToSchedule.Add(j);
                    return;
                }

                //schedule 1 or more quarters after, mind the year
                //schedule on nearest available machine
                //start i at whatever quarter you calculate, not simply zero

                start = (mostRecentPrereqYear * 4 + mostRecentPrereqQuarter - 1) + 1;
            }
            for (int i = start; i < machineNodes.Count; i++)
            {
                MachineNode mn = machineNodes[i];
                //if machine node exeeds preferences continue to next node
                if (mn.GetClassesScheduled() > 3)
                {
                    continue;
                }
                List <Machine> machines = mn.GetMachines();
                for (int k = 0; k < machines.Count; k++)
                {
                    Machine m = machines[k];
                    if (m.CanDoJob(j) && !m.CheckInUse()) //if not in use and it can do the job
                    {
                        if (Overlap(j, m, mn))            //can't schedule it if the times overlap even if machine found
                        {
                            continue;
                        }
                        m.SetCurrentJobProcessing(j);
                        m.SetInUse(true);
                        j.SetScheduled(true);
                        j.SetQuarterScheduled(m.GetQuarter());
                        j.SetYearScheduled(m.GetYear());
                        mn.AddClassesScheduled(1);
                        finalPlan.Add(m);
                        return;
                    }
                }
            }
        }
        //------------------------------------------------------------------------------
        // Puts a course into the schedule by first checking the course's most
        // immediate prerequisite that has been scheduled and starting from the next
        // nearest schedulable machineNode. From the starting point the course is then
        // scheduled according to preferences.
        //
        // SPECIAL NOTE: As Polina writes below, this is indeed a perfect function to
        //               implement several preferences invloved with courses and scheduling.
        //               Namely, Courses per quarter, day preferences, and timeOfDay preferences.
        //               I took the liberty of labeling the best spots to place these.
        //               Additionally, should Machines ever have a CoreCourse, or other attributes
        //               (Diversity, Humanities, etc.) checks could be placed in this function
        //               to schedule those courses.
        //
        // does the actual action of putting a course on a machine; this will be the hub
        // for implementing preferences, not all are implemented at the moment; also,
        // right now unscheduled courses are simply going into a list but if you were to
        // do something else, this function is where it would originate
        //------------------------------------------------------------------------------
        private void PutCourseOnMachine(Job j, List <CourseNode> groups)
        {
            #region variables
            //get most recent prereq
            int mostRecentPrereqYear    = 0;
            int mostRecentPrereqQuarter = 1;
            int start = 0;
            #endregion

            #region Prerequisite Handler
            //if no prereqs then schedule at any time
            if (PrereqsExist(groups)) //CHECKS FOR NULL
            {                         //this is if there are prereqs
                int[] yq = GetMostRecentPrereq(groups);

                mostRecentPrereqYear    = yq[0];
                mostRecentPrereqQuarter = yq[1];

                //ERROR CHECK
                if (mostRecentPrereqQuarter == -1 || mostRecentPrereqYear == -1)
                { //has prerequisites but they weren't able to be scheduled
                    unableToSchedule.Add(j);
                    return;
                }

                //schedule 1 or more quarters after, mind the year <--(?)
                //schedule on nearest available machine
                //start i at whatever quarter you calculate, not simply zero
                start = (mostRecentPrereqYear * 4 + mostRecentPrereqQuarter - 1) + 1;
            }
            #endregion


            for (int i = start; i < machineNodes.Count; i++)
            {
                MachineNode mn = machineNodes[i];
                // Check the number of credits scheduled per quarter make sure it does not exceed preference.
                // Check the number of core credits scheduled per quarter make sure it does not exceed preference.
                // TODO:    Add a default case. What if they dont have a preference should we assign all their classes in one quarter?
                //          Probably not...
                //System.Diagnostics.Debug.WriteLine("NUM OF CREDITS FOR JOB: " + j.GetNumCredits() + " CORE COURSE: " + j.GetCoreCourse());
                if (mn.GetCreditsScheduled() + j.GetNumCredits() > preferences.getCreditsPerQuarter() ||
                    (j.GetCoreCourse() && j.GetNumCredits() + mn.GetMajorCreditsScheduled() > preferences.getCoreCredits()))
                {
                    continue;
                }
                List <Machine> machines = mn.GetMachines();

                for (int k = 0; k < machines.Count; k++)
                {
                    //<<----------------------------INSERT DAY/TIME PREFERENCE AND CHECK AGAINST IT
                    Machine m = machines[k];
                    if (m.CanDoJob(j) && !m.CheckInUse())
                    {     //if not in use and it can do the job
                        if (Overlap(j, m, mn))
                        { //can't schedule it if the times overlap even if machine found
                            continue;
                        }
                        m.SetCurrentJobProcessing(j);
                        m.SetInUse(true);
                        j.SetScheduled(true);
                        j.SetQuarterScheduled(m.GetQuarter());
                        j.SetYearScheduled(m.GetYear());
                        // Need to update the machine node such that it reflects the new amount of credits, core credits, etc.
                        //mn.AddClassesScheduled(1);
                        mn.AddClassesScheduled(j);
                        finalPlan.Add(m);
                        return;
                    }
                }
            }
        }