Calculates the overall metrics for the graph.
See Algorithms.OverallMetricCalculator for details on how overall metrics are calculated.
Inheritance: GraphMetricCalculatorBase2
        TryCalculateGraphMetrics
        (
            IGraph graph,
            CalculateGraphMetricsContext calculateGraphMetricsContext,
            out GraphMetricColumn [] graphMetricColumns
        )
        {
            Debug.Assert(graph != null);
            Debug.Assert(calculateGraphMetricsContext != null);
            AssertValid();

            graphMetricColumns = new GraphMetricColumn[0];

            // Attempt to retrieve the group information the WorkbookReader object
            // may have stored as metadata on the graph.

            GroupInfo [] aoGroups;

            if (
                !calculateGraphMetricsContext.ShouldCalculateGraphMetrics(
                    GraphMetrics.GroupMetrics)
                ||
                !GroupUtil.TryGetGroups(graph, out aoGroups)
                )
            {
                return(true);
            }

            // The following lists correspond to group worksheet columns.

            List <GraphMetricValueWithID> oVerticesGraphMetricValues =
                new List <GraphMetricValueWithID>();

            List <GraphMetricValueWithID> oUniqueEdgesGraphMetricValues =
                new List <GraphMetricValueWithID>();

            List <GraphMetricValueWithID> oEdgesWithDuplicatesGraphMetricValues =
                new List <GraphMetricValueWithID>();

            List <GraphMetricValueWithID> oTotalEdgesGraphMetricValues =
                new List <GraphMetricValueWithID>();

            List <GraphMetricValueWithID> oSelfLoopsGraphMetricValues =
                new List <GraphMetricValueWithID>();

            List <GraphMetricValueWithID>
            oReciprocatedVertexPairRatioGraphMetricValues =
                new List <GraphMetricValueWithID>();

            List <GraphMetricValueWithID> oReciprocatedEdgeRatioGraphMetricValues =
                new List <GraphMetricValueWithID>();

            List <GraphMetricValueWithID> oConnectedComponentsGraphMetricValues =
                new List <GraphMetricValueWithID>();

            List <GraphMetricValueWithID>
            oSingleVertexConnectedComponentsGraphMetricValues =
                new List <GraphMetricValueWithID>();

            List <GraphMetricValueWithID>
            oMaximumConnectedComponentVerticesGraphMetricValues =
                new List <GraphMetricValueWithID>();

            List <GraphMetricValueWithID>
            oMaximumConnectedComponentEdgesGraphMetricValues =
                new List <GraphMetricValueWithID>();

            List <GraphMetricValueWithID> oMaximumGeodesicDistanceGraphMetricValues =
                new List <GraphMetricValueWithID>();

            List <GraphMetricValueWithID> oAverageGeodesicDistanceGraphMetricValues =
                new List <GraphMetricValueWithID>();

            List <GraphMetricValueWithID> oGraphDensityGraphMetricValues =
                new List <GraphMetricValueWithID>();

            foreach (ExcelTemplateGroupInfo oExcelTemplateGroupInfo in aoGroups)
            {
                ICollection <IVertex> oVertices = oExcelTemplateGroupInfo.Vertices;

                if (oVertices == null || oVertices.Count == 0 ||
                    !oExcelTemplateGroupInfo.RowID.HasValue)
                {
                    continue;
                }

                OverallMetrics oOverallMetrics;

                if (!TryCalculateGraphMetricsForOneGroup(oExcelTemplateGroupInfo,
                                                         calculateGraphMetricsContext, out oOverallMetrics))
                {
                    // The user cancelled.

                    return(false);
                }

                Int32 iRowID = oExcelTemplateGroupInfo.RowID.Value;

                oVerticesGraphMetricValues.Add(new GraphMetricValueWithID(
                                                   iRowID, oOverallMetrics.Vertices));

                oUniqueEdgesGraphMetricValues.Add(new GraphMetricValueWithID(
                                                      iRowID, oOverallMetrics.UniqueEdges));

                oEdgesWithDuplicatesGraphMetricValues.Add(
                    new GraphMetricValueWithID(iRowID,
                                               oOverallMetrics.EdgesWithDuplicates));

                oTotalEdgesGraphMetricValues.Add(new GraphMetricValueWithID(iRowID,
                                                                            oOverallMetrics.TotalEdges));

                oSelfLoopsGraphMetricValues.Add(new GraphMetricValueWithID(iRowID,
                                                                           oOverallMetrics.SelfLoops));

                oReciprocatedVertexPairRatioGraphMetricValues.Add(
                    new GraphMetricValueWithID(iRowID,
                                               OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                                                   oOverallMetrics.ReciprocatedVertexPairRatio)));

                oReciprocatedEdgeRatioGraphMetricValues.Add(
                    new GraphMetricValueWithID(iRowID,
                                               OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                                                   oOverallMetrics.ReciprocatedEdgeRatio)));

                oConnectedComponentsGraphMetricValues.Add(
                    new GraphMetricValueWithID(iRowID,
                                               oOverallMetrics.ConnectedComponents));

                oSingleVertexConnectedComponentsGraphMetricValues.Add(
                    new GraphMetricValueWithID(iRowID,
                                               oOverallMetrics.SingleVertexConnectedComponents));

                oMaximumConnectedComponentVerticesGraphMetricValues.Add(
                    new GraphMetricValueWithID(iRowID,
                                               oOverallMetrics.MaximumConnectedComponentVertices));

                oMaximumConnectedComponentEdgesGraphMetricValues.Add(
                    new GraphMetricValueWithID(iRowID,
                                               oOverallMetrics.MaximumConnectedComponentEdges));

                oMaximumGeodesicDistanceGraphMetricValues.Add(
                    new GraphMetricValueWithID(iRowID,
                                               OverallMetricCalculator2.NullableToGraphMetricValue <Int32>(
                                                   oOverallMetrics.MaximumGeodesicDistance)));

                oAverageGeodesicDistanceGraphMetricValues.Add(
                    new GraphMetricValueWithID(iRowID,
                                               OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                                                   oOverallMetrics.AverageGeodesicDistance)));

                oGraphDensityGraphMetricValues.Add(
                    new GraphMetricValueWithID(iRowID,
                                               OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                                                   oOverallMetrics.GraphDensity)));
            }

            graphMetricColumns = new GraphMetricColumn [] {
                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.Vertices,
                    Int32NumericFormat,
                    oVerticesGraphMetricValues),

                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.UniqueEdges,
                    Int32NumericFormat,
                    oUniqueEdgesGraphMetricValues),

                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.EdgesWithDuplicates,
                    Int32NumericFormat,
                    oEdgesWithDuplicatesGraphMetricValues),

                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.TotalEdges,
                    Int32NumericFormat,
                    oTotalEdgesGraphMetricValues),

                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.SelfLoops,
                    Int32NumericFormat,
                    oSelfLoopsGraphMetricValues),

                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.ReciprocatedVertexPairRatio,
                    DoubleNumericFormat,
                    oReciprocatedVertexPairRatioGraphMetricValues),

                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.ReciprocatedEdgeRatio,
                    DoubleNumericFormat,
                    oReciprocatedEdgeRatioGraphMetricValues),

                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.ConnectedComponents,
                    Int32NumericFormat, oConnectedComponentsGraphMetricValues),

                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.SingleVertexConnectedComponents,
                    Int32NumericFormat,
                    oSingleVertexConnectedComponentsGraphMetricValues),

                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.MaximumConnectedComponentVertices,
                    Int32NumericFormat,
                    oMaximumConnectedComponentVerticesGraphMetricValues),

                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.MaximumConnectedComponentEdges,
                    Int32NumericFormat,
                    oMaximumConnectedComponentEdgesGraphMetricValues),

                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.MaximumGeodesicDistance,
                    Int32NumericFormat,
                    oMaximumGeodesicDistanceGraphMetricValues),

                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.AverageGeodesicDistance,
                    DoubleNumericFormat,
                    oAverageGeodesicDistanceGraphMetricValues),

                CreateGraphMetricColumnWithID(
                    GroupTableColumnNames.GraphDensity,
                    DoubleNumericFormat,
                    oGraphDensityGraphMetricValues),
            };

            return(true);
        }
        WriteOverallMetricsToNewWorkbook
        (
            Microsoft.Office.Interop.Excel.Application oApplicationForNewWorkbook,
            IList <OverallMetricsInfo> oOverallMetricsInfos
        )
        {
            Debug.Assert(oApplicationForNewWorkbook != null);
            Debug.Assert(oOverallMetricsInfos != null);
            AssertValid();

            Workbook oNewWorkbook =
                oApplicationForNewWorkbook.Workbooks.Add(Missing.Value);


            Int32 iOverallMetricsInfos = oOverallMetricsInfos.Count;

            // There are 16 overall metrics, plus one extra column for the file
            // name.

            const Int32 Columns = 1 + 16;

            // There is one extra row for the headers.

            Object [,] aoCellValues =
                ExcelUtil.Get2DArray <Object>(1 + iOverallMetricsInfos, Columns);

            String [] asColumnHeaders =
            {
                "File Name",
                OverallMetricNames.Directedness,
                OverallMetricNames.Vertices,
                OverallMetricNames.UniqueEdges,
                OverallMetricNames.EdgesWithDuplicates,
                OverallMetricNames.TotalEdges,
                OverallMetricNames.SelfLoops,
                OverallMetricNames.ReciprocatedVertexPairRatio,
                OverallMetricNames.ReciprocatedEdgeRatio,
                OverallMetricNames.ConnectedComponents,
                OverallMetricNames.SingleVertexConnectedComponents,
                OverallMetricNames.MaximumConnectedComponentVertices,
                OverallMetricNames.MaximumConnectedComponentEdges,
                OverallMetricNames.MaximumGeodesicDistance,
                OverallMetricNames.AverageGeodesicDistance,
                OverallMetricNames.GraphDensity,
                OverallMetricNames.Modularity,
            };

            Debug.Assert(asColumnHeaders.Length == Columns);

            for (Int32 iColumn = 0; iColumn < Columns; iColumn++)
            {
                aoCellValues[1, iColumn + 1] = asColumnHeaders[iColumn];
            }

            for (Int32 i = 0; i < iOverallMetricsInfos; i++)
            {
                OverallMetricsInfo oOverallMetricsInfo = oOverallMetricsInfos[i];

                OverallMetrics oOverallMetrics =
                    oOverallMetricsInfo.OverallMetrics;

                Object [] aoColumnValues =
                {
                    oOverallMetricsInfo.NodeXLWorkbookFileName,
                    oOverallMetrics.Directedness.ToString(),
                    oOverallMetrics.Vertices,
                    oOverallMetrics.UniqueEdges,
                    oOverallMetrics.EdgesWithDuplicates,
                    oOverallMetrics.TotalEdges,
                    oOverallMetrics.SelfLoops,

                    OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                        oOverallMetrics.ReciprocatedVertexPairRatio),

                    OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                        oOverallMetrics.ReciprocatedEdgeRatio),

                    oOverallMetrics.ConnectedComponents,
                    oOverallMetrics.SingleVertexConnectedComponents,
                    oOverallMetrics.MaximumConnectedComponentVertices,
                    oOverallMetrics.MaximumConnectedComponentEdges,

                    OverallMetricCalculator2.NullableToGraphMetricValue <Int32>(
                        oOverallMetrics.MaximumGeodesicDistance),

                    OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                        oOverallMetrics.AverageGeodesicDistance),

                    OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                        oOverallMetrics.GraphDensity),

                    OverallMetricCalculator2.NullableToGraphMetricValue <Double>(
                        oOverallMetrics.Modularity),
                };

                Debug.Assert(aoColumnValues.Length == Columns);

                for (Int32 iColumn = 0; iColumn < Columns; iColumn++)
                {
                    aoCellValues[i + 2, iColumn + 1] = aoColumnValues[iColumn];
                }
            }

            Worksheet oNewWorksheet = (Worksheet)oNewWorkbook.Worksheets[1];

            // Insert the overall metrics into a table.

            Range oTableRange = ExcelUtil.SetRangeValues(
                (Range)oNewWorksheet.Cells[1, 1], aoCellValues);

            ExcelTableUtil.AddTable(oNewWorksheet, oTableRange, null, null);
        }