Ejemplo n.º 1
0
        public int getGradeForSection(section sec)
        {
            foreach (KeyValuePair <section, int> entry in sectionGrade)
            {
                if (entry.Key == sec)
                {
                    return(entry.Value);
                }
            }
            return(-1);

            /*
             * for (int i = 0; i < sectionGrade.Count;i++ )
             * {
             *  if (sectionGrade.ElementAt(i).Key.id == sec.id)
             *  {
             *      return sectionGrade.ElementAt(i).Value;
             *  }
             *
             * }
             * return -1;
             * */
        }
Ejemplo n.º 2
0
 public void SortForSecion(section sec)
 {
     //OrderBy(o=>o.OrderDate).ToList();
     studentslist = studentslist.OrderByDescending(o => o.getGradeForSection(sec)).ToList();
 }
Ejemplo n.º 3
0
 internal int ResSectionIndex(section SeekedSection)
 {
     return(secList.IndexOf(SeekedSection));
 }
Ejemplo n.º 4
0
        private bool RelocateStudents()
        {
            bool RetVal = false;

            for (int Sectionsindex = 0; Sectionsindex < secList.secList.Count; Sectionsindex++) //looping through sections
            {
                dataGridView1.Rows.Add();
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Value = "in section";
                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1].Value = secList.ReurnSectionByindex(Sectionsindex).id;
                for (int StudentIndex = 0; StudentIndex < secList.ReurnSectionByindex(Sectionsindex).stdlist.GetCount(); StudentIndex++) // looping through students
                {
                    section HisCurrentSection = secList.ReurnSectionByindex(Sectionsindex);
                    student currentStudent    = HisCurrentSection.stdlist.GetStudentyIndex(StudentIndex);


                    dataGridView1.Rows.Add();
                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Value = "in student";
                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1].Value = currentStudent.id;
                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[2].Value = "in section";
                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[3].Value = HisCurrentSection.id;

                    for (int PerfIndex = 0; PerfIndex < currentStudent.preferences.secList.Count; PerfIndex++)
                    {
                        section compSection = currentStudent.preferences.ReurnSectionByindex(PerfIndex);
                        dataGridView1.Rows.Add();
                        dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Value = "Comparing with pref";
                        dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1].Value = "Student: " + currentStudent.id;
                        dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[2].Value = "Current section " + HisCurrentSection.id;
                        dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[3].Value = "better section " + compSection.id;
                        dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[4].Value = "pref num  " + PerfIndex;
                        dataGridView1.Rows.Add();
                        if (compSection == HisCurrentSection)
                        {
                            dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Value = "Satisfied";
                            PerfIndex = currentStudent.preferences.secList.Count; // do not try other pref
                        }
                        else                                                      //pref not done
                        {
                            dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Value = "Not Satisfied";
                            section TargetSection = secList.RestSectionByID(currentStudent.preferences.ReurnSectionByindex(PerfIndex).id);


                            for (int TStudentIndex = 0; TStudentIndex < TargetSection.stdlist.GetCount(); TStudentIndex++) // looping through students in target section
                            {
                                dataGridView1.Rows.Add();
                                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Value = "Trying with section ";
                                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1].Value = TargetSection.id;
                                student TargetStudent = TargetSection.stdlist.GetStudentyIndex(TStudentIndex);
                                if (currentStudent == TargetStudent)
                                {
                                    dataGridView1.Rows.Add();
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Value = "It is me  ...";
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1].Value = "Current Student: " + currentStudent.id;
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[2].Value = "Current Section: " + HisCurrentSection.id;
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[3].Value = "Target Student: " + TargetStudent.id;
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[4].Value = "Target Section: " + TargetSection.id;
                                    continue;
                                }


                                if (currentStudent.getGradeForSection(TargetSection) > TargetStudent.getGradeForSection(TargetSection))
                                {
                                    dataGridView1.Rows.Add();
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Value = "Swapping ...";
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1].Value = "Current Student: " + currentStudent.id;
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[2].Value = "Current Section: " + HisCurrentSection.id;
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[3].Value = "Target Student: " + TargetStudent.id;
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[4].Value = "Target Section: " + TargetSection.id;


                                    if (!SwapStudents(secList, currentStudent, secList.ResSectionIndex(HisCurrentSection), TargetSection.stdlist.GetStudentyIndex(TStudentIndex), secList.ResSectionIndex(TargetSection)))
                                    {
                                        dataGridView1.Rows.Add();
                                        dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Value = "ERROR";

                                        return(false);
                                    }

                                    dataGridView1.Rows.Add();
                                    dataGridView1.Rows.Add();
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Value = "RESTARTING ...";
                                    RelocateStudents();
                                    //         PerfIndex = currentStudent.preferences.secList.Count;
//                                    StudentIndex++;
                                    return(true);
                                }
                                else
                                {
                                    dataGridView1.Rows.Add();
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0].Value = "He deserve more ...";
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1].Value = "Current Student: " + currentStudent.id;
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[2].Value = "Current Section: " + HisCurrentSection.id;
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[3].Value = "Target Student: " + TargetSection.stdlist.GetStudentyIndex(TStudentIndex).id;
                                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[4].Value = "Target Section: " + TargetSection.id;
                                }
                            }
                        }
                    }
                }
            }


            /*
             *
             * bool Relocate = false;
             * for (int Sectionsindex = 0; Sectionsindex < secList.secList.Count; Sectionsindex++) //looping through sections
             * {
             *
             *  for (int StudentIndex = 0; StudentIndex < secList.ReurnSectionByindex(Sectionsindex).stdlist.GetCount(); StudentIndex++) // looping through students
             *  {
             *
             *      section HisCurrentSection = secList.ReurnSectionByindex(Sectionsindex);
             *      student currentStudent = HisCurrentSection.stdlist.GetStudentyIndex(StudentIndex);
             *
             *      for (int PerfIndex = 0; PerfIndex < currentStudent.preferences.secList.Count; PerfIndex++)
             *      {
             *          section SeekedSection = secList.RestSectionByID(currentStudent.preferences.ReurnSectionByindex(PerfIndex).id);
             *
             *          int PerfForCurrentSection = currentStudent.GerPerfForSection(HisCurrentSection);
             *          int PerfForSeekedSection = currentStudent.GerPerfForSection(SeekedSection);
             *          if (SeekedSection != HisCurrentSection && (PerfForCurrentSection > PerfForSeekedSection))
             *          {
             *              for (int StudentInSeekedSectionIndex = 0; StudentInSeekedSectionIndex < SeekedSection.stdlist.GetCount(); StudentInSeekedSectionIndex++)
             *              {
             *                  student TargetStudent = SeekedSection.stdlist.GetStudentyIndex(StudentInSeekedSectionIndex);
             *
             *                  if (currentStudent.getGradeForSection(SeekedSection) > TargetStudent.getGradeForSection(SeekedSection) )
             *                  {
             *                      int t=secList.ResSectionIndex(SeekedSection);
             *                 //     if (!SwapStudents(secList, currentStudent, Sectionsindex, TargetStudent,t ))
             *                      if (!SwapStudents(secList, currentStudent, t, TargetStudent, Sectionsindex))
             *                      {
             *                      }
             *                        Relocate = true;
             *
             *                  }
             *
             *              }
             *          }
             *      }
             *
             *  }
             *
             *  if(Relocate)
             *  {
             *  //    RelocateStudents();
             *  }
             *
             * }
             *
             */

            return(RetVal);
        }
Ejemplo n.º 5
0
 public void AddSection(section sec)
 {
     secList.Add(sec);
 }