public static List <DailyRoomAllocation> ListDailyRoomAllocation(GRBVar[,,] x, GRBVar[,] y, double objVal) { int numGroups = x.GetLength(0); int numRooms = x.GetLength(1); List <DailyRoomAllocation> roomsAllocation = new List <DailyRoomAllocation>(); for (int k = 0; k < x.GetLength(2); k++) { DailyRoomAllocation dailyAllocation = new DailyRoomAllocation(); int numGroupsSplits = 0; for (int i = 0; i < x.GetLength(0); i++) { if (y[i, k].X == 1) { numGroupsSplits++; } for (int j = 0; j < x.GetLength(1); j++) { if (x[i, j, k].X == 1) { dailyAllocation.RoomGroupsAllocated.Add(new Tuple <int, int>(j, i)); } } } dailyAllocation.NumGroupsSplits = numGroupsSplits; dailyAllocation.FuncObj = objVal; dailyAllocation.FillRoomAllocation(numRooms); roomsAllocation.Add(dailyAllocation); } return(roomsAllocation); }
public static List <DailyRoomAllocation> ListDailyRoomAllocation(GRBVar[,,] x, GRBVar[,] y, GRBVar[,] z, Dictionary <int, int> personToGroup, double objVal) { int numGroups = x.GetLength(0); int numRooms = x.GetLength(1); List <DailyRoomAllocation> roomsAllocation = new List <DailyRoomAllocation>(); for (int k = 0; k < x.GetLength(2); k++) { DailyRoomAllocation dailyAllocation = new DailyRoomAllocation(); double numGroupsSplits = 0; double numGroupsChanges = 0; for (int i = 0; i < x.GetLength(0); i++) { if (y[personToGroup[i], k].X == 1) { numGroupsSplits += 1 / Convert.ToDouble(personToGroup.Where(p => p.Value == personToGroup[i]).Count()); } if (z[personToGroup[i], k].X == 1) { numGroupsChanges += 1 / Convert.ToDouble(personToGroup.Where(p => p.Value == personToGroup[i]).Count()); } for (int j = 0; j < x.GetLength(1); j++) { if (x[i, j, k].X == 1) { dailyAllocation.RoomGroupsAllocated.Add(new Tuple <int, int>(j, personToGroup[i])); } } } dailyAllocation.NumGroupsSplits = numGroupsSplits; dailyAllocation.NumGroupsChanges = numGroupsChanges; dailyAllocation.FuncObj = objVal; dailyAllocation.FillRoomAllocation(numRooms); if (k != 0) { FillGroupsEnteredLeft(dailyAllocation, roomsAllocation.Last()); } roomsAllocation.Add(dailyAllocation); } return(roomsAllocation); }
private static void FillGroupsEnteredLeft(DailyRoomAllocation dailyAllocation, DailyRoomAllocation previousAllocation) { var groups = dailyAllocation.RoomGroupsAllocated.Select(g => g.Item2).Distinct(); var lastDayGroups = previousAllocation.RoomGroupsAllocated.Select(g => g.Item2).Distinct(); List <int> groupsEntered = new List <int>(); List <int> groupsLeft = new List <int>(); foreach (var group in groups) { if (!lastDayGroups.Any(g => g == group)) { groupsEntered.Add(group); } } dailyAllocation.GroupsEntered = string.Join(";", groupsEntered); foreach (var group in lastDayGroups) { if (!groups.Any(g => g == group)) { groupsLeft.Add(group); } } dailyAllocation.GroupsLeft = string.Join(";", groupsLeft); }