private void Initialize(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph) { foreach (var cfgBlock in graph.Vertices) { _analysis.Initialize(cfgBlock); } }
public void EmptyGraph(IBidirectionalGraph<string, Edge<string>> g) { this.dfs = new BidirectionalDepthFirstSearchAlgorithm<string, Edge<string>>(g); this.dfs.Compute(); VerifyDfs(); }
/// <summary> /// Construct a filtered graph with an edge and a vertex predicate. /// </summary> /// <param name="g">graph to filter</param> /// <param name="edgePredicate">edge predicate</param> /// <param name="vertexPredicate">vertex predicate</param> /// <exception cref="ArgumentNullException"> /// g, edgePredicate or vertexPredicate are null /// </exception> public FilteredBidirectionalGraph( IBidirectionalGraph g, IEdgePredicate edgePredicate, IVertexPredicate vertexPredicate) : base(g,edgePredicate,vertexPredicate) { }
private void AddStartingBlocksToWorklist(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph) { foreach (var startBlock in _traversalTechnique.GetStartBlocks(graph)) { _workList.Add(startBlock); } }
public void Analyze(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph) { Preconditions.NotNull(graph, "graph"); Initialize(graph); AddStartingBlocksToWorklist(graph); WorklistTraversal2(graph); }
public TreeAdaptorGraph(IBidirectionalGraph wrapped) { if (wrapped == null) { throw new ArgumentNullException("wrapped"); } this.wrapped = wrapped; }
public void Sort <TVertex, TEdge>([PexAssumeNotNull] IBidirectionalGraph <TVertex, TEdge> g, TopologicalSortDirection direction) where TEdge : IEdge <TVertex> { var topo = new SourceFirstBidirectionalTopologicalSortAlgorithm <TVertex, TEdge>(g, direction); try { topo.Compute(); } catch (NonAcyclicGraphException) { } }
private static IEnumerable <TVertex> IsolatedVerticesIterator <TVertex, TEdge>( IBidirectionalGraph <TVertex, TEdge> visitedGraph) where TEdge : IEdge <TVertex> { foreach (var v in visitedGraph.Vertices) { if (visitedGraph.Degree(v) == 0) { yield return(v); } } }
private static IEnumerable <TVertex> RootsIterator <TVertex, TEdge>( IBidirectionalGraph <TVertex, TEdge> visitedGraph) where TEdge : IEdge <TVertex> { foreach (var v in visitedGraph.Vertices) { if (visitedGraph.IsInEdgesEmpty(v)) { yield return(v); } } }
public void OutDegreeSumEqualsEdgeCount([PexAssumeNotNull] IBidirectionalGraph <string, Edge <string> > graph) { int edgeCount = graph.EdgeCount; int degCount = 0; foreach (string v in graph.Vertices) { degCount += graph.OutDegree(v); } Assert.AreEqual(edgeCount, degCount); }
private static void GenerateHierarchicalVertices(BidirectionalGraph <HierarchicalGraphVertex, HierarchicalGraphEdge> graph, HierarchicalGraphVertex vertex, IBidirectionalGraph <Cluster <Variety>, ClusterEdge <Variety> > tree, Cluster <Variety> cluster) { foreach (ClusterEdge <Variety> edge in tree.OutEdges(cluster)) { double depth = vertex.Depth + edge.Length; var newVertex = edge.Target.DataObjects.Count == 1 ? new HierarchicalGraphVertex(edge.Target.DataObjects.First(), depth) : new HierarchicalGraphVertex(depth); graph.AddVertex(newVertex); graph.AddEdge(new HierarchicalGraphEdge(vertex, newVertex, edge.Length)); GenerateHierarchicalVertices(graph, newVertex, tree, edge.Target); } }
public ResultWindow(List <object> vertices) { var g = new BidirectionalGraph <object, IEdge <object> >(); foreach (object vertex in vertices) { g.AddVertex(vertex); } _graphToVisualize = g; InitializeComponent(); }
public EdgeMergeCondensationGraphAlgorithm( IBidirectionalGraph <TVertex, TEdge> visitedGraph, IMutableBidirectionalGraph <TVertex, MergedEdge <TVertex, TEdge> > condensatedGraph, VertexPredicate <TVertex> vertexPredicate ) : base(visitedGraph) { Contract.Requires(condensatedGraph != null); Contract.Requires(vertexPredicate != null); this.condensatedGraph = condensatedGraph; this.vertexPredicate = vertexPredicate; }
/// <summary> /// Creates an immutable array bidirectional graph from the input graph /// </summary> /// <typeparam name="TVertex">type of the vertices</typeparam> /// <typeparam name="TEdge">type of the edges</typeparam> /// <param name="graph"></param> /// <returns></returns> public static ArrayBidirectionalGraph <TVertex, TEdge> ToArrayBidirectionalGraph <TVertex, TEdge>( #if !NET20 this #endif IBidirectionalGraph <TVertex, TEdge> graph ) where TEdge : IEdge <TVertex> { Contract.Requires(graph != null); return(new ArrayBidirectionalGraph <TVertex, TEdge>(graph)); }
public void DependentClassifcation() { var classifiers = new List <Classifier>(); var dependentTree = new DependenceTree(this.vectors); foreach (var c in this.Classes) { classifiers.Add(new DependenceTreeClassifier(c.classId, dependentTree)); } this.GraphToVisualize = dependentTree.GraphToVisualize; this.ClassifyData(classifiers); }
public static IEnumerable <TEdge> GetOutEdges <TVertex, TEdge>(this IBidirectionalGraph <TVertex, TEdge> graph, TVertex vertex) where TEdge : IEdge <TVertex> { var result = new List <TEdge>(); IEnumerable <TEdge> edges; graph.TryGetOutEdges(vertex, out edges); if (edges != null) { result.AddRange(edges); } return(result); }
private static void Compute <TVertex, TEdge>([NotNull] IBidirectionalGraph <TVertex, TEdge> graph) where TEdge : IEdge <TVertex> { var dfs = new BidirectionalDepthFirstSearchAlgorithm <TVertex, TEdge>(graph); dfs.Compute(); foreach (TVertex vertex in graph.Vertices) { Assert.IsTrue(dfs.VerticesColors.ContainsKey(vertex)); Assert.AreEqual(dfs.VerticesColors[vertex], GraphColor.Black); } }
public BidirectionalDepthFirstSearchAlgorithm( IBidirectionalGraph <TVertex, TEdge> visitedGraph, IDictionary <TVertex, GraphColor> colors ) : base(visitedGraph) { if (colors == null) { throw new ArgumentNullException("VertexColors"); } this.colors = colors; }
public bool Analyze2(CFGBlock block, IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph) { var oldTaint = Taints[block]; var newTaint = AnalyzeNode2(block, graph); if (MonotonicChange(oldTaint, newTaint)) { _taints[block] = newTaint; return true; } return false; }
public bool Analyze2(CFGBlock block, IBidirectionalGraph <CFGBlock, TaggedEdge <CFGBlock, EdgeTag> > graph) { var oldTaint = Taints[block]; var newTaint = AnalyzeNode2(block, graph); if (MonotonicChange(oldTaint, newTaint)) { _taints[block] = newTaint; return(true); } return(false); }
private static void Sort <TVertex, TEdge>([NotNull] IBidirectionalGraph <TVertex, TEdge> graph, TopologicalSortDirection direction) where TEdge : IEdge <TVertex> { var algorithm = new SourceFirstBidirectionalTopologicalSortAlgorithm <TVertex, TEdge>(graph, direction); try { algorithm.Compute(); } catch (NonAcyclicGraphException) { } }
private static void AssertDegreeSumEqualsTwiceEdgeCount <TVertex, TEdge>( IBidirectionalGraph <TVertex, TEdge> graph) where TEdge : IEdge <TVertex> { int totalDegree = 0; foreach (TVertex vertex in graph.Vertices) { totalDegree += graph.Degree(vertex); } Assert.AreEqual(graph.EdgeCount * 2, totalDegree); }
private static void AssertInDegreeSumEqualsEdgeCount <TVertex, TEdge>( [NotNull] IBidirectionalGraph <TVertex, TEdge> graph) where TEdge : IEdge <TVertex> { int totalInDegree = 0; foreach (TVertex vertex in graph.Vertices) { totalInDegree += graph.InDegree(vertex); } Assert.AreEqual(graph.EdgeCount, totalInDegree); }
private void OutDegreeSumEqualsEdgeCount <TVertex, TEdge>( IBidirectionalGraph <TVertex, TEdge> graph) where TEdge : IEdge <TVertex> { int edgeCount = graph.EdgeCount; int degCount = 0; foreach (var v in graph.Vertices) { degCount += graph.OutDegree(v); } Assert.Equal(edgeCount, degCount); }
public static IEnumerable <TVertex> IsolatedVertices <TVertex, TEdge>( IBidirectionalGraph <TVertex, TEdge> visitedGraph) where TEdge : IEdge <TVertex> { GraphContracts.AssumeNotNull(visitedGraph, "visitedGraph"); foreach (var v in visitedGraph.Vertices) { if (visitedGraph.Degree(v) == 0) { yield return(v); } } }
public void OutDegreeSumEqualsEdgeCount <TVertex, TEdge>( [NotNull] IBidirectionalGraph <TVertex, TEdge> graph) where TEdge : IEdge <TVertex> { int edgeCount = graph.EdgeCount; int degCount = 0; foreach (TVertex vertex in graph.Vertices) { degCount += graph.OutDegree(vertex); } Assert.AreEqual(edgeCount, degCount); }
public void Compute <TVertex, TEdge>(IBidirectionalGraph <TVertex, TEdge> g) where TEdge : IEdge <TVertex> { var dfs = new BidirectionalDepthFirstSearchAlgorithm <TVertex, TEdge>(g); dfs.Compute(); // let's make sure foreach (var v in g.Vertices) { Assert.IsTrue(dfs.VertexColors.ContainsKey(v)); Assert.AreEqual(dfs.VertexColors[v], GraphColor.Black); } }
public void InDegreeSumEqualsEdgeCount <TVertex, TEdge>( [PexAssumeNotNull] IBidirectionalGraph <TVertex, TEdge> graph) where TEdge : IEdge <TVertex> { int edgeCount = graph.EdgeCount; int degCount = 0; foreach (var v in graph.Vertices) { degCount += graph.InDegree(v); } Assert.AreEqual(edgeCount, degCount); }
public IBidirectionalGraph <HierarchicalGraphVertex, HierarchicalGraphEdge> GenerateHierarchicalGraph(HierarchicalGraphType graphType, ClusteringMethod clusteringMethod, SimilarityMetric similarityMetric) { switch (clusteringMethod) { case ClusteringMethod.Upgma: Func <Variety, Variety, double> upgmaGetDistance = null; switch (similarityMetric) { case SimilarityMetric.Lexical: upgmaGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].LexicalSimilarityScore; break; case SimilarityMetric.Phonetic: upgmaGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].PhoneticSimilarityScore; break; } var upgma = new UpgmaClusterer <Variety>(upgmaGetDistance); IBidirectionalGraph <Cluster <Variety>, ClusterEdge <Variety> > upgmaTree = upgma.GenerateClusters(_projectService.Project.Varieties); return(BuildHierarchicalGraph(upgmaTree)); case ClusteringMethod.NeighborJoining: Func <Variety, Variety, double> njGetDistance = null; switch (similarityMetric) { case SimilarityMetric.Lexical: njGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].LexicalSimilarityScore; break; case SimilarityMetric.Phonetic: njGetDistance = (v1, v2) => 1.0 - v1.VarietyPairs[v2].PhoneticSimilarityScore; break; } var nj = new NeighborJoiningClusterer <Variety>(njGetDistance); IUndirectedGraph <Cluster <Variety>, ClusterEdge <Variety> > njTree = nj.GenerateClusters(_projectService.Project.Varieties); switch (graphType) { case HierarchicalGraphType.Dendrogram: IBidirectionalGraph <Cluster <Variety>, ClusterEdge <Variety> > rootedTree = njTree.ToRootedTree(); return(BuildHierarchicalGraph(rootedTree)); case HierarchicalGraphType.Tree: return(BuildHierarchicalGraph(njTree)); } break; } return(null); }
private static void RunSourceFirstTopologicalSortAndCheck <TVertex, TEdge>( [NotNull] IBidirectionalGraph <TVertex, TEdge> graph, TopologicalSortDirection direction) where TEdge : IEdge <TVertex> { var algorithm = new SourceFirstBidirectionalTopologicalSortAlgorithm <TVertex, TEdge>(graph, direction); algorithm.Compute(); Assert.IsNotNull(algorithm.SortedVertices); Assert.AreEqual(graph.VertexCount, algorithm.SortedVertices.Length); Assert.IsNotNull(algorithm.InDegrees); Assert.AreEqual(graph.VertexCount, algorithm.InDegrees.Count); }
/// <summary> /// Recursively collects all vertices that can be reached from a given vertex /// by traversing only those edges that are chosen by a given predicate. /// </summary> public static IEnumerable <TVertex> GetAdjacentVertices <TVertex, TEdge>(this IBidirectionalGraph <TVertex, TEdge> graph, TVertex vertex, EdgeDirection direction, EdgePredicate <TVertex, TEdge> edgePredicate = null, bool recursive = false) where TEdge : IEdge <TVertex> { if (!graph.ContainsVertex(vertex)) { return(Enumerable.Empty <TVertex>()); } var collectedVertices = new List <TVertex>(); CollectAdjacentVerticesRecursive(graph, vertex, direction, collectedVertices, edgePredicate, recursive); return(collectedVertices.Except(vertex)); }
public ActionGraph(IEngineConfiguration config) { if (config == null) { throw new ArgumentNullException("config"); } var graph = new BidirectionalGraph <IAction, Edge <IAction> >(false); graph.AddVertexRange(config.Actions); var edges = config.Links.Select(x => new Edge <IAction>(x.From, x.To)); graph.AddEdgeRange(edges); _graph = graph; }
public static IEnumerable <TVertex> Roots <TVertex, TEdge>( IBidirectionalGraph <TVertex, TEdge> visitedGraph) where TEdge : IEdge <TVertex> { GraphContracts.AssumeNotNull(visitedGraph, "visitedGraph"); foreach (var v in visitedGraph.Vertices) { if (visitedGraph.IsInEdgesEmpty(v)) { yield return(v); } } }
public static bool FoundTarget <TVertex, TEdge>(IBidirectionalGraph <TVertex, TEdge> g, TVertex root, TVertex target) where TEdge : IEdge <TVertex> { IDistanceRelaxer distanceRelaxer = DistanceRelaxers.EdgeShortestDistance; var algorithm = new BestFirstFrontierSearchAlgorithm <TVertex, TEdge>(g, edgeWeights => 1.0, distanceRelaxer); bool targetReached = false; algorithm.TargetReached += (sender, args) => targetReached = true; var recorder = new VertexPredecessorRecorderObserver <TVertex, TEdge>(); using (recorder.Attach(algorithm)) algorithm.Compute(root, target); return(targetReached); }
public static IEnumerable <TVertex> SourceFirstBidirectionalTopologicalSort <TVertex, TEdge>( #if !NET20 this #endif IBidirectionalGraph <TVertex, TEdge> visitedGraph, TopologicalSortDirection direction) where TEdge : IEdge <TVertex> { Contract.Requires(visitedGraph != null); var vertices = new List <TVertex>(visitedGraph.VertexCount); SourceFirstBidirectionalTopologicalSort(visitedGraph, vertices, direction); return(vertices); }
/// <summary> /// Constructs a new ArrayBidirectionalGraph instance from a /// IBidirectionalGraph instance /// </summary> /// <param name="visitedGraph"></param> public ArrayBidirectionalGraph( IBidirectionalGraph <TVertex, TEdge> visitedGraph ) { Contract.Requires(visitedGraph != null); this.vertexEdges = new Dictionary <TVertex, InOutEdges>(visitedGraph.VertexCount); this.edgeCount = visitedGraph.EdgeCount; foreach (var vertex in visitedGraph.Vertices) { var outEdges = Enumerable.ToArray(visitedGraph.OutEdges(vertex)); var inEdges = Enumerable.ToArray(visitedGraph.InEdges(vertex)); this.vertexEdges.Add(vertex, new InOutEdges(outEdges, inEdges)); } }
public static void ShowGraphCircular(GraphLayout layout, IBidirectionalGraph <object, IEdge <object> > graph, int horizontalGap = 25, int verticalGap = 10) { var overlapParameters = new OverlapRemovalParameters(); overlapParameters.HorizontalGap = horizontalGap; overlapParameters.VerticalGap = verticalGap; layout.OverlapRemovalParameters = overlapParameters; layout.OverlapRemovalAlgorithmType = "FSA"; layout.OverlapRemovalConstraint = AlgorithmConstraints.Must; layout.LayoutMode = LayoutMode.Simple; layout.LayoutAlgorithmType = "Circular"; layout.Graph = graph; }
private void WorklistTraversal(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph) { while (_workList.Any()) { var block = _workList.GetNext(); var nextEdges = _traversalTechnique.NextEdges(graph, block); foreach (var edge in nextEdges) { var didChange = _analysis.Analyze(edge); var target =_traversalTechnique.EdgeTarget(edge); if ((didChange || !_visited.Contains(target)) && !_workList.Contains(target)) { _workList.Add(target); } _visited.Add(target); } } }
private void CreateGraphToVisualize() { var g = new BidirectionalGraph<object, IEdge<object>>(); //add the vertices to the graph string[] vertices = new string[5]; for (int i = 0; i < 5; i++) { vertices[i] = i.ToString(); g.AddVertex(vertices[i]); } //add some edges to the graph g.AddEdge(new Edge<object>(vertices[0], vertices[1])); g.AddEdge(new Edge<object>(vertices[1], vertices[2])); g.AddEdge(new Edge<object>(vertices[2], vertices[3])); g.AddEdge(new Edge<object>(vertices[3], vertices[1])); g.AddEdge(new Edge<object>(vertices[1], vertices[4])); _graphToVisualize = g; }
private void WorklistTraversal2(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph) { while (_workList.Any()) { var block = _workList.GetNext(); var didChange = _analysis.Analyze2(block, graph); var successors = graph.OutEdges(block) .OrderBy(e => e.Tag.EdgeType) .Select(e => e.Target); foreach (var successor in successors) { if (didChange || !_visited.Contains(successor)) { _workList.Add(successor); } } _visited.Add(block); } }
public IEnumerable<CFGBlock> GetStartBlocks(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph) { return graph.Roots().Where(r => r.IsRoot); }
private static IBidirectionalGraph<HierarchicalGraphVertex, HierarchicalGraphEdge> BuildHierarchicalGraph(IBidirectionalGraph<Cluster<Variety>, ClusterEdge<Variety>> tree) { var graph = new BidirectionalGraph<HierarchicalGraphVertex, HierarchicalGraphEdge>(); var root = new HierarchicalGraphVertex(0); graph.AddVertex(root); GenerateHierarchicalVertices(graph, root, tree, tree.Roots().First()); return graph; }
private static void GenerateHierarchicalVertices(BidirectionalGraph<HierarchicalGraphVertex, HierarchicalGraphEdge> graph, HierarchicalGraphVertex vertex, IBidirectionalGraph<Cluster<Variety>, ClusterEdge<Variety>> tree, Cluster<Variety> cluster) { foreach (ClusterEdge<Variety> edge in tree.OutEdges(cluster)) { double depth = vertex.Depth + edge.Length; var newVertex = edge.Target.DataObjects.Count == 1 ? new HierarchicalGraphVertex(edge.Target.DataObjects.First(), depth) : new HierarchicalGraphVertex(depth); graph.AddVertex(newVertex); graph.AddEdge(new HierarchicalGraphEdge(vertex, newVertex, edge.Length)); GenerateHierarchicalVertices(graph, newVertex, tree, edge.Target); } }
/// <summary> /// /// </summary> /// <param name="g"></param> /// <param name="assg"></param> public void Transform(IBidirectionalGraph g, IMutableVertexAndEdgeListGraph assg) { VertexCollection avs = new VertexCollection(); // adding vertices foreach(IEdge e in g.Edges) { // xi_-(L) = g(xi_-(0), xi_+(L)) CharacteristicVertex avm = (CharacteristicVertex)assg.AddVertex(); avm.IncomingEdge = e; avm.Vertex = e.Target; avs.Add(avm); // xi_+(0) = g(xi_-(0), xi_+(L)) CharacteristicVertex avp = (CharacteristicVertex)assg.AddVertex(); avp.IncomingEdge = e; avp.Vertex = e.Source; avs.Add(avp); } // adding out edges foreach(CharacteristicVertex av in avs) { foreach(IEdge e in g.OutEdges(av.Vertex)) { // find target vertex: CharacteristicVertex avtarget = FindTargetVertex(e); // add xi_- CharacteristicEdge aem = (CharacteristicEdge)assg.AddEdge(av,avtarget); aem.Positive = false; aem.Edge = e; } foreach(IEdge e in g.InEdges(av.Vertex)) { // find target vertex: CharacteristicVertex avtarget = FindTargetVertex(e); // add xi_- CharacteristicEdge aem = (CharacteristicEdge)assg.AddEdge(av,avtarget); aem.Positive = true; aem.Edge = e; } } }
/// <summary> /// Source vertex prodicate /// </summary> /// <param name="graph"></param> /// <returns></returns> public static SourceVertexPredicate SourceVertex(IBidirectionalGraph graph) { return new SourceVertexPredicate(graph); }
public static void AddGraph(IBidirectionalGraph<object, IEdge<object>> graph, List<double> expectedValues, List<double> actualValues) { if (selfPtr == null) { selfPtr = new VisualizationManager(); } while (selfPtr.graphList == null || selfPtr.expectedGraphOutputDataList == null || selfPtr.actualGraphOutputDataList == null) { Thread.Sleep(1); } selfPtr.graphList.Add(graph); selfPtr.expectedGraphOutputDataList.Add(ConvertDoubleListToPointCollection(expectedValues)); selfPtr.actualGraphOutputDataList.Add(ConvertDoubleListToPointCollection(actualValues)); }
private CFGTaintInfo AnalyzeNode2(CFGBlock block, IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph) { var oldTaint = Taints[block]; var predecessorsOut = graph.InEdges(block); var outTaints = predecessorsOut.Select(p => new { EdgeType = p.Tag, Source = p.Source }) .Where(s => Taints[s.Source].Out != null && Taints[s.Source].Out.Any()) .Select(s => Taints[s.Source].Out[s.EdgeType.EdgeType]) .Where(o => o != null); ImmutableVariableStorage newInTaint; if (outTaints.Any()) { newInTaint = oldTaint.In.Merge(outTaints.Aggregate((current, next) => current.Merge(next))); } else { newInTaint = oldTaint.In; } ImmutableDictionary<EdgeType, ImmutableVariableStorage> newOutTaint; if (block.AstEntryNode == null) { newOutTaint = ImmutableDictionary<EdgeType, ImmutableVariableStorage>.Empty.Add(EdgeType.Normal, newInTaint); } else { var newOut = _blockAnalyzer.Analyze(block.AstEntryNode, newInTaint); var newOutWithCondSani = _conditionTaintAnalyser.AnalyzeCond(block.AstEntryNode, newOut); newOutTaint = newOutWithCondSani.ToImmutableDictionary(); } return new CFGTaintInfo(newInTaint, newOutTaint); }
public IEnumerable<CFGBlock> GetStartBlocks(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph) { return graph.Vertices.Where(v => v.IsLeaf); }
public IEnumerable<TaggedEdge<CFGBlock, EdgeTag>> NextEdges(IBidirectionalGraph<CFGBlock, TaggedEdge<CFGBlock, EdgeTag>> graph, CFGBlock block) { return graph.InEdges(block); }
private void Calculate() { initialList = new List<List<string>>(); foreach (var item in initialStrings) { initialList.Add(Extensions.GetSplittedWords(item.Value)); } comparationList = Operands.CompareLines(initialStrings.Values.ToList()); List<List<int>> groupsList = Groupping.Group(comparationList); gropsFull = Operands.GetUniqueInGroups(initialStrings, groupsList); groupsSimplified = Groupping.Simplify(initialStrings, gropsFull); modulesFull = new Dictionary<List<int>, string>(); graphsListInitial = new List<IBidirectionalGraph<object, IEdge<object>>>(); graphsListModuled = new List<IBidirectionalGraph<object, IEdge<object>>>(); int counter = 0; foreach (var item in groupsSimplified) { graphsListInitial.Add(Graph.AdjacentyMatrixToGraph(Modules.CreateRelationMatrix(initialStrings, item))); var modulesMatrix = Modules.GetModulesMatrix(initialStrings, item); graphsListModuled.Add(Graph.AdjacentyMatrixToGraph(modulesMatrix)); modulesFull.Add(item.Key, String.Join(" ", modulesMatrix.Headers.Values.ToList())); counter++; } modulesUnique = Modules.GetModulesUnique(modulesFull); graphFlows = Modules.GetFlows(initialStrings.Values.ToList(),groupsSimplified.Values.ToList(), modulesUnique); initialized = true; }
/// <summary> /// Create the predicate over <paramref name="graph"/>. /// </summary> /// <param name="graph">graph to visit</param> public SourceVertexPredicate(IBidirectionalGraph graph) { if (graph==null) throw new ArgumentNullException("graph"); this.graph = graph; }
public static void ContainsEdgeAssertions(IBidirectionalGraph<int, IEdge<int>> g, IEdge<int> e12, IEdge<int> f12, IEdge<int> e21, IEdge<int> f21) { Assert.AreEqual(0, g.InDegree(1)); Assert.AreEqual(1, g.OutDegree(1)); Assert.AreEqual(1, g.InDegree(2)); Assert.AreEqual(0, g.OutDegree(2)); Assert.AreEqual(1, g.OutEdges(1).Count()); Assert.AreEqual(1, g.InEdges(2).Count()); // e12 must be present in u, because we added it. Assert.IsTrue(g.ContainsEdge(e12)); // f12 is also in u, because e12 == f12. Assert.IsTrue(g.ContainsEdge(f12)); // e21 and f21 are not in u, because it's a directed graph. if (e21 != null) Assert.IsFalse(g.ContainsEdge(e21)); if (f21 != null) Assert.IsFalse(g.ContainsEdge(f21)); // there must be an edge between vertices 1, 2. Assert.IsTrue(g.ContainsEdge(1, 2)); // no edge between vertices 2, 1, because the graph is directed. Assert.IsFalse(g.ContainsEdge(2, 1)); // ContainsEdge(1, 3) raises contracts violation in IIncidenceGraphContract, because 3 is not in the graph. // obviously no edge between vertices 1, 3, as vertex 3 is not even present in the graph. // Assert.IsFalse(g.ContainsEdge(1, 3)); }