Analyzer.ReciprocatedVertexPairRatioCalculator.CalculateReciprocatedVertexPairRatio C# (CSharp) Method

CalculateReciprocatedVertexPairRatio() protected method

protected CalculateReciprocatedVertexPairRatio ( IVertex oVertex, HashSet oVertexIDPairs ) : Double
oVertex IVertex
oVertexIDPairs HashSet
return Double
        protected Double CalculateReciprocatedVertexPairRatio
            (IVertex oVertex,HashSet<Int64> oVertexIDPairs)
        {
            Debug.Assert(oVertex != null);
            Debug.Assert(oVertexIDPairs != null);

            Int32 iAdjacentVerticesWithBothEdges = 0;
            Int32 iAdjacentVertices = 0;

            foreach (IVertex oAdjacentVertex in oVertex.AdjacentVertices)
            {
                // Skip self-loops.

                if (oAdjacentVertex != oVertex)
                {
                    iAdjacentVertices++;

                    // Check for edges in both directions.

                    if (
                        oVertexIDPairs.Contains( CollectionUtil.GetDictionaryKey(
                            oVertex.ID, oAdjacentVertex.ID, true) )
                        &&
                        oVertexIDPairs.Contains( CollectionUtil.GetDictionaryKey(
                            oAdjacentVertex.ID, oVertex.ID, true) )
                        )
                    {
                        iAdjacentVerticesWithBothEdges++;
                    }
                }
            }

            if (iAdjacentVertices == 0)
            {
                return (0);
            }

            return ( (Double)iAdjacentVerticesWithBothEdges /
                (Double)iAdjacentVertices );
        }