private bool AddWayneIfAcceptable(Wayne wayne) { if (wayne.IsAcceptable()) { _wayneTable.Add(wayne); return true; } return false; }
public void AddFixWayne(Wayne wayne) { if (!wayne.IsAcceptable()) { Console.WriteLine(wayne.ToString()); throw new Exception("Your fixed wayne is not correct, please recheck it"); } _doctorList.First(x => x == wayne.ERDoctor).ERWayne.Add(wayne.WayneDate); _doctorList.First(x => x == wayne.WardDoctor).WardWayne.Add(wayne.WayneDate); if (wayne.WayneDate.NeedOPD()) _doctorList.First(x => x == wayne.OPDDoctor).OPDWayne.Add(wayne.WayneDate); _wayneTable.Add(wayne); }
public void Fill() { if (IsDone()) { ShowFairness(); if (!FairEnough()) return; ShowResult(); return; } var currentDate = new DateTime(Year, Month, GetFirstDayToFill()); var erTireness = 10; var wardTireness = 5; var OPDTireness = 2; if (currentDate.IsHoliday()) { erTireness = (erTireness * 3) / 2; wardTireness = (wardTireness * 3) / 2; } var wayne = new Wayne(currentDate); var rnd = new Random(); var doctorListCopy = _doctorList .Where(x => !x.AbsenceList.Contains(currentDate)) .Where(x => !x.AmInWayneMoreThanTwoConsecutiveDays(currentDate)) .OrderBy(x => (x.ERWayne.Count() + x.WardWayne.Count() + x.OPDWayne.Count()) / x.Factor) .ThenBy(x => x.Tireness / x.Factor) .ThenBy(x => rnd.Next()) .Take(currentDate.NeedOPD() ? 4 : 3) .ToList(); foreach (var erDoctor in doctorListCopy.Where(d => d.AmIOKForERThisDay(currentDate))) { wayne.ERDoctor = erDoctor; erDoctor.ERWayne.Add(currentDate); erDoctor.Tireness += erTireness; foreach (var wardDoctor in doctorListCopy.Where(d => d != erDoctor && d.AmIOKForWardThisDay(currentDate))) { wayne.WardDoctor = wardDoctor; wardDoctor.WardWayne.Add(currentDate); wardDoctor.Tireness += wardTireness; if (!currentDate.NeedOPD()) { var wayneTableCopy = Copy(); if (wayneTableCopy.AddWayneIfAcceptable(wayne)) { wayneTableCopy.Fill(); } } else { foreach (var OPDDoctor in doctorListCopy.Where(d => d != erDoctor && d != wardDoctor)) { wayne.OPDDoctor = OPDDoctor; OPDDoctor.OPDWayne.Add(currentDate); OPDDoctor.Tireness += OPDTireness; var wayneTableCopy = Copy(); if (wayneTableCopy.AddWayneIfAcceptable(wayne)) { wayneTableCopy.Fill(); } OPDDoctor.Tireness -= OPDTireness; OPDDoctor.OPDWayne.Remove(currentDate); } } wardDoctor.Tireness -= wardTireness; wardDoctor.WardWayne.Remove(currentDate); } erDoctor.Tireness -= erTireness; erDoctor.ERWayne.Remove(currentDate); } }