Example #1
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);
            }
        }
Example #2
0
 /// <summary>
 /// Step 4: Remove redundant paths from graph
 /// </summary>
 protected void RemoveRedundancy()
 {
     if (_redundantPathsPurger != null)
     {
         DeBruijnPathList redundantNodes;
         do
         {
             redundantNodes = _redundantPathsPurger.DetectErroneousNodes(_graph);
             _redundantPathsPurger.RemoveErroneousNodes(_graph, redundantNodes);
         } while (redundantNodes.Paths.Count > 0);
     }
 }