TryCalculateGraphMetricsForOneGroup ( GroupInformation oGroupInformation, CalculateGraphMetricsContext oCalculateGraphMetricsContext, out OverallMetrics oOverallMetrics ) { Debug.Assert(oGroupInformation != null); Debug.Assert(oGroupInformation.Vertices != null); Debug.Assert(oGroupInformation.Vertices.Count > 0); Debug.Assert(oCalculateGraphMetricsContext != null); AssertValid(); oOverallMetrics = null; ICollection <IVertex> oVertices = oGroupInformation.Vertices; // Create a new graph from the vertices in the group and the edges that // connect them. IGraph oNewGraph = SubgraphCalculator.GetSubgraphAsNewGraph(oVertices); // Calculate the overall metrics for the new graph using the // OverallMetricCalculator class in the Algorithms namespace, which // knows nothing about Excel. return((new Algorithms.OverallMetricCalculator()). TryCalculateGraphMetrics(oNewGraph, oCalculateGraphMetricsContext.BackgroundWorker, out oOverallMetrics)); }
TestGetSubgraphAsNewGraph9() { // Complete graph, include two vertices. foreach (Boolean bDirected in TestGraphUtil.AllBoolean) { CreateGraph(bDirected); Dictionary <String, IVertex> oVertexDictionary = AddVertices( "A", "B", "C", "D" ); AddEdgesForCompleteGraph(oVertexDictionary); IGraph oNewGraph = SubgraphCalculator.GetSubgraphAsNewGraph( new IVertex[] { oVertexDictionary["A"], oVertexDictionary["B"], }); CheckVertices(oNewGraph, "A", "B"); CheckEdges(oNewGraph, "A", "A", "A", "B", "B", "B", "B", "A" ); } }
TestGetSubgraphAsNewGraph7() { // Include two vertices, with edges that are included, undirected // graph. CreateGraph(false); Dictionary <String, IVertex> oVertexDictionary = AddVertices( "A", "B" ); AddEdges(oVertexDictionary, "A", "B", "A", "B", "B", "A", "B", "A" ); IGraph oNewGraph = SubgraphCalculator.GetSubgraphAsNewGraph( new IVertex[] { oVertexDictionary["A"], oVertexDictionary["B"] }); CheckVertices(oNewGraph, "A", "B"); CheckEdges(oNewGraph, "A", "B", "A", "B", "B", "A", "B", "A" ); }
TestGetSubgraphAsNewGraph6() { CreateGraph(true); // Inclue two vertices, with edges that are included. Dictionary <String, IVertex> oVertexDictionary = AddVertices( "A", "B" ); AddEdges(oVertexDictionary, "A", "B", "A", "B", "B", "A", "B", "A" ); IGraph oNewGraph = SubgraphCalculator.GetSubgraphAsNewGraph( new IVertex[] { oVertexDictionary["A"], oVertexDictionary["B"] }); CheckVertices(oNewGraph, "A", "B"); CheckEdges(oNewGraph, "A", "B", "A", "B", "B", "A", "B", "A" ); }
SelectSubgraphs ( NodeXLControl nodeXLControl, IEnumerable <IVertex> verticesToSelectSubgraphsFor, Decimal levels, Boolean selectConnectingEdges ) { Debug.Assert(nodeXLControl != null); Debug.Assert(verticesToSelectSubgraphsFor != null); Debug.Assert(levels >= 0); Debug.Assert(Decimal.Remainder(levels, 0.5M) == 0M); // Create HashSets for all of the vertices and edges that will be // selected. The key is the IVertex or IEdge. HashSets are used to // prevent the same vertex or edge from being selected twice. HashSet <IVertex> oAllSelectedVertices = new HashSet <IVertex>(); HashSet <IEdge> oAllSelectedEdges = new HashSet <IEdge>(); foreach (IVertex oVertexToSelectSubgraphFor in verticesToSelectSubgraphsFor) { // These are similar collections for the vertices and edges that // will be selected for this subgraph only. Dictionary <IVertex, Int32> oThisSubgraphSelectedVertices; HashSet <IEdge> oThisSubgraphSelectedEdges; SubgraphCalculator.GetSubgraph(oVertexToSelectSubgraphFor, levels, selectConnectingEdges, out oThisSubgraphSelectedVertices, out oThisSubgraphSelectedEdges); // Consolidate the subgraph's selected vertices and edges into the // "all" dictionaries. foreach (IVertex oVertex in oThisSubgraphSelectedVertices.Keys) { oAllSelectedVertices.Add(oVertex); } foreach (IEdge oEdge in oThisSubgraphSelectedEdges) { oAllSelectedEdges.Add(oEdge); } } // Replace the selection. nodeXLControl.SetSelected(oAllSelectedVertices, oAllSelectedEdges); }
TestGetSubgraphAsNewGraph() { // Include one vertex, no edges. CreateGraph(true); Dictionary <String, IVertex> oVertexDictionary = AddVertices( "A" ); IGraph oNewGraph = SubgraphCalculator.GetSubgraphAsNewGraph( new IVertex[] { oVertexDictionary["A"] }); CheckVertices(oNewGraph, "A"); CheckEdges(oNewGraph); }
TestGetSubgraphAsNewGraph3() { // Include one vertex, with self-loop edge that is included. CreateGraph(true); Dictionary <String, IVertex> oVertexDictionary = AddVertices( "A" ); AddEdges(oVertexDictionary, "A", "A"); IGraph oNewGraph = SubgraphCalculator.GetSubgraphAsNewGraph( new IVertex[] { oVertexDictionary["A"] }); CheckVertices(oNewGraph, "A"); CheckEdges(oNewGraph, "A", "A"); }
CloneVertexIntoSubgraph ( IVertex oOriginalVertex, IGraph oSubgraph, Decimal decLevels ) { Debug.Assert(oOriginalVertex != null); Debug.Assert(oSubgraph != null); Debug.Assert(decLevels >= 0); AssertValid(); // Get the original vertices and edges to clone. For the vertex // dictionary, the key is the IVertex and the value is the vertex's // level, which is the distance of the vertex from oOriginalVertex. // For the edge HashSet, the key is the IEdge. Dictionary <IVertex, Int32> oOriginalVerticesToClone; HashSet <IEdge> oOriginalEdgesToClone; SubgraphCalculator.GetSubgraph(oOriginalVertex, decLevels, true, out oOriginalVerticesToClone, out oOriginalEdgesToClone); // Clone the vertices. This dictionary maps the IDs of the original // vertices to their clones. Dictionary <Int32, IVertex> oOriginalToSubgraphVertexMapper = new Dictionary <Int32, IVertex>(); IVertexCollection oSubgraphVertices = oSubgraph.Vertices; foreach (IVertex oOriginalVertexToClone in oOriginalVerticesToClone.Keys) { IVertex oSubgraphVertex = oOriginalVertexToClone.Clone(false, false); oSubgraphVertices.Add(oSubgraphVertex); oOriginalToSubgraphVertexMapper.Add(oOriginalVertexToClone.ID, oSubgraphVertex); } // This dictionary is no longer needed. oOriginalVerticesToClone.Clear(); oOriginalVerticesToClone = null; // Clone the edges. IEdgeCollection oSubgraphEdges = oSubgraph.Edges; foreach (IEdge oOriginalEdgeToClone in oOriginalEdgesToClone) { IVertex [] aoOriginalVertices = oOriginalEdgeToClone.Vertices; IVertex oSubgraphVertex1 = oOriginalToSubgraphVertexMapper[aoOriginalVertices[0].ID]; IVertex oSubgraphVertex2 = oOriginalToSubgraphVertexMapper[aoOriginalVertices[1].ID]; oSubgraphEdges.Add(oSubgraphVertex1, oSubgraphVertex2, oOriginalEdgeToClone.IsDirected); } Debug.Assert(oOriginalToSubgraphVertexMapper.ContainsKey( oOriginalVertex.ID)); return(oOriginalToSubgraphVertexMapper[oOriginalVertex.ID]); }