Ejemplo n.º 1
0
        public static int[,] Run(int[,] data, int target)
        {
            var row = data.GetUpperBound(0) + 1;
            var col = data.GetUpperBound(1) + 1;

            var search      = new IterativeMatrixSearch(data, target);
            var resultNodes = search.Start();

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

            var result = new int[row, col];

            for (var i = 0; i < row; i++)
            {
                for (var j = 0; j < col; j++)
                {
                    result[i, j] = resultNodes[i, j].Value.Low;
                }
            }

            return(result);
        }
Ejemplo n.º 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));
        }