Ejemplo n.º 1
0
        GroupByVertexAttributeOther
        (
            Microsoft.Office.Interop.Excel.Workbook workbook,
            String attributeColumnName
        )
        {
            Debug.Assert(workbook != null);
            Debug.Assert(!String.IsNullOrEmpty(attributeColumnName));

            IGraph oGraph = ReadWorkbook(workbook);

            // The key is a unique attribute value from the specified column, and
            // the value is a GroupOther object that contains a list of the
            // vertices that have that attribute value.

            Dictionary <String, GroupOther> oGroupDictionary =
                new Dictionary <String, GroupOther>();

            foreach (IVertex oVertex in oGraph.Vertices)
            {
                Object oAttributeValue;

                if (!oVertex.TryGetValue(attributeColumnName, typeof(String),
                                         out oAttributeValue))
                {
                    continue;
                }

                String sAttributeValue = (String)oAttributeValue;

                GroupOther oGroupOther;

                if (!oGroupDictionary.TryGetValue(sAttributeValue,
                                                  out oGroupOther))
                {
                    oGroupOther          = new GroupOther();
                    oGroupOther.Name     = sAttributeValue;
                    oGroupOther.Vertices = new LinkedList <IVertex>();

                    oGroupDictionary.Add(sAttributeValue, oGroupOther);
                }

                oGroupOther.Vertices.AddLast(oVertex);
            }

            // Convert the collection of groups to an array of GraphMetricColumn
            // objects, then write the array to the workbook.

            GraphMetricColumn [] aoGraphMetricColumns =
                GroupsToGraphMetricColumnsConverter.Convert <GroupOther>
                    (oGroupDictionary.Values,
                    (oGroup) => oGroup.Vertices,
                    (oGroup) => oGroup.Name,
                    false, null);

            WriteGraphMetricsToWorkbook(workbook, aoGraphMetricColumns);
        }
Ejemplo n.º 2
0
        TryCalculateGraphMetrics
        (
            IGraph graph,
            CalculateGraphMetricsContext calculateGraphMetricsContext,
            out GraphMetricColumn [] graphMetricColumns
        )
        {
            Debug.Assert(graph != null);
            Debug.Assert(calculateGraphMetricsContext != null);
            AssertValid();

            graphMetricColumns = null;

            // Partition the graph into clusters using the ClusterCalculator class
            // in the Algorithms namespace, which knows nothing about Excel.

            ICollection <Community> oCommunities;

            Algorithms.ClusterCalculator oClusterCalculator =
                new Algorithms.ClusterCalculator();

            oClusterCalculator.Algorithm = m_eAlgorithm;

            oClusterCalculator.PutNeighborlessVerticesInOneCluster =
                m_bPutNeighborlessVerticesInOneCluster;

            if (!oClusterCalculator.TryCalculateGraphMetrics(graph,
                                                             calculateGraphMetricsContext.BackgroundWorker,
                                                             out oCommunities))
            {
                // The user cancelled.

                return(false);
            }

            // Convert the collection of communities to an array of
            // GraphMetricColumn objects.

            graphMetricColumns =
                GroupsToGraphMetricColumnsConverter.Convert <Community>(
                    oCommunities,
                    (oCommunity) => oCommunity.Vertices
                    );

            return(true);
        }
Ejemplo n.º 3
0
        TryCalculateGraphMetrics
        (
            IGraph graph,
            CalculateGraphMetricsContext calculateGraphMetricsContext,
            out GraphMetricColumn [] graphMetricColumns
        )
        {
            Debug.Assert(graph != null);
            Debug.Assert(calculateGraphMetricsContext != null);
            AssertValid();

            graphMetricColumns = null;

            // Partition the graph into motifs using the MotifCalculator class in
            // the Algorithms namespace, which knows nothing about Excel.

            Algorithms.MotifCalculator oMotifCalculator =
                new Algorithms.MotifCalculator();

            ICollection <Motif> oMotifs;

            if (!oMotifCalculator.TryCalculateMotifs(graph,
                                                     m_eMotifsToCalculate, m_iDConnectorMinimumAnchorVertices,
                                                     m_iDConnectorMaximumAnchorVertices,
                                                     m_iCliqueMinimumMemberVertices, m_iCliqueMaximumMemberVertices,
                                                     calculateGraphMetricsContext.BackgroundWorker, out oMotifs))
            {
                // The user cancelled.

                return(false);
            }

            // Convert the collection of motifs to an array of GraphMetricColumn
            // objects.

            graphMetricColumns =
                GroupsToGraphMetricColumnsConverter.Convert <Motif>(
                    oMotifs,
                    (oMotif) => oMotif.VerticesInMotif,
                    (oMotif) => MotifToGroupName(oMotif),
                    true,
                    (oMotif) => oMotif.CollapsedAttributes
                    );

            return(true);
        }
Ejemplo n.º 4
0
        TryCalculateGraphMetrics
        (
            IGraph graph,
            CalculateGraphMetricsContext calculateGraphMetricsContext,
            out GraphMetricColumn [] graphMetricColumns
        )
        {
            Debug.Assert(graph != null);
            Debug.Assert(calculateGraphMetricsContext != null);
            AssertValid();

            graphMetricColumns = null;

            // Partition the graph into strongly connected components using the
            // ConnectedComponentCalculator class in the Algorithms namespace,
            // which knows nothing about Excel.
            //
            // Note that ConnectedComponentCalculator does its work synchronously.

            Algorithms.ConnectedComponentCalculator oConnectedComponentCalculator =
                new Algorithms.ConnectedComponentCalculator();

            IList <LinkedList <IVertex> > oComponents =
                oConnectedComponentCalculator.CalculateStronglyConnectedComponents(
                    graph, false);

            // Convert the collection of components to an array of
            // GraphMetricColumn objects.

            graphMetricColumns =
                GroupsToGraphMetricColumnsConverter.Convert <LinkedList <IVertex> >(
                    oComponents,
                    (oComponent) => oComponent
                    );

            return(true);
        }
Ejemplo n.º 5
0
        GroupByVertexAttributeGeneric <T>
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            String sAttributeColumnName,
            IEnumerable <T> oMinimumValues,
            T oMinimumValueForType,
            StringToTypeConverter <T> oStringToTypeConverter,
            TypeAdjuster <T> oTypeAdjuster
        )
            where T : IComparable <T>
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(!String.IsNullOrEmpty(sAttributeColumnName));
            Debug.Assert(oMinimumValues != null);

            IGraph oGraph = ReadWorkbook(oWorkbook);

            List <T> oMinimumValueList = new List <T>(oMinimumValues);

            // Add a group that will hold vertices whose values are less than the
            // first minimum value in oMinimumValueList.  That way, every vertex
            // will end up in a group.

            oMinimumValueList.Insert(0, oMinimumValueForType);

            // For each group whose minimum value is stored in oMinimumValueList,
            // there is one LinkedList of vertices in oGroupList.

            Int32 iGroups = oMinimumValueList.Count;

            LinkedList <IVertex> [] oGroupList = new LinkedList <IVertex> [iGroups];

            for (Int32 i = 0; i < iGroups; i++)
            {
                oMinimumValueList[i] = oTypeAdjuster(oMinimumValueList[i]);
                oGroupList[i]        = new LinkedList <IVertex>();
            }

            foreach (IVertex oVertex in oGraph.Vertices)
            {
                Object oAttributeValue;
                T      tAttributeValue;

                if (
                    !oVertex.TryGetValue(sAttributeColumnName, typeof(String),
                                         out oAttributeValue)
                    ||
                    !oStringToTypeConverter((String)oAttributeValue,
                                            out tAttributeValue)
                    )
                {
                    continue;
                }

                tAttributeValue = oTypeAdjuster(tAttributeValue);

                // (This search technique is simple but slow.  It should be
                // replaced with a binary search.)

                for (Int32 i = iGroups - 1; i >= 0; i--)
                {
                    if (tAttributeValue.CompareTo(oMinimumValueList[i]) >= 0)
                    {
                        oGroupList[i].AddLast(oVertex);
                        break;
                    }
                }
            }

            // Convert the list of groups to an array of GraphMetricColumn objects,
            // then write the array to the workbook.

            GraphMetricColumn [] aoGraphMetricColumns =
                GroupsToGraphMetricColumnsConverter.Convert <LinkedList <IVertex> >
                    (oGroupList, (oGroup) => oGroup);

            WriteGraphMetricsToWorkbook(oWorkbook, aoGraphMetricColumns);
        }