Exemple #1
0
        public ServerSelector(ProblemInput input, ProblemOutput result)
        {
            _input  = input;
            _result = result;

            _availableServersByCapacity = new Stack <Server>(GetServerListByPreference(input));
        }
Exemple #2
0
 public RowAllocator(ProblemInput input, ProblemOutput result, Random random)
 {
     _random        = random;
     _result        = result;
     _input         = input;
     _unusedServers = new Stack <Server>();
     CreateRows();
 }
Exemple #3
0
        public bool AllocateNextServerToPool(ProblemInput input, ServerSelector serverSelector, Pool pool)
        {
            var nextServer = serverSelector.UseNextServer();
            ServerAllocation allocation = AlllocateServerToRow(input, nextServer, pool);

            if (allocation == null)
            {
                _unusedServers.Push(nextServer);
                return(false);
            }

            allocation.Pool = pool;

            _result._allocations.Add(allocation.Server, allocation);
            return(true);
        }
Exemple #4
0
        public Row(ProblemInput input, int rowIndex)
        {
            _rowIndex    = rowIndex;
            _columns     = input.Columns;
            _isAvailable = new bool[input.Columns];
            for (int i = 0; i < input.Columns; i++)
            {
                _isAvailable[i] = true;
            }

            foreach (var slot in input.UnavilableSlots)
            {
                if (slot.Y != rowIndex)
                {
                    continue;
                }

                _isAvailable[slot.X] = false;
            }
        }
Exemple #5
0
        private ServerAllocation AlllocateServerToRow(ProblemInput input, Server server, Pool pool)
        {
            Row row;
            int column;
            int tries = 0;

            do
            {
                row    = GetNextRowForPool(pool);
                column = row.GetAndAcquireSlot(server.Slots);
                tries++;
                if (tries > input.Rows * 2)
                {
                    return(null);
                }
            } while (column == -1);

            return(new ServerAllocation {
                InitialColumn = column, Row = row._rowIndex, Server = server
            });
        }
Exemple #6
0
 private IOrderedEnumerable <Server> GetServerListByPreference(ProblemInput input)
 {
     return(input.Servers.OrderBy(x => ((double)x.Capacity) / x.Slots));
 }