internal static void PerformWarshall(VisioAutomation.DocumentAnalysis.BitArray2D adj_matrix) { if (adj_matrix == null) { throw new System.ArgumentNullException(nameof(adj_matrix)); } if (adj_matrix.Width != adj_matrix.Height) { const string msg = "Adjacency Matrix width must equal its height"; throw new System.ArgumentException(msg); } for (int k = 0; k < adj_matrix.Width; k++) { for (int row = 0; row < adj_matrix.Height; row++) { for (int col = 0; col < adj_matrix.Width; col++) { bool v = adj_matrix.Get(row, col) | (adj_matrix.Get(row, k) & adj_matrix.Get(k, col)); adj_matrix[row, col] = v; } } } }
public void Construct2DBitArray() { // check that cols and rows must be > 0 bool caught = false; try { var ba = new VisioAutomation.DocumentAnalysis.BitArray2D(0, 1); } catch (System.ArgumentOutOfRangeException) { caught = true; } if (caught == false) { Assert.Fail("Did not catch expected exception"); } caught = false; try { var ba = new VisioAutomation.DocumentAnalysis.BitArray2D(1, 0); } catch (System.ArgumentOutOfRangeException) { caught = true; } if (caught == false) { Assert.Fail("Did not catch expected exception"); } // Create a 1x1 BitArray var ba2 = new VisioAutomation.DocumentAnalysis.BitArray2D(1, 1); Assert.AreEqual(false, ba2[0, 0]); ba2[0, 0] = true; Assert.AreEqual(true, ba2[0, 0]); ba2[0, 0] = false; Assert.AreEqual(false, ba2[0, 0]); }
public static IEnumerable <DirectedEdge <TNode, object> > GetClosureFromEdges <TNode, TData>( IEnumerable <DirectedEdge <TNode, TData> > edges) { if (edges == null) { throw new System.ArgumentNullException(nameof(edges)); } var object_to_id = new Dictionary <TNode, int>(); var id_to_object = new Dictionary <int, TNode>(); foreach (var edge in edges) { if (!object_to_id.ContainsKey(edge.From)) { object_to_id[edge.From] = object_to_id.Count; } if (!object_to_id.ContainsKey(edge.To)) { object_to_id[edge.To] = object_to_id.Count; } } foreach (var i in object_to_id) { id_to_object[i.Value] = i.Key; } var internal_edges = new List <DirectedEdge <int, object> >(); foreach (var edge in edges) { int fromid = object_to_id[edge.From]; int toid = object_to_id[edge.To]; var directed_edge = new DirectedEdge <int, object>(fromid, toid, null); internal_edges.Add(directed_edge); } if (internal_edges.Count == 0) { yield break; } int num_vertices = object_to_id.Count; var adj_matrix = new VisioAutomation.DocumentAnalysis.BitArray2D(num_vertices, num_vertices); foreach (var iedge in internal_edges) { adj_matrix[iedge.From, iedge.To] = true; } var warshall_result = adj_matrix.Clone(); ConnectionAnalyzer.PerformWarshall(warshall_result); for (int row = 0; row < adj_matrix.Width; row++) { for (int col = 0; col < adj_matrix.Height; col++) { if (warshall_result.Get(row, col) && (row != col)) { var de = new DirectedEdge <TNode, object>(id_to_object[row], id_to_object[col], null); yield return(de); } } } }