CountDuplicateEdges
(
ListObject oEdgeTable,
Object [,] aoVertex1NameValues,
Object [,] aoVertex2NameValues,
Object [,] aoThirdColumnValues,
Boolean bGraphIsDirected
)
{
Debug.Assert(oEdgeTable != null);
Debug.Assert(aoVertex1NameValues != null);
Debug.Assert(aoVertex2NameValues != null);
AssertValid();
ListColumn oEdgeWeightColumn;
Range oEdgeWeightData;
Object [,] aoEdgeWeightValues;
if ( !ExcelTableUtil.TryGetOrAddTableColumn(oEdgeTable,
EdgeTableColumnNames.EdgeWeight, 13.7F,
null, out oEdgeWeightColumn, out oEdgeWeightData,
out aoEdgeWeightValues) )
{
throw new InvalidOperationException(
"Can't add edge weight column.");
}
// The key identifies a unique edge and the value is the sum of the
// edge weight values for all duplicate edges with the key.
Dictionary<String, Double> oEdgeWeightSums =
new Dictionary<String, Double>();
Int32 iRows = GetRowCount(aoVertex1NameValues);
// Populate the dictionary.
for (Int32 iRowOneBased = 1; iRowOneBased <= iRows; iRowOneBased++)
{
String sEdgeKey;
if ( TryGetEdgeKey(iRowOneBased, aoVertex1NameValues,
aoVertex2NameValues, aoThirdColumnValues, bGraphIsDirected,
out sEdgeKey) )
{
// Does the row already have an edge weight in the edge weight
// column?
Double dEdgeWeightForRow;
if ( !ExcelUtil.TryGetDoubleFromCell(aoEdgeWeightValues,
iRowOneBased, 1, out dEdgeWeightForRow) )
{
// No.
dEdgeWeightForRow = 1;
}
// Has a row with the same key already been found?
Double dEdgeWeightSum;
if ( !oEdgeWeightSums.TryGetValue(sEdgeKey,
out dEdgeWeightSum) )
{
// No.
dEdgeWeightSum = 0;
}
oEdgeWeightSums[sEdgeKey] = dEdgeWeightForRow + dEdgeWeightSum;
}
}
// Now fill in the edge weight cells with the dictionary values.
for (Int32 iRowOneBased = 1; iRowOneBased <= iRows; iRowOneBased++)
{
String sEdgeKey;
if ( TryGetEdgeKey(iRowOneBased, aoVertex1NameValues,
aoVertex2NameValues, aoThirdColumnValues, bGraphIsDirected,
out sEdgeKey) )
{
aoEdgeWeightValues[iRowOneBased, 1] =
oEdgeWeightSums[sEdgeKey];
}
}
oEdgeWeightData.set_Value(Missing.Value, aoEdgeWeightValues);
}