Ejemplo n.º 1
0
        public void AllocateUnsedServerToPool(Pool pool)
        {
            var nextServer = _unusedServers.Pop();

            int col = -1;
            int row = 0;

            for (; row < _input.Rows; row++)
            {
                col = _allRows[row].GetAndAcquireSlot(nextServer.Slots);
                if (col != -1)
                {
                    break;
                }
            }

            if (col == -1)
            {
                return;
            }

            ServerAllocation allocation = new ServerAllocation {
                InitialColumn = col, Row = row, Server = nextServer
            };

            allocation.Pool = pool;

            _result._allocations.Add(allocation.Server, allocation);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public override ProblemOutput GetResultFromReader(ProblemInput input, TextReader reader)
        {
            ProblemOutput output = new ProblemOutput();

            output._allocations = new Dictionary <Server, ServerAllocation>();

            for (int i = 0; i < input.Servers.Count; i++)
            {
                string[] line = reader.ReadLine().Split(' ');
                if (line[0] == "x")
                {
                    continue;
                }
                int row  = int.Parse(line[0]);
                int slot = int.Parse(line[1]);
                int pool = int.Parse(line[2]);

                Server current = input.Servers[i];

                for (int j = 0; j < current.Slots; j++)
                {
                    if (input.UnavilableSlots.Contains(new Coordinate(slot + j, row)))
                    {
                        throw new InvalidProgramException("Validation failed, server placed in unavailable slot");
                    }
                }
                // Dictionary will validate that server is not used twice
                // Validation for server not in same spot in the printer to console code

                ServerAllocation alooc = new ServerAllocation();
                alooc.Row           = row;
                alooc.Pool          = input.Pools[pool];
                alooc.Server        = current;
                alooc.InitialColumn = slot;

                output._allocations.Add(current, alooc);
            }

            return(output);
        }