예제 #1
0
        public static void ImproveWorstPoolWorstRow(ProblemInput input, ProblemOutput output2)
        {
            bool swap = true;
            int  m    = 0;

            while (swap)
            {
                // Console.WriteLine(m++);
                swap = Swap(input);
            }
        }
예제 #2
0
        private static List <Row> GetRows(ProblemInput input, PoolDetails poolToImprove)
        {
            List <Row> rows = new List <Row>();

            for (int i = 0; i < input.NumOfRows; i++)
            {
                rows.Add(new Row(i)
                {
                    Capacity = poolToImprove.RowsCapacity[i]
                });
            }

            return(rows);
        }
예제 #3
0
        private static bool Swap(ProblemInput input)
        {
            var worst       = input.Pools.Min(_ => _.GuaranteedCapacity);
            var allBadPools = input.Pools.Where(_ => _.GuaranteedCapacity == worst);

            foreach (var poolToImprove in allBadPools.ToList())
            {
                foreach (PoolDetails goodPool in input.Pools.OrderByDescending(_ => _.GuaranteedCapacity).ToList())
                {
                    for (int j = 0; j < input.NumOfRows; j++)
                    {
                        foreach (var server1 in goodPool.Servers.Where(_ => _.Row == j).ToList())
                        {
                            foreach (var server2 in poolToImprove.Servers.Where(_ => _.Capacity < server1.Capacity).ToList())
                            {
                                poolToImprove.RemoveServerFromPool(server2);
                                goodPool.RemoveServerFromPool(server1);

                                goodPool.AddServerToPool(server2);
                                poolToImprove.AddServerToPool(server1);

                                if (goodPool.GuaranteedCapacity > worst && poolToImprove.GuaranteedCapacity > worst)
                                {
                                    return(true);
                                }
                                else
                                {
                                    poolToImprove.RemoveServerFromPool(server1);
                                    goodPool.RemoveServerFromPool(server2);

                                    goodPool.AddServerToPool(server1);
                                    poolToImprove.AddServerToPool(server2);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }