Exemplo n.º 1
0
        /// <summary>
        /// Step 3: Remove dangling links from graph.
        /// </summary>
        protected void UnDangleGraph()
        {
            if (this.DanglingLinksPurger != null && this.DanglingLinksThreshold > 0)
            {
                DeBruijnPathList danglingNodes = null;

                // Observe lengths of dangling links in the graph
                // This is an optimization - instead of incrementing threshold by 1 and
                // running the purger iteratively, we first determine the lengths of the
                // danglings links found in the graph and run purger only for those lengths.
                this.DanglingLinksPurger.LengthThreshold = this.DanglingLinksThreshold - 1;

                IEnumerable <int> danglingLengths;
                IGraphEndsEroder  graphEndsEroder = this.DanglingLinksPurger as IGraphEndsEroder;
                if (graphEndsEroder != null && this.AllowErosion)
                {
                    // If eroder is implemented, while getting lengths of dangling links,
                    // it also erodes the low coverage ends, this marks any node for deletion below a threshold.

                    //TODO: Verify that this does enumerate all dangling ends, the concern is that if a dangling end of length 7 and 2
                    //arrive at a node which itself would be of dangling node of length 2 without these "dangling ends" then a dangling end of 9
                    // (which it would be without either the 7 or 2 end) might not be reported.
                    danglingLengths = graphEndsEroder.ErodeGraphEnds(this.Graph, this.ErosionThreshold);
                }
                else
                {
                    // Perform dangling purger at all incremental values till dangleThreshold.
                    danglingLengths = Enumerable.Range(1, this.DanglingLinksThreshold - 1);
                }

                // Erosion is to be only once. Reset erode threshold to -1.
                this.ErosionThreshold = -1;


                // Start removing dangling links
                foreach (int threshold in danglingLengths)
                {
                    if (this.Graph.NodeCount >= threshold)
                    {
                        this.DanglingLinksPurger.LengthThreshold = threshold;
                        danglingNodes = this.DanglingLinksPurger.DetectErroneousNodes(this.Graph);
                        this.DanglingLinksPurger.RemoveErroneousNodes(this.Graph, danglingNodes);
                    }
                }

                // Removing dangling links can in turn create more dangling links
                // In order to remove all links within threshold, we therefore run
                // purger at threshold length until there is no more change in graph.
                do
                {
                    danglingNodes = null;
                    if (this.Graph.NodeCount >= this.DanglingLinksThreshold)
                    {
                        this.DanglingLinksPurger.LengthThreshold = this.DanglingLinksThreshold;
                        danglingNodes = this.DanglingLinksPurger.DetectErroneousNodes(this.Graph);
                        this.DanglingLinksPurger.RemoveErroneousNodes(this.Graph, danglingNodes);
                    }
                }while (danglingNodes != null && danglingNodes.Paths.Count > 0);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Step 3: Remove dangling links from graph
        /// </summary>
        protected void UnDangleGraph()
        {
            if (_danglingLinksPurger != null && _dangleThreshold > 0)
            {
                DeBruijnPathList danglingNodes = null;

                // Observe lenghts of dangling links in the graph
                // This is an optimization - instead of incrementing threshold by 1 and
                // running the purger iteratively, we first determine the lengths of the
                // danglings links found in the graph and run purger only for those lengths.
                _danglingLinksPurger.LengthThreshold = _dangleThreshold - 1;

                IEnumerable <int> danglingLengths;
                IGraphEndsEroder  graphEndsEroder = _danglingLinksPurger as IGraphEndsEroder;
                if (graphEndsEroder != null && _isErosionEnabled)
                {
                    // If eroder is implemented, while getting lengths of dangling links,
                    // it also erodes the low coverage ends.
                    danglingLengths = graphEndsEroder.ErodeGraphEnds(_graph, _erosionThreshold);
                }
                else
                {
                    // Perform dangling purger at all incremental values till dangleThreshold.
                    danglingLengths = Enumerable.Range(1, _dangleThreshold - 1);
                }

                // Erosion is to be only once. Reset erode threshold to -1.
                _erosionThreshold = -1;

                // Start removing dangling links
                foreach (int threshold in danglingLengths)
                {
                    if (_graph.Nodes.Count >= threshold)
                    {
                        _danglingLinksPurger.LengthThreshold = threshold;
                        danglingNodes = _danglingLinksPurger.DetectErroneousNodes(_graph);
                        _danglingLinksPurger.RemoveErroneousNodes(_graph, danglingNodes);
                    }
                }

                // Removing dangling links can in turn create more dangling links
                // In order to remove all links within threshold, we therefore run
                // purger at threshold length until there is no more change in graph.
                do
                {
                    danglingNodes = null;
                    if (_graph.Nodes.Count >= _dangleThreshold)
                    {
                        _danglingLinksPurger.LengthThreshold = _dangleThreshold;
                        danglingNodes = _danglingLinksPurger.DetectErroneousNodes(_graph);
                        _danglingLinksPurger.RemoveErroneousNodes(_graph, danglingNodes);
                    }
                }while (danglingNodes != null && danglingNodes.Paths.Count > 0);
            }
        }