private static void addOldScheduleToNewScheduleTillTimeSlot(IEnumerable<Models.Activity> oldSchedule, int Day, int Slot)
{
int i, j, z, groupIndex = 0, stationIndex = 0, prefIndex = -1, constraintIndex = -1;
// take out the second scheduled activity pin
bool[] vis = new bool[ oldSchedule.Count() ];
oldSchedule = oldSchedule.OrderBy(a => a.TimeSlot.Start);
List<Models.Activity> oldSched = oldSchedule.ToList();
for (i = 0; i < oldSched.Count(); i++)
{
if (vis[i])
continue;
if (oldSched[i].Station.isActivityPin)
{
for (j = i + 1; j < oldSched.Count; j++)
{
if (oldSched[j].Station.ID == oldSched[i].Station.ID && oldSched[j].Group.ID == oldSched[i].Group.ID &&
oldSched[j].TimeSlot.Start.DayOfWeek == oldSched[i].TimeSlot.Start.DayOfWeek)
{
vis[j] = true;
break;
}
}
}
}
for(z=0;z<oldSched.Count;z++)
{
if (vis[z])
continue;
Models.Activity A = oldSched[z];
KeyValuePair<int, int> DS = timeSlotToDaySlot(A.TimeSlot);
for (i = 0; i < AllGroups.Count; i++) if (AllGroups[i].ID == A.Group.ID) { groupIndex = i; break; }
for (i = 0; i < AllStations.Count; i++) if (AllStations[i].ID == A.Station.ID) { stationIndex = i; break; }
oldMasterSchedule[DS.Key, DS.Value].Add(groupIndex, stationIndex);
if( AllStations[stationIndex].isActivityPin )
oldMasterSchedule[DS.Key, DS.Value + 1].Add(groupIndex, stationIndex);
if (DS.Key > Day || DS.Key == Day && DS.Value >= Slot)
continue;
for(i=0;i<AllGroups.Count;i++)
for(j=0;j<5;j++)
if (AllGroups[i].StationPicks[j] != -1 && !AllGroups[i].StationPicked[j] && AllGroups[i].StationPicks[j] == stationIndex)
{
prefIndex = -1;
break;
}
if( prefIndex == -1 )
for (i = 0; i < AllConstraints.Count; i++)
if (!ConstraintMet[i] && AllConstraints[i].G == AllGroups[groupIndex] && AllConstraints[i].S == AllStations[stationIndex])
{
constraintIndex = i;
break;
}
scheduleGroupToStationAtDaySlot(groupIndex, stationIndex, DS.Key, DS.Value, constraintIndex, prefIndex);
}
}