Smrf.NodeXL.ExcelTemplate.MatrixWorkbookImporter.CheckSymmetryOfUndirectedMatrix C# (CSharp) Method

CheckSymmetryOfUndirectedMatrix() protected method

protected CheckSymmetryOfUndirectedMatrix ( Microsoft oSourceWorksheet, Int32 iFirstEdgeWeightRowOneBased, Int32 iFirstEdgeWeightColumnOneBased, Int32 iVertices ) : void
oSourceWorksheet Microsoft
iFirstEdgeWeightRowOneBased System.Int32
iFirstEdgeWeightColumnOneBased System.Int32
iVertices System.Int32
return void
    CheckSymmetryOfUndirectedMatrix
    (
        Microsoft.Office.Interop.Excel.Worksheet oSourceWorksheet,
        Int32 iFirstEdgeWeightRowOneBased,
        Int32 iFirstEdgeWeightColumnOneBased,
        Int32 iVertices
    )
    {
        Debug.Assert(oSourceWorksheet != null);
        Debug.Assert(iFirstEdgeWeightRowOneBased >= 1);
        Debug.Assert(iFirstEdgeWeightColumnOneBased >= 1);
        Debug.Assert(iVertices > 0);

        for (Int32 i = 0; i < iVertices; i++)
        {
            // Read row i and column i.

            Object [,] oRowOfEdgeWeightValues = ExcelUtil.GetValuesInRow(
                oSourceWorksheet, iFirstEdgeWeightRowOneBased + i,
                iFirstEdgeWeightColumnOneBased, iVertices);

            Object [,] oColumnOfEdgeWeightValues =
                ExcelUtil.GetValuesInColumn(oSourceWorksheet,
                iFirstEdgeWeightRowOneBased,
                iFirstEdgeWeightColumnOneBased + i, iVertices);

            for (Int32 j = 0; j < iVertices; j++)
            {
                String sRowString = null;
                String sColumnString = null;

                if (
                    !ExcelUtil.TryGetNonEmptyStringFromCell(
                        oRowOfEdgeWeightValues, 1, j + 1, out sRowString)
                    ||
                    !ExcelUtil.TryGetNonEmptyStringFromCell(
                        oColumnOfEdgeWeightValues, j + 1, 1, out sColumnString)
                    ||
                    sRowString != sColumnString
                    )
                {
                    Int32 iBadCoordinate1 = iFirstEdgeWeightRowOneBased + i;
                    Int32 iBadCoordinate2 = iFirstEdgeWeightColumnOneBased + j;

                    OnInvalidSourceWorkbook( String.Format(

                        "The edge weights in {0} and {1} must be identical"
                        + " numbers.  (The matrix for an undirected graph must"
                        + " be symmetric.)"
                        ,
                        ExcelUtil.GetCellAddress(oSourceWorksheet,
                            iBadCoordinate1, iBadCoordinate2),

                        ExcelUtil.GetCellAddress(oSourceWorksheet,
                            iBadCoordinate2, iBadCoordinate1)
                        ),
                        oSourceWorksheet, iBadCoordinate1, iBadCoordinate2
                        );
                }
            }
        }
    }