//------------------------------------------------------------------------------ // // checks if the day time is contained in the machine, used to check for Overlaps // //------------------------------------------------------------------------------ private bool ContainsDayTime(List <DayTime> times, DayTime dt) { for (int i = 0; i < times.Count; i++) { DayTime time = times[i]; if (time == dt) { return(true); } } return(false); }
//------------------------------------------------------------------------------ // // prints just one job // //------------------------------------------------------------------------------ public void PrintBusyMachine() { Console.WriteLine("-----------------------------------"); Console.WriteLine("Year: " + year); Console.WriteLine("Quarter: " + quarter); Console.WriteLine("CourseID:"); Console.WriteLine(currentJobProcessing.GetID()); Console.WriteLine("DayTimes:"); for (int i = 0; i < dateTime.Count; i++) { DayTime dt = dateTime[i]; Console.WriteLine("Day: " + dt.GetDay()); Console.WriteLine("Start time: " + dt.GetStartTime()); Console.WriteLine("End time: " + dt.GetEndTime()); } Console.WriteLine("-----------------------------------"); }
//------------------------------------------------------------------------------ // // prints all the jobs // //------------------------------------------------------------------------------ public void Print() { Console.WriteLine("-----------------------------------"); Console.WriteLine("Year: " + year); Console.WriteLine("Quarter: " + quarter); Console.WriteLine("Jobs:"); for (int i = 0; i < jobs.Count; i++) { Job j = jobs[i]; Console.WriteLine(j.GetID()); } Console.WriteLine("DayTimes:"); for (int i = 0; i < dateTime.Count; i++) { DayTime dt = dateTime[i]; Console.WriteLine("Day: " + dt.GetDay()); Console.WriteLine("Start time: " + dt.GetStartTime()); Console.WriteLine("End time: " + dt.GetEndTime()); } Console.WriteLine("-----------------------------------"); }
//------------------------------------------------------------------------------ // create a query that will pull all the different machines // which means getting every single time slot // distinct year, quarter, time, and set of DayTimes //ANDRUE NOTE: This allocates a machine to every individual course in CourseTime and adds it to a list of Machines. //------------------------------------------------------------------------------ private void InitMachines() { string query = "select CourseID, StartTimeID, EndTimeID, DayID, QuarterID, SectionID from CourseTime order by CourseID ASC;"; DataTable dt = DBPlugin.ExecuteToDT(query); int dt_size = dt.Rows.Count - 1; DataRow dr = dt.Rows[dt_size]; //Temporary Machine Variables Machine dummyMachine = new Machine(); DayTime dummyDayTime = new DayTime(); int course = 0; int start = 0; int end = 0; int day = 0; int quarter = 0; int section = 0; int currentCourse = (int)dr.ItemArray[0]; //USED FOR PEAKING THE NEXT ROW int currentQuarter = (int)dr.ItemArray[4]; //USED FOR PEAKING THE NEXT ROW int currentSection = (int)dr.ItemArray[5]; //USED FOR PEAKING THE NEXT ROW //Treats the information gained from the query like a FILO object while (dt_size >= 0) { dr = dt.Rows[dt_size]; //check for null values if (dr.ItemArray[0] == DBNull.Value || dr.ItemArray[1] == DBNull.Value || dr.ItemArray[2] == DBNull.Value || dr.ItemArray[3] == DBNull.Value || dr.ItemArray[4] == DBNull.Value || dr.ItemArray[5] == DBNull.Value) { dt_size--; //IF any portion is null, then the row is discarded entirely. continue; } //going to have to do the same with year probably; Andrue Note: Most likely the case course = (int)dr.ItemArray[0]; start = (int)dr.ItemArray[1]; end = (int)dr.ItemArray[2]; day = (int)dr.ItemArray[3]; quarter = (int)dr.ItemArray[4]; section = (int)dr.ItemArray[5]; //same course but different section OR different quarter is a different machine //different course is a different machine if ((currentCourse == course && (currentSection != section || currentQuarter != quarter)) || (currentCourse != course)) { dummyMachine = new Machine(); //creates a new machine to be used currentCourse = (int)dr.ItemArray[0]; currentQuarter = (int)dr.ItemArray[4]; currentSection = (int)dr.ItemArray[5]; } dummyDayTime = new DayTime(); dummyDayTime.SetDayTime(day, start, end); dummyMachine.AddDayTime(dummyDayTime); dummyMachine.SetQuarter(quarter); //we add a new machine when we peek to the next row and see //(different course) OR (same course and (different section OR dif qtr)) //Andrue Note: Maybe isolate these arguments into helper functions for ease-of-use? //if (itself(?)) OR (not same course) OR (IS course but NOT SAME Section OR Quarter) int next = dt_size - 1; if (dt_size == 0 || ((int)dt.Rows[next].ItemArray[0] != currentCourse || ((int)dt.Rows[next].ItemArray[0] == currentCourse && ((int)dt.Rows[next].ItemArray[5] != currentSection) || (int)dt.Rows[next].ItemArray[4] != currentQuarter))) { addMachine(dummyMachine, course); } dt_size--; } //END WHILE LOOP /* * //print machines for testing; unnecessary * for (int i = 0; i < machineNodes.Count; i++) { * MachineNode mn = machineNodes[i]; * List<Machine> machines = mn.GetMachines(); * Console.WriteLine("Quarter: " + mn.GetQuarter()); * for (int j = 0; j < machines.Count; j++) { * Machine m = machines[j]; * m.Print(); * } * } */ }
//------------------------------------------------------------------------------ // create a query that will pull all the different machines // which means getting every single time slot // distinct year, quarter, time, and set of DayTimes //------------------------------------------------------------------------------ private void InitMachines() { string query = "select CourseID, StartTimeID, EndTimeID, DayID, QuarterID, SectionID from CourseTime order by CourseID ASC;"; DataTable dt = ExecuteQuery(query); Machine dummyMachine = new Machine(); DayTime dummyDayTime = new DayTime(); int dt_size = dt.Rows.Count - 1; DataRow dr = dt.Rows[dt_size]; int currentCourse = (int)dr.ItemArray[0]; int currentQuarter = (int)dr.ItemArray[4]; int currentSection = (int)dr.ItemArray[5]; int course = 0; int start = 0; int end = 0; int day = 0; int quarter = 0; int section = 0; while (dt_size >= 0) { dr = dt.Rows[dt_size]; //check for null values if (dr.ItemArray[0] == DBNull.Value || dr.ItemArray[1] == DBNull.Value || dr.ItemArray[2] == DBNull.Value || dr.ItemArray[3] == DBNull.Value || dr.ItemArray[4] == DBNull.Value || dr.ItemArray[5] == DBNull.Value) { dt_size--; continue; } course = (int)dr.ItemArray[0]; section = (int)dr.ItemArray[5]; quarter = (int)dr.ItemArray[4]; //going to have to do the same with year probably //same course but different section is a different machine //different course is a different machine if ((currentCourse == course && (currentSection != section || currentQuarter != quarter)) || (currentCourse != course)) { dummyMachine = new Machine(); currentCourse = (int)dr.ItemArray[0]; currentSection = (int)dr.ItemArray[5]; currentQuarter = (int)dr.ItemArray[4]; } start = (int)dr.ItemArray[1]; end = (int)dr.ItemArray[2]; day = (int)dr.ItemArray[3]; dummyDayTime = new DayTime(); dummyDayTime.SetDayTime(day, start, end); dummyMachine.AddDayTime(dummyDayTime); dummyMachine.SetQuarter(quarter); //we add a new machine when we peek to the next row and see //(different course) OR (same course and (different section OR dif qtr)) if (dt_size == 0 || ((int)dt.Rows[dt_size - 1].ItemArray[0] != currentCourse || ((int)dt.Rows[dt_size - 1].ItemArray[0] == currentCourse && ((int)dt.Rows[dt_size - 1].ItemArray[5] != currentSection) || (int)dt.Rows[dt_size - 1].ItemArray[4] != currentQuarter))) { dummyMachine.AddJob(new Job(course)); for (int i = 0; i < machineNodes.Count; i++) { MachineNode mn = machineNodes[i]; List <Machine> machines = mn.GetMachines(); if (machines.Count > 0) { for (int j = 0; j < machines.Count; j++) { Machine m = machines[j]; if (m == dummyMachine) //found the machine, just add job { m.AddJob(new Job(course)); } else if (dummyMachine.GetYear().Equals(mn.GetYear()) && dummyMachine.GetQuarter().Equals(mn.GetQuarter())) //machine does not exist, add it in { machines.Add(dummyMachine); break; } } } else if (dummyMachine.GetYear().Equals(mn.GetYear()) && dummyMachine.GetQuarter().Equals(mn.GetQuarter())) { machines.Add(dummyMachine); break; } else { Console.WriteLine("Dummy Machine Year: " + dummyMachine.GetYear()); Console.WriteLine("Dummy Machine Quarter: " + dummyMachine.GetQuarter()); Console.WriteLine("mn Year: " + mn.GetYear()); Console.WriteLine("mn Quarter: " + mn.GetQuarter()); Console.WriteLine('\n'); } } } dt_size--; } //print machines for testing; unnecessary for (int i = 0; i < machineNodes.Count; i++) { MachineNode mn = machineNodes[i]; List <Machine> machines = mn.GetMachines(); Console.WriteLine("Quarter: " + mn.GetQuarter()); for (int j = 0; j < machines.Count; j++) { Machine m = machines[j]; m.Print(); } } }
//------------------------------------------------------------------------------ // WARNING!! --Please Read SPECIAL NOTE below-- // Runs a query which pulls all the courses that exist in CourseTime. Conceptually, // this creates a list of every class that has been offered. Details like the // Course ID, the time the class starts, the time the class ends, days offered, // quarter offered, and the section ID or collected to their respective // counterparts. This provides a means to reduce the amount of objects being handled // and can allow implmentation of day-specific and time-specific preferences. // // Various checks prevent duplication of machines. // // SPECIAL NOTE: If we have the means to, and are required to do so, of // implementing different course offerings on a yearly basis // this is where we would need to change it. DOING SO WOULD MEAN // THAT THE FUNCTION, NORMALIZEMACHINES(), WOULD BE INCOMPATIBLE // WITH THIS ALGORITHM. //------------------------------------------------------------------------------ private void InitMachines() { // This query returns ~2000 rows of course info. We pre-process a lot of info // with adding jobs and decidingg where to place maachinens/jobs. // If we know the school ID. Then we have what looks like an average of 300 classes less. //string oldquery = "select CourseID, StartTimeID, EndTimeID, DayID, QuarterID, SectionID from CourseTime order by CourseID ASC;"; string query = "SELECT ct.CourseID, StartTimeID, EndTimeID, DayID, QuarterID, ct.SectionID, c.MaxCredit " + "FROM CourseTime as ct " + "LEFT JOIN Course as c ON c.CourseID = ct.CourseID " + "ORDER BY ct.CourseID ASC"; DataTable dt = DBPlugin.ExecuteToDT(query); int dt_size = dt.Rows.Count - 1; DataRow dr = dt.Rows[dt_size]; //Temporary Machine Variables Machine dummyMachine = new Machine(); DayTime dummyDayTime = new DayTime(); int course = 0; int start = 0; int end = 0; int day = 0; int quarter = 0; int section = 0; int credits = 0; int currentCourse = (int)dr.ItemArray[0]; //USED FOR PEAKING THE NEXT ROW int currentQuarter = (int)dr.ItemArray[4]; //USED FOR PEAKING THE NEXT ROW int currentSection = (int)dr.ItemArray[5]; //USED FOR PEAKING THE NEXT ROW //Treats the information gained from the query like a FILO object while (dt_size >= 0) { dr = dt.Rows[dt_size]; //check for null values if (dr.ItemArray[0] == DBNull.Value || dr.ItemArray[1] == DBNull.Value || dr.ItemArray[2] == DBNull.Value || dr.ItemArray[3] == DBNull.Value || dr.ItemArray[4] == DBNull.Value || dr.ItemArray[5] == DBNull.Value) { dt_size--; //IF any portion is null, then the row is discarded entirely. continue; } //going to have to do the same with year probably; Andrue Note: Most likely the case course = (int)dr.ItemArray[0]; start = (int)dr.ItemArray[1]; end = (int)dr.ItemArray[2]; day = (int)dr.ItemArray[3]; quarter = (int)dr.ItemArray[4]; section = (int)dr.ItemArray[5]; credits = (int)dr.ItemArray[6]; //same course but different section OR different quarter is a different machine //different course is a different machine if ((currentCourse == course && (currentSection != section || currentQuarter != quarter)) || (currentCourse != course)) { dummyMachine = new Machine(); //creates a new machine to be used currentCourse = (int)dr.ItemArray[0]; currentQuarter = (int)dr.ItemArray[4]; currentSection = (int)dr.ItemArray[5]; } dummyDayTime = new DayTime(); dummyDayTime.SetDayTime(day, start, end); dummyMachine.AddDayTime(dummyDayTime); dummyMachine.SetQuarter(quarter); //we add a new machine when we peek to the next row and see //(different course) OR (same course and (different section OR dif qtr)) //Andrue Note: Maybe isolate these arguments into helper functions for ease-of-use? //if (itself(?)) OR (not same course) OR (IS course but NOT SAME Section OR Quarter) int next = dt_size - 1; if (dt_size == 0 || ((int)dt.Rows[next].ItemArray[0] != currentCourse || ((int)dt.Rows[next].ItemArray[0] == currentCourse && ((int)dt.Rows[next].ItemArray[5] != currentSection) || (int)dt.Rows[next].ItemArray[4] != currentQuarter))) { addMachine(dummyMachine, new Job(course, credits, false)); } dt_size--; } }