public ServerSelector(ProblemInput input, ProblemOutput result) { _input = input; _result = result; _availableServersByCapacity = new Stack <Server>(GetServerListByPreference(input)); }
public RowAllocator(ProblemInput input, ProblemOutput result, Random random) { _random = random; _result = result; _input = input; _unusedServers = new Stack <Server>(); CreateRows(); }
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); }
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; } }
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 }); }
private IOrderedEnumerable <Server> GetServerListByPreference(ProblemInput input) { return(input.Servers.OrderBy(x => ((double)x.Capacity) / x.Slots)); }