コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public static Dock FromData(DockData dockData, Dictionary <string, BerthingAlgorithm> berthingChoices)
 {
     return(new Dock(dockData, berthingChoices));
 }