//*************************************************************************
        //  Method: GetGeodesicDistanceStrings()
        //
        /// <summary>
        /// Gets strings that describe the geodesic distances.
        /// </summary>
        ///
        /// <param name="oOverallMetrics">
        /// Contains the graph's overall metrics.
        /// </param>
        ///
        /// <param name="sMaximumGeodesicDistance">
        /// Where a string describing the maximum geodesic distance gets stored.
        /// </param>
        ///
        /// <param name="sAverageGeodesicDistance">
        /// Where a string describing the average geodesic distance gets stored.
        /// </param>
        //*************************************************************************
        protected void GetGeodesicDistanceStrings(
            OverallMetrics oOverallMetrics,
            out String sMaximumGeodesicDistance,
            out String sAverageGeodesicDistance
            )
        {
            Debug.Assert(oOverallMetrics != null);
            AssertValid();

            if (oOverallMetrics.MaximumGeodesicDistance.HasValue)
            {
            sMaximumGeodesicDistance = FormatInt32(
                oOverallMetrics.MaximumGeodesicDistance.Value);

            // The maximum and average are computed together.

            Debug.Assert(oOverallMetrics.AverageGeodesicDistance.HasValue);

            sAverageGeodesicDistance = FormatDouble(
                oOverallMetrics.AverageGeodesicDistance.Value);
            }
            else
            {
            sMaximumGeodesicDistance = sAverageGeodesicDistance =
                NotApplicableMessage;
            }
        }
        //*************************************************************************
        //  Method: TryCalculateGraphMetrics()
        //
        /// <summary>
        /// Attempts to calculate the graph metrics while optionally running on a
        /// background thread.
        /// </summary>
        ///
        /// <param name="graph">
        /// The graph to calculate metrics for.  The graph may contain duplicate
        /// edges and self-loops.
        /// </param>
        ///
        /// <param name="backgroundWorker">
        /// The BackgroundWorker whose thread is calling this method, or null if
        /// the method is being called by some other thread.
        /// </param>
        ///
        /// <param name="graphMetrics">
        /// Where the graph metrics get stored if true is returned.  
        /// </param>
        ///
        /// <returns>
        /// true if the graph metrics were calculated, false if the user wants to
        /// cancel.
        /// </returns>
        //*************************************************************************
        public Boolean TryCalculateGraphMetrics(
            IGraph graph,
            BackgroundWorker backgroundWorker,
            out OverallMetrics graphMetrics
            )
        {
            Debug.Assert(graph != null);
            AssertValid();

            graphMetrics = null;

            if (backgroundWorker != null)
            {
            if (backgroundWorker.CancellationPending)
            {
                return (false);
            }

            ReportProgress(1, 3, backgroundWorker);
            }

            DuplicateEdgeDetector oDuplicateEdgeDetector =
            new DuplicateEdgeDetector(graph);

            Int32 iVertices = graph.Vertices.Count;
            Int32 iEdges = graph.Edges.Count;
            Int32 iSelfLoops = CountSelfLoops(graph);

            Int32 iConnectedComponents, iSingleVertexConnectedComponents,
            iMaximumConnectedComponentVertices,
            iMaximumConnectedComponentEdges;

            CalculateConnectedComponentMetrics(graph, out iConnectedComponents,
            out iSingleVertexConnectedComponents,
            out iMaximumConnectedComponentVertices,
            out iMaximumConnectedComponentEdges);

            Nullable<Int32> iMaximumGeodesicDistance;
            Nullable<Double> dAverageGeodesicDistance;

            if (backgroundWorker != null)
            {
            ReportProgress(2, 3, backgroundWorker);
            }

            CalculateGeodesicDistances(graph, out iMaximumGeodesicDistance,
            out dAverageGeodesicDistance);

            OverallMetrics oOverallMetrics = new OverallMetrics(
            graph.Directedness,
            oDuplicateEdgeDetector.UniqueEdges,
            oDuplicateEdgeDetector.EdgesWithDuplicates,
            iSelfLoops,
            iVertices,

            CalculateGraphDensity(graph, iVertices,
                oDuplicateEdgeDetector.
                    TotalEdgesAfterMergingDuplicatesNoSelfLoops),

            iConnectedComponents,
            iSingleVertexConnectedComponents,
            iMaximumConnectedComponentVertices,
            iMaximumConnectedComponentEdges,
            iMaximumGeodesicDistance,
            dAverageGeodesicDistance
            );

            graphMetrics = oOverallMetrics;

            return (true);
        }
Exemplo n.º 3
0
        TryCalculateGraphMetrics
        (
            IGraph graph,
            BackgroundWorker backgroundWorker,
            out OverallMetrics graphMetrics
        )
        {
            Debug.Assert(graph != null);
            AssertValid();

            graphMetrics = null;

            if (backgroundWorker != null)
            {
                if (backgroundWorker.CancellationPending)
                {
                    return(false);
                }

                ReportProgress(1, 3, backgroundWorker);
            }

            DuplicateEdgeDetector oDuplicateEdgeDetector =
                new DuplicateEdgeDetector(graph);

            Int32 iVertices  = graph.Vertices.Count;
            Int32 iEdges     = graph.Edges.Count;
            Int32 iSelfLoops = CountSelfLoops(graph);

            Int32 iConnectedComponents, iSingleVertexConnectedComponents,
                  iMaximumConnectedComponentVertices,
                  iMaximumConnectedComponentEdges;

            CalculateConnectedComponentMetrics(graph, out iConnectedComponents,
                                               out iSingleVertexConnectedComponents,
                                               out iMaximumConnectedComponentVertices,
                                               out iMaximumConnectedComponentEdges);

            Nullable <Int32>  iMaximumGeodesicDistance;
            Nullable <Double> dAverageGeodesicDistance;

            if (backgroundWorker != null)
            {
                ReportProgress(2, 3, backgroundWorker);
            }

            CalculateGeodesicDistances(graph, out iMaximumGeodesicDistance,
                                       out dAverageGeodesicDistance);

            OverallMetrics oOverallMetrics = new OverallMetrics(
                graph.Directedness,
                oDuplicateEdgeDetector.UniqueEdges,
                oDuplicateEdgeDetector.EdgesWithDuplicates,
                iSelfLoops,
                iVertices,

                CalculateGraphDensity(graph, iVertices,
                                      oDuplicateEdgeDetector.
                                      TotalEdgesAfterMergingDuplicatesNoSelfLoops),

                iConnectedComponents,
                iSingleVertexConnectedComponents,
                iMaximumConnectedComponentVertices,
                iMaximumConnectedComponentEdges,
                iMaximumGeodesicDistance,
                dAverageGeodesicDistance
                );

            graphMetrics = oOverallMetrics;

            return(true);
        }