Boy_Scouts_Scheduler.GreedyAlgorithm.GreedyScheduler.getSchedule C# (CSharp) Method

getSchedule() public static method

public static getSchedule ( IEnumerable groups, IEnumerable stations, IEnumerable constraints, IEnumerable slots, IEnumerable oldSchedule, Models startingTimeSlot ) : IEnumerable
groups IEnumerable
stations IEnumerable
constraints IEnumerable
slots IEnumerable
oldSchedule IEnumerable
startingTimeSlot Models
return IEnumerable
        public static IEnumerable<Models.Activity> getSchedule(IEnumerable<Models.Group> groups, IEnumerable<Models.Station> stations, IEnumerable<Models.SchedulingConstraint> constraints, 
				IEnumerable<Models.TimeSlot> slots, IEnumerable<Models.Activity> oldSchedule, Models.TimeSlot startingTimeSlot)
        {
            ZeroOut();

            List<Models.Activity> schedule = new List<Models.Activity>();

            AllGroups = new List<Group>();
            AllStations = new List<Station>();
            AllConstraints = new List<Constraint>();

            int i,j,k;

            convertTimeSlotsToDaySlots(slots);

            List<Models.Group> tmpallGroups = new List<Models.Group>(groups.ToArray());
            List<Models.Station> tmpallStations = new List<Models.Station>(stations.ToArray());
            List<Models.TimeSlot> tmpallSlots = new List<Models.TimeSlot>(slots.ToArray());

            foreach (Models.Station s in stations)
                AllStations.Add(new Station(s.ID, s.Name, s.Capacity, s.Category, s.isActivityPin, timeSlotsToAvailability(s.AvailableTimeSlots)));

            foreach (Models.Group x in groups)
            {
                int p1 = -1, p2 = -1, p3 = -1, p4 = -1, p5 = -1;

                for (i = 0; i < AllStations.Count; i++)
                {
                    if (x.Preference1 != null && x.Preference1.ID == AllStations[i].ID) p1 = i;
                    if (x.Preference2 != null && x.Preference2.ID == AllStations[i].ID) p2 = i;
                    if (x.Preference3 != null && x.Preference3.ID == AllStations[i].ID) p3 = i;
                    if (x.Preference4 != null && x.Preference4.ID == AllStations[i].ID) p4 = i;
                    if (x.Preference5 != null && x.Preference5.ID == AllStations[i].ID) p5 = i;
                }

                AllGroups.Add(new Group(x.ID, x.Name, x.Type.ID, p1, p2, p3, p4, p5));
            }

            foreach (Models.SchedulingConstraint c in constraints)
            {
                Group g = AllGroups[0];
                Station s = AllStations[0];

                for (i = 0; i < AllStations.Count; i++) if (AllStations[i].ID == c.Station.ID) s = AllStations[i];

                if (c.Group != null)
                {
                    for (i = 0; i < AllGroups.Count; i++) if (AllGroups[i].ID == c.Group.ID) g = AllGroups[i];

                    AllConstraints.Add(new Constraint(g, s, c.VisitNum));
                }
                else if (c.GroupType != null)
                {
                    for (i = 0; i < AllGroups.Count; i++)
                        if (c.GroupType.ID == AllGroups[i].Rank)
                            AllConstraints.Add(new Constraint(g, s, c.VisitNum));
                }
                else if( c.Group == null && c.GroupType == null)
                    for (i = 0; i < AllGroups.Count; i++)
                        AllConstraints.Add(new Constraint(AllGroups[i], s, c.VisitNum));
            }

            KeyValuePair<int, int> startDaySlot = timeSlotToDaySlot(startingTimeSlot);

            if (startDaySlot.Key == 1 && startDaySlot.Value == 1)
                generateNewScheduleFromScracth = true;
            else
                generateNewScheduleFromScracth = false;

            addOldScheduleToNewScheduleTillTimeSlot(oldSchedule, startDaySlot.Key, startDaySlot.Value);

            Schedule(startDaySlot.Key, startDaySlot.Value);

            /*
            Dictionary<string, string>[,] Q = new Dictionary<string, string>[10, 20];

            for(i=0;i<10;i++)
                for(j=0;j<20;j++)
                {
                    Q[i,j] = new Dictionary<string,string>();

                    foreach (KeyValuePair<int, int> P in masterSchedule[i, j])
                    {
                        Q[i, j].Add(AllGroups[P.Key].Name, AllStations[P.Value].Name);
                    }
                }
             * */
            for (i = 1; i <= 5; i++)
            {
                for (j = 1; j <= nSlots[i]; j++)
                {
                    int slotID = daySlotToTimeSlot(i, j);
                    Models.TimeSlot T = new Models.TimeSlot();

                    foreach (Models.TimeSlot t in slots)
                        if (t.ID == slotID)
                            T = t;

                    foreach (KeyValuePair<int, int> P in masterSchedule[i, j])
                    {
                        Models.Activity A = new Models.Activity();

                        A.Group = tmpallGroups[P.Key];
                        A.Station = tmpallStations[P.Value];

                        A.TimeSlot = T;

                        schedule.Add(A);
                    }
                }
            }

            return schedule;
        }