/// <summary> /// Go through the current table list to determine switch targets /// The target can be one family, and can be a combination of families, /// currently sitting on the table, whose combined sizes /// is suitable for a switch. /// Cannot do two moves yet. /// For simplicity, we just look for a single family at a time /// for switching. No combinations. /// </summary> /// <param name="fmly"></param> /// <returns></returns> private static List <Family> BuildSwitchTargeList(Family fmly) { List <Family> list = new List <Family> { }; for (int j = 0; j < _tableList.Count; j++) { //only occupied tables if (_tableList[j].GuestList != null) { for (int k = 0; k < _tableList[j].GuestList.Count; k++) { WeddingTable currentTable = _tableList[j]; Family currentGuest = _tableList[j].GuestList[k]; if (fmly.Size <= currentGuest.Size + _tableList[j].FreeSpots) { //check if the family is compatible with the remaining families //if so, add currentTable.GuestList.Remove(currentGuest); if (currentTable.FirendlyWith(fmly.Name) && fmly.Likes(currentTable.FamilyNames)) { list.Add(currentGuest); } //add it back currentTable.GuestList.Add(currentGuest); } } } } return(list); }
/// <summary> /// Initial assignment /// </summary> /// <param name="fmly"></param> private static void Assign_Seats(Family fmly) { bool assigned = false; //always first //tableList = tableList.OrderByDescending(y => y.FreeSpots).ToList(); for (int j = 0; j < _tableList.Count; j++) { //initial assignment if (_tableList[j].FreeSpots >= fmly.Size && _tableList[j].FirendlyWith(fmly.Name) && fmly.Likes(_tableList[j].FamilyNames)) { fmly.TableName = _tableList[j].Name; _tableList[j].GuestList.Add(fmly); _unseated_list.Remove(fmly); assigned = true; break; } } if (!assigned) { //determine whether it's because of table capacity int largest_spot = _tableList.Max(x => x.FreeSpots); if (largest_spot < _unseated_list[0].Size) { throw new Exception("Not enough large table to sit enire families."); } _leftover_list.Add(_unseated_list[0]); _unseated_list.Remove(_unseated_list[0]); } }
/// <summary> /// trying to find the switch target a spot /// </summary> /// <param name="fmly"></param> /// <returns></returns> private static bool Assign_Switched_Seats(Family fmly) { bool assigned = false; //always first //tableList = tableList.OrderByDescending(y => y.FreeSpots).ToList(); for (int j = 0; j < _tableList.Count; j++) { //initial assignment if (_tableList[j].FreeSpots >= fmly.Size && _tableList[j].FirendlyWith(fmly.Name) && fmly.Likes(_tableList[j].FamilyNames)) { fmly.TableName = _tableList[j].Name; _tableList[j].GuestList.Add(fmly); _leftover_list.Remove(fmly); assigned = true; break; } } return(assigned); }