private Dock(DockData data, Dictionary <string, BerthingAlgorithm> berthingChoices) { berthSpots = new IBerth[data.Size]; for (var i = 0; i < data.Boats.Length; i++) { AddBoat(data.Boats[i], data.Indices[i], data.BerthTimes[i]); } foreach (BoatData boatData in data.LeftToday) { leftToday.Add(Boat.FromData(boatData)); } if (berthingChoices.TryGetValue(data.BerthingChoiceAlgorithm, out BerthingAlgorithm berthingChoice)) { SetBerthingAlgorithm(berthingChoice, data.BerthingChoiceAlgorithm); } else { SetBerthingAlgorithm(DefaultBerthing, nameof(DefaultBerthing)); } }
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); }
public static Dock FromData(DockData dockData, Dictionary <string, BerthingAlgorithm> berthingChoices) { return(new Dock(dockData, berthingChoices)); }