Analyzer.PageRankCalculator.TryCalculateGraphMetrics C# (CSharp) Method

TryCalculateGraphMetrics() public method

public TryCalculateGraphMetrics ( IGraph graph, BackgroundWorker backgroundWorker, MetricDouble &graphMetrics ) : System.Boolean
graph IGraph
backgroundWorker System.ComponentModel.BackgroundWorker
graphMetrics MetricDouble
return System.Boolean
        public Boolean TryCalculateGraphMetrics
        (
            IGraph graph,
            BackgroundWorker backgroundWorker,
            out MetricDouble graphMetrics
        )
        {
            Debug.Assert(graph != null);
            

            IVertexCollection oVertices = graph.Vertices;

            /** initialize PR per vertex **/
            Dictionary<Int32, Double> oldPageRanks = new Dictionary<Int32, Double>(oVertices.Count);
            Dictionary<Int32, Double> newPageRanks = new Dictionary<Int32, Double>(oVertices.Count);
            MetricDouble oMetricDouble = new MetricDouble(oVertices.Count, "PageRank");
            graphMetrics = oMetricDouble;

            foreach(IVertex oVertex in oVertices){
                System.Console.WriteLine("V{0}", oVertex.ID);
                oldPageRanks.Add(oVertex.ID, 1.0/oVertices.Count);
                newPageRanks.Add(oVertex.ID, 0);
            }
            int ii = 0;
            while (!isConverged(oldPageRanks, newPageRanks)){
                
                oldPageRanks = newPageRanks;
                if (!ReportProgressAndCheckCancellationPending(0, 100, backgroundWorker))
                {
                    return (false);
                }
                calculateVertexPageRank(oVertices, oldPageRanks, out newPageRanks);
                ii++;
            }
            System.Console.WriteLine("ii = {0}", ii);
            
            foreach (KeyValuePair<Int32, Double> p in newPageRanks) {
                oMetricDouble.Add(p.Key, p.Value);
            }
          

            return (true);
        }