Analyzer.ReciprocatedVertexPairRatioCalculator.TryCalculateGraphMetrics C# (CSharp) Method

TryCalculateGraphMetrics() public method

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

            IVertexCollection oVertices = graph.Vertices;
            Int32 iVertices = oVertices.Count;
            Int32 iCalculations = 0;

            // The key is an IVertex.ID and the value is the vertex's reciprocated
            // vertex pair ratio, or null.

            MetricDouble oReciprocatedVertexPairRatios = new MetricDouble(oVertices.Count, "ReciprocatedVertexPairRatio");
            graphMetrics = oReciprocatedVertexPairRatios;
            if (graph.Directedness == GraphDirectedness.Directed)
            {
                // Contains a key for each of the graph's unique edges.  The key is
                // the edge's ordered vertex ID pair.

                HashSet<Int64> oVertexIDPairs = GetVertexIDPairs(graph);

                foreach (IVertex oVertex in oVertices)
                {
                    // Check for cancellation and report progress every
                    // VerticesPerProgressReport calculations.

                    if (
                        (iCalculations % VerticesPerProgressReport == 0)
                        &&
                        !ReportProgressAndCheckCancellationPending(
                            iCalculations, iVertices, backgroundWorker)
                        )
                    {
                        return (false);
                    }

                    oReciprocatedVertexPairRatios.Add(oVertex.ID,
                        CalculateReciprocatedVertexPairRatio(
                            oVertex, oVertexIDPairs));

                    iCalculations++;
                }
            }

            return (true);
        }