public void SetUp() { m_oConnectedComponentCalculator = new ConnectedComponentCalculator(); m_oGraph = new Graph(); m_oVertices = m_oGraph.Vertices; m_oEdges = m_oGraph.Edges; }
TestSortBad() { // null collection. try { IVertexCollection oVertexCollection = null; m_oByMetadataVertexSorter.Sort(oVertexCollection); } catch (ArgumentNullException oArgumentNullException) { Assert.AreEqual( "Microsoft.NodeXL.Core.ByMetadataVertexSorter`1[[System.Int32," + " mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken" + "=b77a5c561934e089]].Sort: " + "vertices argument can't be null.\r\n" + "Parameter name: vertices" , oArgumentNullException.Message ); throw oArgumentNullException; } }
// Kiem tra 1 diem co nam trong da giac khong public static bool CheckInnerPoint(IVertexCollection points, IVertex point) { IVertex currentPoint = point; //Ray-cast algorithm is here onward int k, j = points.Count - 1; var oddNodes = false; //to check whether number of intersections is odd for (k = 0; k < points.Count; k++) { //fetch adjucent points of the polygon IVertex polyK = points[k]; IVertex polyJ = points[j]; //check the intersections if (((polyK.Y > currentPoint.Y) != (polyJ.Y > currentPoint.Y)) && (currentPoint.X < (polyJ.X - polyK.X) * (currentPoint.Y - polyK.Y) / (polyJ.Y - polyK.Y) + polyK.X)) { oddNodes = !oddNodes; //switch between odd and even } j = k; } //if odd number of intersections if (oddNodes) { //mouse point is inside the polygon return(true); } //if even number of intersections return(false); }
private void add_edges(DataRowCollection edge_rows, IVertexCollection oVertices, IEdgeCollection oEdges) { String from; String to; foreach (DataRow row in edge_rows) { //Notice: "EdgeFromid" and "EdgeToid" should be edited from = row["FromID"].ToString(); to = row["ToID"].ToString(); // Add an edge IVertex oFrom = null; IVertex oTo = null; foreach (IVertex oVertex in oVertices) { if (oVertex.Tag.ToString() == from) { oFrom = oVertex; } if (oVertex.Tag.ToString() == to) { oTo = oVertex; } } IEdge oEdge1 = oEdges.Add(oFrom, oTo, true); } }
RestoreLayout() { AssertValid(); IVertexCollection oVertices = m_oGraph.Vertices; Int32 iVertices = oVertices.Count; Debug.Assert(m_aoVertexLocations != null); Debug.Assert(m_aoVertexLocations.Length == iVertices); Int32 iVertex = 0; foreach (IVertex oVertex in oVertices) { oVertex.Location = m_aoVertexLocations[iVertex]; iVertex++; } IList <GroupInfo> oGroupsToDraw; if (TryGetGroupsToDraw(out oGroupsToDraw)) { Int32 iGroupsToDraw = oGroupsToDraw.Count; Debug.Assert(m_aoGroupRectangles != null); Debug.Assert(m_aoGroupRectangles.Length == iGroupsToDraw); for (Int32 i = 0; i < iGroupsToDraw; i++) { oGroupsToDraw[i].Rectangle = m_aoGroupRectangles[i]; } } }
AddVertices ( IGraph oGraph, Int32 iVerticesToAdd ) { Debug.Assert(oGraph != null); Debug.Assert(iVerticesToAdd >= 0); IVertex[] aoVertices = new IVertex[iVerticesToAdd]; IVertexCollection oVertexCollection = oGraph.Vertices; // Add the vertices. for (Int32 i = 0; i < iVerticesToAdd; i++) { IVertex oVertex = aoVertices[i] = new Vertex(); oVertex.Name = oVertex.ID.ToString(); oVertexCollection.Add(oVertex); } return(aoVertices); }
//************************************************************************* // Constructor: ConnectedComponentCalculatorTest() // /// <summary> /// Initializes a new instance of the <see /// cref="ConnectedComponentCalculatorTest" /> class. /// </summary> //************************************************************************* public ConnectedComponentCalculatorTest() { m_oConnectedComponentCalculator = null; m_oGraph = null; m_oVertices = null; m_oEdges = null; }
GetGraphBoundingRectangle ( IGraph graph ) { Debug.Assert(graph != null); IVertexCollection oVertices = graph.Vertices; if (oVertices.Count == 0) { return(RectangleF.Empty); } Single fLeft = Single.MaxValue; Single fRight = Single.MinValue; Single fTop = Single.MaxValue; Single fBottom = Single.MinValue; foreach (IVertex oVertex in oVertices) { PointF oLocation = oVertex.Location; Single fX = oLocation.X; Single fY = oLocation.Y; fLeft = Math.Min(fLeft, fX); fRight = Math.Max(fRight, fX); fTop = Math.Min(fTop, fY); fBottom = Math.Max(fBottom, fY); } return(RectangleF.FromLTRB(fLeft, fTop, fRight, fBottom)); }
// Kiem tra 1 diem co nam trong da giac khong public static bool CheckInnerPoint(IVertexCollection points, IVertex point) { IVertex currentPoint = point; //Ray-cast algorithm is here onward int k, j = points.Count - 1; var oddNodes = false; //to check whether number of intersections is odd for (k = 0; k < points.Count; k++) { //fetch adjucent points of the polygon IVertex polyK = points[k]; IVertex polyJ = points[j]; //check the intersections if (((polyK.Y > currentPoint.Y) != (polyJ.Y > currentPoint.Y)) && (currentPoint.X < (polyJ.X - polyK.X) * (currentPoint.Y - polyK.Y) / (polyJ.Y - polyK.Y) + polyK.X)) oddNodes = !oddNodes; //switch between odd and even j = k; } //if odd number of intersections if (oddNodes) { //mouse point is inside the polygon return true; } //if even number of intersections return false; }
TestSort() { // Ascending sort using default comparer, which sorts by ID. const Int32 Vertices = 100; IGraph oGraph = new Graph(); IVertex [] aoUnsortedVertices = TestGraphUtil.AddVertices(oGraph, Vertices); IVertexCollection oVertexCollection = oGraph.Vertices; ICollection <IVertex> oSortedVertices = m_oByDelegateVertexSorter.Sort(oVertexCollection); Assert.AreEqual(Vertices, oSortedVertices.Count); Int32 iPreviousID = -1; foreach (IVertex oSortedVertex in oSortedVertices) { Int32 iID = oSortedVertex.ID; if (iPreviousID != -1) { Assert.AreEqual(iPreviousID + 1, iID); } iPreviousID = iID; } }
/// <summary> /// ctor() /// </summary> /// <param name="cgVertex">Vertex in the condensation graph</param> /// <param name="stronglyConnectedVertices">strongly connected /// components /// in the original graph which are represented by the condensation /// graph node</param> public CondensationGraphVertexEventArgs( IVertex cgVertex, IVertexCollection stronglyConnectedVertices) { this.vCG = cgVertex; this.stronglyConnectedVertices = stronglyConnectedVertices; }
/// <summary> /// Creates a predicate that checks if vertices are in /// <paramref name="list"/> /// </summary> /// <param name="list">list of vertices</param> /// <exception cref="ArgumentNullException">list is a null reference</exception> public InCollectionVertexPredicate(IVertexCollection list) { if (list == null) { throw new ArgumentNullException("list"); } this.list = list; }
TryCalculateFanMotifs ( IGraph oGraph, BackgroundWorker oBackgroundWorker, out ICollection <Motif> oMotifs ) { Debug.Assert(oGraph != null); oMotifs = null; LinkedList <Motif> oFanMotifs = new LinkedList <Motif>(); LinkedList <IVertex> oLeaves = new LinkedList <IVertex>(); IVertexCollection oVertices = oGraph.Vertices; Int32 iVertices = oVertices.Count; Int32 iCalculationsSoFar = 0; foreach (IVertex oVertex in oVertices) { if (!ReportProgressIfNecessary(iCalculationsSoFar, iVertices, oBackgroundWorker)) { return(false); } ICollection <IVertex> oAdjacentVertices = oVertex.AdjacentVertices; if (oAdjacentVertices.Count >= 2) { foreach (IVertex oAdjacentVertex in oAdjacentVertices) { if (oAdjacentVertex.AdjacentVertices.Count == 1) { oLeaves.AddLast(oAdjacentVertex); } } if (oLeaves.Count >= 2) { oFanMotifs.AddLast( new FanMotif(oVertex, oLeaves.ToArray())); } oLeaves.Clear(); } iCalculationsSoFar++; } // Set the ArcScale property on each FanMotif object. SetFanMotifArcScale(oFanMotifs); oMotifs = oFanMotifs; return(true); }
TryCalculateDConnectorMotifs ( IGraph oGraph, Int32 iDMinimum, Int32 iDMaximum, BackgroundWorker oBackgroundWorker, out ICollection <Motif> oMotifs ) { Debug.Assert(oGraph != null); oMotifs = null; IVertexCollection oVertices = oGraph.Vertices; Int32 iVertices = oVertices.Count; Int32 iCalculationsSoFar = 0; // The key is an ordered combination of the vertex IDs of the potential // motif's D anchor vertices, and the value is the corresponding // potential DConnectorMotif object. Dictionary <string, DConnectorMotif> oPotentialDConnectorMotifs = new Dictionary <string, DConnectorMotif>(); foreach (IVertex oPotentialSpanVertex in oVertices) { if (!ReportProgressIfNecessary(iCalculationsSoFar, iVertices, oBackgroundWorker)) { return(false); } // Get only the non-self-loop adjacent vertices ICollection <IVertex> oPotentialAnchorVertices = oPotentialSpanVertex.AdjacentVertices .Where <IVertex>(adjVertex => adjVertex != oPotentialSpanVertex).ToList <IVertex>(); if (DVerticesMightBeAnchors(oPotentialAnchorVertices, iDMinimum, iDMaximum)) { AddSpanVertexToPotentialDConnectorMotifs( oPotentialSpanVertex, oPotentialAnchorVertices, oPotentialDConnectorMotifs); } iCalculationsSoFar++; } // Filter the potential D-connector motifs and add the real ones to // the collection of motifs. oMotifs = FilterDConnectorMotifs(oPotentialDConnectorMotifs); // Set the SpanScale property on each DConnectorMotif object. SetDConnectorMotifSpanScale(oMotifs); return(true); }
public IndexBuffer(ICollection <uint> idx, IVertexCollection vtx = null) : this(idx.Count, vtx) { int i = 0; foreach (uint j in idx) { this[i++] = j; } }
CreateGraph ( IVertex [] aoVertices, List <PajekEdgeData> oUndirectedEdgeData, List <PajekEdgeData> oDirectedEdgeData ) { Debug.Assert(oUndirectedEdgeData != null); Debug.Assert(oDirectedEdgeData != null); GraphDirectedness eDirectedness = GraphDirectedness.Undirected; Int32 iVertices = 0; Int32 iUndirectedEdges = oUndirectedEdgeData.Count; Int32 iDirectedEdges = oDirectedEdgeData.Count; if (iUndirectedEdges > 0 && iDirectedEdges > 0) { eDirectedness = GraphDirectedness.Mixed; } else if (iDirectedEdges > 0) { eDirectedness = GraphDirectedness.Directed; } IGraph oGraph = new Graph(eDirectedness); IVertexCollection oVertices = oGraph.Vertices; IEdgeCollection oEdges = oGraph.Edges; if (aoVertices != null) { // Populate the vertex collection. foreach (IVertex oVertex in aoVertices) { oVertices.Add(oVertex); } iVertices = aoVertices.Length; } // Populate the edges collection. foreach (PajekEdgeData oEdgeData in oUndirectedEdgeData) { AddEdgeToGraph(oEdgeData, oEdges, aoVertices, false); } foreach (PajekEdgeData oEdgeData in oDirectedEdgeData) { AddEdgeToGraph(oEdgeData, oEdges, aoVertices, true); } return(oGraph); }
TryCalculateGraphMetrics ( IGraph graph, BackgroundWorker backgroundWorker, out Dictionary <Int32, Nullable <Double> > graphMetrics ) { Debug.Assert(graph != null); AssertValid(); IVertexCollection oVertices = graph.Vertices; Int32 iVertices = oVertices.Count; Int32 iCalculations = 0; // The key is an IVertex.ID and the value is the vertex's reciprocated // vertex pair ratio, or null. Dictionary <Int32, Nullable <Double> > oReciprocatedVertexPairRatios = new Dictionary <Int32, Nullable <Double> >(oVertices.Count); graphMetrics = oReciprocatedVertexPairRatios; if (graph.Directedness == GraphDirectedness.Directed) { // Contains a key for each of the graph's unique edges. The key is // the edge's ordered vertex ID pair. HashSet <Int64> oVertexIDPairs = GetVertexIDPairs(graph); foreach (IVertex oVertex in oVertices) { // Check for cancellation and report progress every // VerticesPerProgressReport calculations. if ( (iCalculations % VerticesPerProgressReport == 0) && !ReportProgressAndCheckCancellationPending( iCalculations, iVertices, backgroundWorker) ) { return(false); } oReciprocatedVertexPairRatios.Add(oVertex.ID, CalculateReciprocatedVertexPairRatio( oVertex, oVertexIDPairs)); iCalculations++; } } return(true); }
//************************************************************************* // Constructor: VertexCollectionTest() // /// <summary> /// Initializes a new instance of the <see cref="VertexCollectionTest" /> /// class. /// </summary> //************************************************************************* public VertexCollectionTest() { m_oVertexCollection = null; m_oGraph = null; m_bVertexAdded = false; m_oAddedVertex = null; m_bVertexRemoved = false; m_oRemovedVertex = null; }
TestSort4() { // Descending sort on Double. ByMetadataVertexSorter <Double> oByMetadataVertexSorter = new ByMetadataVertexSorter <Double>(SortKey); const Int32 Vertices = 100; IGraph oGraph = new Graph(); IVertex [] aoUnsortedVertices = TestGraphUtil.AddVertices(oGraph, Vertices); IVertexCollection oVertexCollection = oGraph.Vertices; Int32 i; for (i = 0; i < Vertices; i++) { aoUnsortedVertices[i].SetValue(SortKey, (Double)(Vertices - i)); } oByMetadataVertexSorter.SortAscending = false; for (i = 0; i < Vertices; i++) { aoUnsortedVertices[i].SetValue(SortKey, (Double)(Vertices - i)); } ICollection <IVertex> oSortedVertices = oByMetadataVertexSorter.Sort(oVertexCollection); Assert.AreEqual(Vertices, oSortedVertices.Count); i = 0; foreach (IVertex oSortedVertex in oSortedVertices) { Assert.AreEqual( (Double)(Vertices - i), (Double)oSortedVertex.GetRequiredValue( SortKey, typeof(Double)) ); i++; } }
ParseVertices ( IGraph oGraph, XmlNode oGraphXmlNode, XmlNamespaceManager oXmlNamespaceManager, Dictionary <String, GraphMLAttribute> oGraphMLAttributeDictionary ) { Debug.Assert(oGraph != null); Debug.Assert(oGraphXmlNode != null); Debug.Assert(oXmlNamespaceManager != null); Debug.Assert(oGraphMLAttributeDictionary != null); AssertValid(); IVertexCollection oVertices = oGraph.Vertices; // The key is the id attribute of the "node" XML node, and the value is // the corresponding IVertex. Dictionary <String, IVertex> oVertexDictionary = new Dictionary <String, IVertex>(); foreach (XmlNode oNodeXmlNode in oGraphXmlNode.SelectNodes( GraphMLPrefix + ":node", oXmlNamespaceManager)) { String sID = XmlUtil2.SelectRequiredSingleNodeAsString( oNodeXmlNode, "@id", null); IVertex oVertex = oVertices.Add(); oVertex.Name = sID; try { oVertexDictionary.Add(sID, oVertex); } catch (ArgumentException) { throw new XmlException( "The id \"" + sID + "\" exists for two \"node\" XML nodes." + " Node id values must be unique." ); } ParseGraphMLAttributeValues(oNodeXmlNode, oXmlNamespaceManager, oVertex, true, oGraphMLAttributeDictionary); } return(oVertexDictionary); }
TestGetVertexIDPair6() { // Undirected graph, useDirectedness = false. IGraph oUndirectedGraph = new Graph(GraphDirectedness.Undirected); IVertexCollection oUndirectedVertices = oUndirectedGraph.Vertices; IVertex oUndirectedVertexA = oUndirectedVertices.Add(); IVertex oUndirectedVertexB = oUndirectedVertices.Add(); IVertex oUndirectedVertexC = oUndirectedVertices.Add(); IVertex oUndirectedVertexD = oUndirectedVertices.Add(); IEdgeCollection oEdges = oUndirectedGraph.Edges; IEdge oEdge1 = oEdges.Add(oUndirectedVertexA, oUndirectedVertexB, false); IEdge oEdge2 = oEdges.Add(oUndirectedVertexA, oUndirectedVertexB, false); IEdge oEdge3 = oEdges.Add(oUndirectedVertexB, oUndirectedVertexA, false); IEdge oEdge4 = oEdges.Add(oUndirectedVertexA, oUndirectedVertexC, false); Int64 i64VertexIDPair1 = EdgeUtil.GetVertexIDPair(oEdge1, false); Int64 i64VertexIDPair2 = EdgeUtil.GetVertexIDPair(oEdge2, false); Int64 i64VertexIDPair3 = EdgeUtil.GetVertexIDPair(oEdge3, false); Int64 i64VertexIDPair4 = EdgeUtil.GetVertexIDPair(oEdge4, false); // Make sure that the left-shift worked. Assert.IsTrue(i64VertexIDPair1 > Int32.MaxValue); Assert.IsTrue(i64VertexIDPair2 > Int32.MaxValue); Assert.IsTrue(i64VertexIDPair3 > Int32.MaxValue); Assert.IsTrue(i64VertexIDPair4 > Int32.MaxValue); Assert.AreEqual(i64VertexIDPair1, i64VertexIDPair2); Assert.AreEqual(i64VertexIDPair1, i64VertexIDPair3); Assert.AreNotEqual(i64VertexIDPair1, i64VertexIDPair4); Assert.AreEqual(i64VertexIDPair2, i64VertexIDPair3); Assert.AreNotEqual(i64VertexIDPair2, i64VertexIDPair4); Assert.AreNotEqual(i64VertexIDPair3, i64VertexIDPair4); }
TryCalculateGraphMetrics ( IGraph graph, BackgroundWorker backgroundWorker, out Dictionary <Int32, Double> graphMetrics ) { Debug.Assert(graph != null); AssertValid(); IVertexCollection oVertices = graph.Vertices; Int32 iVertices = oVertices.Count; Dictionary <Int32, Double> oClusteringCoefficients = new Dictionary <Int32, Double>(iVertices); graphMetrics = oClusteringCoefficients; Boolean bGraphIsDirected = (graph.Directedness == GraphDirectedness.Directed); Int32 iCalculations = 0; foreach (IVertex oVertex in oVertices) { // Check for cancellation and report progress every // VerticesPerProgressReport calculations. if (backgroundWorker != null && iCalculations % VerticesPerProgressReport == 0) { if (backgroundWorker.CancellationPending) { return(false); } ReportProgress(iCalculations, iVertices, backgroundWorker); } oClusteringCoefficients.Add(oVertex.ID, CalculateClusteringCoefficient(oVertex, bGraphIsDirected)); iCalculations++; } return(true); }
TryCalculateGraphMetrics ( IGraph graph, BackgroundWorker backgroundWorker, out Dictionary <Int32, VertexDegrees> graphMetrics ) { Debug.Assert(graph != null); AssertValid(); IVertexCollection oVertices = graph.Vertices; Int32 iVertices = oVertices.Count; Int32 iCalculations = 0; Dictionary <Int32, VertexDegrees> oVertexIDDictionary = new Dictionary <Int32, VertexDegrees>(iVertices); graphMetrics = oVertexIDDictionary; foreach (IVertex oVertex in oVertices) { // Check for cancellation and report progress every // VerticesPerProgressReport calculations. if (backgroundWorker != null && (iCalculations % VerticesPerProgressReport == 0)) { if (backgroundWorker.CancellationPending) { return(false); } ReportProgress(iCalculations, iVertices, backgroundWorker); } Int32 iInDegree, iOutDegree; CalculateVertexDegrees(oVertex, out iInDegree, out iOutDegree); oVertexIDDictionary.Add(oVertex.ID, new VertexDegrees(iInDegree, iOutDegree)); iCalculations++; } return(true); }
private void add_nodes(DataTable node_table, IVertexCollection oVertices) { DataRowCollection node_rows = node_table.Rows; DataColumnCollection node_col = node_table.Columns; foreach (DataRow row in node_rows) { //Notice: "nodename" and "nodeid" should be edited IVertex oVertexA = oVertices.Add(); oVertexA.Name = row["NodeName"].ToString(); oVertexA.Tag = row["ID"].ToString(); int i = 0; foreach(DataColumn col in node_col){ oVertexA.SetValue(col.ColumnName, row[i++]); } } }
TestSortBad() { // null collection. try { IVertexCollection oVertexCollection = null; m_oByMetadataVertexSorter.Sort(oVertexCollection); } catch (ArgumentNullException oArgumentNullException) { Assert.IsTrue(oArgumentNullException.Message.Contains( "Sort: vertices argument can't be null")); throw oArgumentNullException; } }
void AddEdgesFromStronglyConnectedComponent( IVertexCollection component ) { int sourceVertexCount = (int) System.Math.Ceiling( System.Math.Sqrt( component.Count ) ); IEnumerator componentEnumerator = component.GetEnumerator(); for ( int currentVertexIndex = 0; currentVertexIndex < sourceVertexCount; currentVertexIndex++ ) { componentEnumerator.MoveNext(); foreach( Vertex sinkVertex in component ) { _graph.AddEdge( (Vertex) componentEnumerator.Current, sinkVertex); } } }
AddLoadedVertex ( String sVertexName, IVertexCollection oVertices, Dictionary <Int32, IVertex> oVertexDictionary ) { Debug.Assert(!String.IsNullOrEmpty(sVertexName)); Debug.Assert(oVertices != null); Debug.Assert(oVertexDictionary != null); AssertValid(); IVertex oVertex = new Vertex(); oVertex.Name = sVertexName; oVertices.Add(oVertex); oVertexDictionary.Add(oVertices.Count - 1, oVertex); }
CreateVertex ( String sVertexName, IVertexCollection oVertices, Dictionary <String, IVertex> oVertexNameDictionary ) { Debug.Assert(!String.IsNullOrEmpty(sVertexName)); Debug.Assert(oVertices != null); Debug.Assert(oVertexNameDictionary != null); IVertex oVertex = oVertices.Add(); oVertex.Name = sVertexName; oVertexNameDictionary.Add(sVertexName, oVertex); return(oVertex); }
//************************************************************************* // Constructor: LayoutSaver() // /// <summary> /// Initializes a new instance of the <see cref="LayoutSaver" /> class. /// </summary> //************************************************************************* public LayoutSaver ( IGraph graph ) { Debug.Assert(graph != null); m_oGraph = graph; IVertexCollection oVertices = graph.Vertices; m_oVertexLocations = new Dictionary <Int32, PointF>(oVertices.Count); foreach (IVertex oVertex in oVertices) { m_oVertexLocations[oVertex.ID] = oVertex.Location; } AssertValid(); }
VertexNameToVertex ( String vertexName, IVertexCollection vertices, Dictionary<String, IVertex> vertexNameDictionary ) { Debug.Assert( !String.IsNullOrEmpty(vertexName) ); Debug.Assert(vertices != null); Debug.Assert(vertexNameDictionary != null); IVertex oVertex; if ( !vertexNameDictionary.TryGetValue(vertexName, out oVertex) ) { oVertex = CreateVertex(vertexName, vertices, vertexNameDictionary); } return (oVertex); }
VertexNameToVertex ( String vertexName, IVertexCollection vertices, Dictionary <String, IVertex> vertexNameDictionary ) { Debug.Assert(!String.IsNullOrEmpty(vertexName)); Debug.Assert(vertices != null); Debug.Assert(vertexNameDictionary != null); IVertex oVertex; if (!vertexNameDictionary.TryGetValue(vertexName, out oVertex)) { oVertex = CreateVertex(vertexName, vertices, vertexNameDictionary); } return(oVertex); }
internal void Condense(IVertexCollection iVertexCollection) { foreach (TypeVertex v in iVertexCollection) { if (!this.ContainedTypes.Contains(v.TypeRef)) { this.ContainedTypes.Add(v.TypeRef); } string nmspace = TypeVertex.GetNamespace(v.TypeRef); if (this.NameSpaces.ContainsKey(nmspace)) { this.NameSpaces[nmspace]++; } else { this.NameSpaces[nmspace] = 1; } } }
TestGetVertexIDPair() { // Directed graph. IGraph oDirectedGraph = new Graph(GraphDirectedness.Directed); IVertexCollection oDirectedVertices = oDirectedGraph.Vertices; IVertex oDirectedVertexA = oDirectedVertices.Add(); IVertex oDirectedVertexB = oDirectedVertices.Add(); IVertex oDirectedVertexC = oDirectedVertices.Add(); IVertex oDirectedVertexD = oDirectedVertices.Add(); IEdgeCollection oEdges = oDirectedGraph.Edges; IEdge oEdge1 = oEdges.Add(oDirectedVertexA, oDirectedVertexB, true); IEdge oEdge2 = oEdges.Add(oDirectedVertexA, oDirectedVertexB, true); IEdge oEdge3 = oEdges.Add(oDirectedVertexB, oDirectedVertexA, true); IEdge oEdge4 = oEdges.Add(oDirectedVertexA, oDirectedVertexC, true); Int64 i64VertexIDPair1 = EdgeUtil.GetVertexIDPair(oEdge1); Int64 i64VertexIDPair2 = EdgeUtil.GetVertexIDPair(oEdge2); Int64 i64VertexIDPair3 = EdgeUtil.GetVertexIDPair(oEdge3); Int64 i64VertexIDPair4 = EdgeUtil.GetVertexIDPair(oEdge4); // Make sure that the left-shift worked. Assert.IsTrue(i64VertexIDPair1 > Int32.MaxValue); Assert.IsTrue(i64VertexIDPair2 > Int32.MaxValue); Assert.IsTrue(i64VertexIDPair3 > Int32.MaxValue); Assert.IsTrue(i64VertexIDPair4 > Int32.MaxValue); Assert.AreEqual(i64VertexIDPair1, i64VertexIDPair2); Assert.AreNotEqual(i64VertexIDPair1, i64VertexIDPair3); Assert.AreNotEqual(i64VertexIDPair1, i64VertexIDPair4); Assert.AreNotEqual(i64VertexIDPair2, i64VertexIDPair3); Assert.AreNotEqual(i64VertexIDPair2, i64VertexIDPair4); Assert.AreNotEqual(i64VertexIDPair3, i64VertexIDPair4); }
TestSort2() { // Ascending sort on IVertex.Name. m_oByDelegateVertexSorter.VertexComparer = this.CompareVerticesByName; const Int32 Vertices = 100; IGraph oGraph = new Graph(); IVertex [] aoUnsortedVertices = TestGraphUtil.AddVertices(oGraph, Vertices); IVertexCollection oVertexCollection = oGraph.Vertices; Int32 i; for (i = 0; i < Vertices; i++) { aoUnsortedVertices[i].Name = (Vertices - i).ToString("D3"); } ICollection <IVertex> oSortedVertices = m_oByDelegateVertexSorter.Sort(oVertexCollection); Assert.AreEqual(Vertices, oSortedVertices.Count); i = 0; foreach (IVertex oSortedVertex in oSortedVertices) { Assert.AreEqual( (i + 1).ToString("D3"), oSortedVertex.Name ); i++; } }
VertexNameToVertex ( String sVertexName, IVertexCollection oVertices, Dictionary <String, IVertex> oVertexNameDictionary ) { Debug.Assert(!String.IsNullOrEmpty(sVertexName)); Debug.Assert(oVertices != null); Debug.Assert(oVertexNameDictionary != null); AssertValid(); IVertex oVertex; if (!oVertexNameDictionary.TryGetValue(sVertexName, out oVertex)) { oVertex = CreateVertex(sVertexName, oVertices, oVertexNameDictionary); } return(oVertex); }
TestSort2() { // Descending sort on Int32. const Int32 Vertices = 100; IGraph oGraph = new Graph(); IVertex [] aoUnsortedVertices = TestGraphUtil.AddVertices(oGraph, Vertices); IVertexCollection oVertexCollection = oGraph.Vertices; Int32 i; for (i = 0; i < Vertices; i++) { aoUnsortedVertices[i].SetValue(SortKey, Vertices - i); } m_oByMetadataVertexSorter.SortAscending = false; ICollection <IVertex> oSortedVertices = m_oByMetadataVertexSorter.Sort(oVertexCollection); Assert.AreEqual(Vertices, oSortedVertices.Count); i = 0; foreach (IVertex oSortedVertex in oSortedVertices) { Assert.AreEqual( Vertices - i, (Int32)oSortedVertex.GetRequiredValue(SortKey, typeof(Int32)) ); i++; } }
SetUp() { m_oDirectedGraph = new Graph(GraphDirectedness.Directed); IVertexCollection oDirectedVertices = m_oDirectedGraph.Vertices; m_oDirectedVertexA = oDirectedVertices.Add(); m_oDirectedVertexA.Name = "A"; m_oDirectedVertexB = oDirectedVertices.Add(); m_oDirectedVertexB.Name = "B"; m_oDirectedVertexC = oDirectedVertices.Add(); m_oDirectedVertexC.Name = "C"; m_oDirectedVertexD = oDirectedVertices.Add(); m_oDirectedVertexD.Name = "D"; m_oDirectedVertexWithNullName = oDirectedVertices.Add(); m_oDirectedVertexWithNullName.Name = null; m_oUndirectedGraph = new Graph(GraphDirectedness.Undirected); IVertexCollection oUndirectedVertices = m_oUndirectedGraph.Vertices; m_oUndirectedVertexA = oUndirectedVertices.Add(); m_oUndirectedVertexA.Name = "A"; m_oUndirectedVertexB = oUndirectedVertices.Add(); m_oUndirectedVertexB.Name = "B"; m_oUndirectedVertexC = oUndirectedVertices.Add(); m_oUndirectedVertexC.Name = "C"; m_oUndirectedVertexD = oUndirectedVertices.Add(); m_oUndirectedVertexD.Name = "D"; m_oUndirectedVertexWithNullName = oUndirectedVertices.Add(); m_oUndirectedVertexWithNullName.Name = null; }
private Face(ElementType faceType, IEnumerable <int> vertexes, IEnumerable <int> texCoords, IEnumerable <int> normals) { var vertexList = vertexes.ToList(); MeshSize = vertexList.Count(); if (faceType.HasFlag(ElementType.Vertex)) { Type = ElementType.Vertex; _collection = new VertexIndicesCollection(vertexList); } if (faceType.HasFlag(ElementType.Normal)) { Type |= ElementType.Normal; var normal = new IndicesCollection(ElementType.Normal, normals); if (_collection != null) { normal.Extend(_collection); } _collection = normal; } if (faceType.HasFlag(ElementType.TextureCoord)) { Type |= ElementType.TextureCoord; var texCoord = new IndicesCollection(ElementType.TextureCoord, texCoords); if (_collection != null) { texCoord.Extend(_collection); } _collection = texCoord; } }
protected LinkedList<Community> CreateCommunities (IVertexCollection oVertices, IDGenerator oIDGenerator) { Debug.Assert(oVertices != null); Debug.Assert(oIDGenerator != null); // This is the list of communities. Initially, there will be one // community for each of the graph's vertices. LinkedList<Community> oCommunities = new LinkedList<Community>(); // This temporary dictionary is used to map a vertex ID to a community. // The key is the IVertex.ID and the value is the corresponding // Community object. Dictionary<Int32, Community> oVertexIDDictionary = new Dictionary<Int32, Community>(oVertices.Count); // First, create a community for each of the graph's vertices. Each // community contains just the vertex. foreach (IVertex oVertex in oVertices) { Community oCommunity = new Community(); Int32 iID = oIDGenerator.GetNextID(); oCommunity.ID = iID; oCommunity.Vertices.Add(oVertex); // TODO: IVertex.AdjacentVertices includes self-loops. Should // self-loops be eliminated everywhere, including here and within // the graph's total edge count? Not sure how self-loops are // affecting the algorithm used by this class... oCommunity.Degree = oVertex.AdjacentVertices.Count; oCommunities.AddLast(oCommunity); oVertexIDDictionary.Add(oVertex.ID, oCommunity); } // Now populate each community's list of community pairs. foreach (Community oCommunity1 in oCommunities) { Debug.Assert(oCommunity1.Vertices.Count == 1); IVertex oVertex = oCommunity1.Vertices.First(); SortedList<Int32, CommunityPair> oCommunityPairs = oCommunity1.CommunityPairs; foreach (IVertex oAdjacentVertex in oVertex.AdjacentVertices) { if (oAdjacentVertex == oVertex) { // Skip self-loops. continue; } Community oCommunity2 = oVertexIDDictionary[oAdjacentVertex.ID]; CommunityPair oCommunityPair = new CommunityPair(); oCommunityPair.Community1 = oCommunity1; oCommunityPair.Community2 = oCommunity2; oCommunityPairs.Add(oCommunity2.ID, oCommunityPair); } } return (oCommunities); }
internal void Condense(IVertexCollection iVertexCollection) { foreach (TypeVertex v in iVertexCollection) { if (!this.ContainedTypes.Contains(v.TypeRef)) { this.ContainedTypes.Add(v.TypeRef); } string nmspace = TypeVertex.GetNamespace(v.TypeRef); if (this.NameSpaces.ContainsKey(nmspace)) { this.NameSpaces[nmspace]++; } else { this.NameSpaces[nmspace] = 1; } } }
//************************************************************************* // Method: CreateVertex() // /// <summary> /// Creates a vertex. /// </summary> /// /// <param name="sVertexName"> /// Name of the vertex to create. /// </param> /// /// <param name="oVertices"> /// Vertex collection to add the new vertex to. /// </param> /// /// <param name="oVertexNameDictionary"> /// Dictionary of existing vertices. The key is the vertex name and the /// value is the vertex. The dictionary can't already contain <paramref /// name="sVertexName" />. /// </param> /// /// <returns> /// The created vertex. /// </returns> /// /// <remarks> /// This method creates a vertex and adds it to both <paramref /// name="oVertices" /> and <paramref name="oVertexNameDictionary" />. /// </remarks> //************************************************************************* protected IVertex CreateVertex( String sVertexName, IVertexCollection oVertices, Dictionary<String, IVertex> oVertexNameDictionary ) { Debug.Assert( !String.IsNullOrEmpty(sVertexName) ); Debug.Assert(oVertices != null); Debug.Assert(oVertexNameDictionary != null); AssertValid(); IVertex oVertex = oVertices.Add(); oVertex.Name = sVertexName; oVertexNameDictionary.Add(sVertexName, oVertex); return (oVertex); }
//************************************************************************* // Constructor: EdgeCollectionEnumeratorTest() // /// <summary> /// Initializes a new instance of the <see /// cref="EdgeCollectionEnumeratorTest" /> class. /// </summary> //************************************************************************* public EdgeCollectionEnumeratorTest() { m_oEnumerator = null; m_oGraph = null; m_oVertexCollection = null; }
/// <summary> /// Creates a predicate that checks if vertices are in /// <paramref name="list"/> /// </summary> /// <param name="list">list of vertices</param> /// <exception cref="ArgumentNullException">list is a null reference</exception> public InCollectionVertexPredicate(IVertexCollection list) { if (list == null) throw new ArgumentNullException("list"); this.list = list; }
/// <summary> /// Check if vertex is in list /// </summary> /// <param name="list"></param> /// <returns></returns> public static InCollectionVertexPredicate InCollection(IVertexCollection list) { return new InCollectionVertexPredicate(list); }
public void SetUp() { m_oGraph = null; m_oVertices = null; m_oEdges = null; }
public void SetUp() { m_oGraph = new Graph(); m_oVertices = m_oGraph.Vertices; m_oEdges = m_oGraph.Edges; }
public void TearDown() { m_oEnumerator.Reset(); m_oEnumerator = null; m_oGraph = null; m_oVertexCollection = null; }
public void SetUp() { m_oGraph = new Graph(); Debug.Assert(m_oGraph.Edges is EdgeCollection); IEdgeCollection oEdgeCollection = m_oGraph.Edges; Debug.Assert(oEdgeCollection.GetEnumerator() is EdgeCollection.Enumerator); m_oEnumerator = (EdgeCollection.Enumerator)oEdgeCollection.GetEnumerator(); Debug.Assert(m_oGraph.Vertices is VertexCollection); m_oVertexCollection = m_oGraph.Vertices; }
VertexNameToVertex ( String sVertexName, IVertexCollection oVertices, Dictionary<String, IVertex> oDictionary ) { Debug.Assert( !String.IsNullOrEmpty(sVertexName) ); Debug.Assert(oVertices != null); Debug.Assert(oDictionary != null); AssertValid(); IVertex oVertex; if ( !oDictionary.TryGetValue(sVertexName, out oVertex) ) { oVertex = oVertices.Add(); oVertex.Name = sVertexName; oDictionary.Add(sVertexName, oVertex); } return (oVertex); }
public void TearDown() { m_oVertexCollection = null; m_oGraph = null; m_bVertexAdded = false; m_oAddedVertex = null; m_bVertexRemoved = false; m_oRemovedVertex = null; }
//************************************************************************* // Method: CreateGraph() // /// <summary> /// Creates the original graph. /// </summary> /// /// <param name="bDirected"> /// true for directed, false for undirected. /// </param> //************************************************************************* protected void CreateGraph( Boolean bDirected ) { m_oGraph = new Graph(bDirected ? GraphDirectedness.Directed : GraphDirectedness.Undirected); m_oVertices = m_oGraph.Vertices; m_oEdges = m_oGraph.Edges; }
//************************************************************************* // Method: VertexNameToVertex() // /// <summary> /// Finds or creates a vertex given a vertex name. /// </summary> /// /// <param name="sVertexName"> /// Name of the vertex to find or create. /// </param> /// /// <param name="oVertices"> /// Vertex collection to add a new vertex to if a new vertex is created. /// </param> /// /// <param name="oVertexNameDictionary"> /// Dictionary of existing vertices. The key is the vertex name and the /// value is the vertex. /// </param> /// /// <returns> /// The found or created vertex. /// </returns> /// /// <remarks> /// If <paramref name="oVertexNameDictionary" /> contains a vertex named /// <paramref name="sVertexName" />, the vertex is returned. Otherwise, a /// vertex is created, added to <paramref name="oVertices" />, added to /// <paramref name="oVertexNameDictionary" />, and returned. /// </remarks> //************************************************************************* protected IVertex VertexNameToVertex( String sVertexName, IVertexCollection oVertices, Dictionary<String, IVertex> oVertexNameDictionary ) { Debug.Assert( !String.IsNullOrEmpty(sVertexName) ); Debug.Assert(oVertices != null); Debug.Assert(oVertexNameDictionary != null); AssertValid(); IVertex oVertex; if ( !oVertexNameDictionary.TryGetValue(sVertexName, out oVertex) ) { oVertex = CreateVertex(sVertexName, oVertices, oVertexNameDictionary); } return (oVertex); }
public void TearDown() { m_oGraph = null; m_oVertices = null; m_oEdges = null; }
public void TearDown() { m_oConnectedComponentCalculator = null; m_oGraph = null; m_oVertices = null; m_oEdges = null; }
public void SetUp() { m_oGraph = new Graph(); Debug.Assert(m_oGraph.Vertices is VertexCollection); m_oVertexCollection = m_oGraph.Vertices; ( (VertexCollection)m_oVertexCollection ).VertexAdded += new VertexEventHandler(this.VertexCollection_VertexAdded); ( (VertexCollection)m_oVertexCollection ).VertexRemoved += new VertexEventHandler(this.VertexCollection_VertexRemoved); m_bVertexAdded = false; m_oAddedVertex = null; m_bVertexRemoved = false; m_oRemovedVertex = null; }
AddLoadedVertex ( String sVertexName, IVertexCollection oVertices, Dictionary<Int32, IVertex> oVertexDictionary ) { Debug.Assert( !String.IsNullOrEmpty(sVertexName) ); Debug.Assert(oVertices != null); Debug.Assert(oVertexDictionary != null); AssertValid(); IVertex oVertex = new Vertex(); oVertex.Name = sVertexName; oVertices.Add(oVertex); oVertexDictionary.Add(oVertices.Count - 1, oVertex); }
/// <summary> /// ctor() /// </summary> /// <param name="cgVertex">Vertex in the condensation graph</param> /// <param name="stronglyConnectedVertices">strongly connected /// components /// in the original graph which are represented by the condensation /// graph node</param> public CondensationGraphVertexEventArgs( IVertex cgVertex, IVertexCollection stronglyConnectedVertices) { this.vCG = cgVertex; this.stronglyConnectedVertices = stronglyConnectedVertices; }
private void calculateVertexPageRank(IVertexCollection vertices, Dictionary<Int32, Double> oldPageRanks, out Dictionary<Int32, Double> newPageRanks) { newPageRanks = new Dictionary<Int32, Double>(vertices.Count); foreach(IVertex node in vertices){ ICollection<IVertex> adjacentNodes = node.AdjacentVertices; double newRank = (1 - damping_factor) / vertices.Count; foreach (IVertex adjNode in adjacentNodes) { double adjNodeRank; oldPageRanks.TryGetValue(adjNode.ID, out adjNodeRank); newRank += damping_factor * adjNodeRank / adjNode.AdjacentVertices.Count; } newPageRanks.Add(node.ID, newRank); } }