Esempio n. 1
0
        public List <List <SubjectSelection> > Get_Optimized_Selections()
        {
            Optimized_Selections.Clear();
            Array.Clear(table, 0, table.Length);
            //table = new int[16, 7];

            Grouped_Selections = AvailableSelections
                                 .GroupBy(s => s.Subject.Id)
                                 .Select(g => g.OrderByDescending(s => s.Priority).ToList())
                                 .ToList();

            for (int i = 0; i < Grouped_Selections.Count; ++i)
            {
                if ((Grouped_Selections[i].Count > 0) && //exists at least one
                    (Preferred_Selections_Id.Exists(Id =>
                                                    Id == Grouped_Selections[i][0].SubjectId)))
                {
                    Grouped_Selections.RemoveAt(i--);
                }
            }

            for (int i = 0; i < Grouped_Selections.Count; ++i)
            {
                if (Grouped_Selections[i].Count == 0)
                {
                    Grouped_Selections.RemoveAt(i);
                }
            }

            int[] selections = new int[Grouped_Selections.Count];
            Attempt_Selections(selections, 0);

            return(Optimized_Selections);
        }
Esempio n. 2
0
        private void Attempt_Selections(int[] selections, int i)
        {
            if (i == Grouped_Selections.Count)
            {
                Optimized_Selections.Add(IntArrayToSelectionList(selections));
            }
            else
            {
                for (int j = 0; j < Grouped_Selections[i].Count; ++j)
                {
                    if (Add_Selection_To_Table(Grouped_Selections[i][j]))
                    {
                        selections[i] = j;
                        Attempt_Selections(selections, i + 1);
                    }

                    Remove_Selection_From_Table(Grouped_Selections[i][j]);
                }
            }
        }