Ejemplo n.º 1
0
        private List <Suggestion> GetUniqueSuggestions(
            Group group,
            IReadOnlyList <Connector> connectors,
            decimal occupiedCapacity,
            decimal maxCurrentInAmps
            )
        {
            var availableCapacity    = group.CapacityInAmps - occupiedCapacity;
            var freeingCapacityConst = maxCurrentInAmps - availableCapacity;
            var lastSuggestionCount  = connectors.Count;
            var i           = 0;
            var suggestions = new List <Suggestion>();

            while (i < connectors.Count)
            {
                if (connectors[i].MaxCurrentInAmps <= maxCurrentInAmps)
                {
                    var pos             = i;
                    var freeingCapacity = freeingCapacityConst - connectors[pos].MaxCurrentInAmps;
                    var suggestion      = new Suggestion(new[] { pos });

                    while (freeingCapacity > 0M && suggestion.List.Count < lastSuggestionCount)
                    {
                        pos = SearchBinaryInDescendingList(connectors, freeingCapacity, pos);

                        if (pos < connectors.Count && (freeingCapacity - connectors[pos].MaxCurrentInAmps >= 0M))
                        {
                            suggestion.AddIndex(pos);
                            freeingCapacity -= connectors[pos].MaxCurrentInAmps;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (freeingCapacity == 0M && suggestion.List.Count <= lastSuggestionCount)
                    {
                        lastSuggestionCount = suggestion.List.Count;
                        suggestions.Add(suggestion);
                    }
                }

                i++;
            }

            var result = new List <Suggestion>();

            foreach (var suggestion in suggestions)
            {
                if (suggestion.List.Count > lastSuggestionCount)
                {
                    continue;
                }

                result.Add(suggestion);
            }

            return(result);
        }