Пример #1
0
        public List <NodeDescription> AddSeedNodes(
            int seedNodesToAdd,
            IEnumerable <NodeDescription> nodes,
            IEnumerable <NodeDescription> currentSeedNodes,
            int faultDomainCount,
            int upgradeDomainCount)
        {
            this.UpdateNodeInfo(nodes, faultDomainCount, upgradeDomainCount);

            if (seedNodesToAdd <= 0 || nodes.Count() < currentSeedNodes.Count() + seedNodesToAdd)
            {
                return(null);
            }

            if (nodes.Count() == currentSeedNodes.Count() + seedNodesToAdd)
            {
                return(SubtractNodes(nodes, currentSeedNodes));
            }

            var data     = this.GetMatrix(nodes);
            var existing = this.GetMatrix(currentSeedNodes);

            var result = RandomMatrixSearch.Run(data, existing, currentSeedNodes.Count() + seedNodesToAdd, true);

            for (int i = 0; i < this.row; i++)
            {
                for (int j = 0; j < this.col; j++)
                {
                    result[i, j] -= existing[i, j];
                }
            }

            return(this.GetNodesFromMatrix(SubtractNodes(nodes, currentSeedNodes), result));
        }
Пример #2
0
        private IEnumerable <NodeDescription> SelectInternal(
            int targetSeedNodeCount,
            IEnumerable <NodeDescription> nodes,
            bool allowSuboptimal)
        {
            this.traceLogger.WriteInfo(SeedNodeSelector.TraceType, "SeedNodeSelector.SelectInternal: Entering. allowSuboptimal: {0}", allowSuboptimal);

            var data = this.GetMatrix(nodes);

            if (!allowSuboptimal)
            {
                var upperLimit = (targetSeedNodeCount + Math.Max(this.row, this.col) - 1) / Math.Max(this.row, this.col);
                for (int i = 0; i < this.row; i++)
                {
                    for (int j = 0; j < this.col; j++)
                    {
                        if (data[i, j] > upperLimit)
                        {
                            data[i, j] = upperLimit;
                        }
                    }
                }
            }

            if (nodes.Count() == targetSeedNodeCount)
            {
                if (!allowSuboptimal && !Validate(data, targetSeedNodeCount, data))
                {
                    this.traceLogger.WriteInfo(SeedNodeSelector.TraceType, "SeedNodeSelector.SelectInternal: return null.");
                    return(null);
                }

                this.traceLogger.WriteInfo(SeedNodeSelector.TraceType, "SeedNodeSelector.SelectInternal: return original nodes.");
                return(nodes);
            }

            var result = IterativeMatrixSearch.Run(data, targetSeedNodeCount);

            this.traceLogger.WriteInfo(SeedNodeSelector.TraceType, "SeedNodeSelector.SelectInternal: IterativeMatrixSearch.Run returns {0}.", result != null);

            if (result == null && allowSuboptimal)
            {
                result = RandomMatrixSearch.Run(data, null, targetSeedNodeCount, true);
                this.traceLogger.WriteInfo(SeedNodeSelector.TraceType, "SeedNodeSelector.SelectInternal: RandomMatrixSearch.Run returns {0}.", result != null);
            }

            if (result == null)
            {
                return(null);
            }

            return(this.GetNodesFromMatrix(nodes, result));
        }
Пример #3
0
        public List <NodeDescription> RemoveSeedNodes(
            int seedNodesToRemove,
            IEnumerable <NodeDescription> currentSeedNodes)
        {
            this.UpdateNodeInfo(currentSeedNodes, this.row, this.col);

            if (seedNodesToRemove <= 0 || currentSeedNodes.Count() <= seedNodesToRemove)
            {
                return(null);
            }

            var data         = this.GetMatrix(currentSeedNodes);
            var result       = RandomMatrixSearch.Run(data, null, currentSeedNodes.Count() - seedNodesToRemove, true);
            var newSeedNodes = this.GetNodesFromMatrix(currentSeedNodes, result);

            return(SubtractNodes(currentSeedNodes, newSeedNodes));
        }