private static bool[] GetFreeBerths(double berthSpace, IBerth[] berths) { var freeSpots = new bool[berths.Length]; if (berthSpace >= 1) { for (var i = 0; i < berths.Length; i++) { freeSpots[i] = berths[i] is null; } } else { for (var i = 0; i < berths.Length; i++) { IBerth spot = berths[i]; if (spot is null || spot.FreeSpace >= berthSpace) { freeSpots[i] = true; } } } return(freeSpots); }
public bool TryRemove(Boat boat) { for (var i = 0; i < berthSpots.Length; i++) { if (berthSpots[i] is null) { continue; } if (berthSpots[i].Occupancy.Select(o => o.boat).Contains(boat)) { int size = berthSpots[i].Size; IBerth berth = berthSpots[i].RemoveBoat(boat); for (var j = 0; j < size; j++) { berthSpots[i + j] = berth; } return(true); } } return(false); }
public DockData AsData() { int count = Boats.Count(); var data = new DockData { Size = Size, BerthingChoiceAlgorithm = algorithmName, Boats = new BoatData[count], Indices = new int[count], BerthTimes = new int[count], LeftToday = leftToday.Select(b => b.AsData()).ToArray() }; IBerth prev = null; for (int source = 0, target = 0; source < berthSpots.Length; source++) { IBerth spot = berthSpots[source]; if (spot is null || spot == prev) { continue; } foreach ((Boat boat, int berthTime) in spot.Occupancy) { data.Indices[target] = source; data.Boats[target] = boat.AsData(); data.BerthTimes[target] = berthTime; target++; } prev = spot; } return(data); }