Ejemplo n.º 1
0
        DirectedGraph <INodeMetadata> ExcludeFormulaNodes(DirectedGraph <INodeMetadata> directedGraph)
        {
            var newGraph     = directedGraph.Clone(v => v.Data);
            var formulaNodes = newGraph.Verticies.Where(v => v.Data.VisualisationInfo.NodeType == NodeType.Formula).ToArray();

            // Add edge between formula successors and predecessors
            foreach (var formulaNode in formulaNodes)
            {
                var predecessors = formulaNode.Predecessors.ToArray();
                var successors   = formulaNode.Successors.ToArray();
                newGraph.DeleteVertex(formulaNode.Data);

                foreach (var predecessor in predecessors)
                {
                    foreach (var successor in successors)
                    {
                        var source = predecessor.Source;
                        var target = successor.Target;
                        newGraph.AddEdge(source.Data, target.Data, source.Id, target.Id);
                    }
                }
            }

            return(newGraph);
        }
Ejemplo n.º 2
0
        public void CloneTest()
        {
            var graph      = new DirectedGraph();
            var newVertex1 = new Vertex("test-1");
            var newVertex2 = new Vertex("test-2");
            var newVertex3 = new Vertex("test-3");

            graph.AddVertex(newVertex1);
            graph.AddVertex(newVertex2);
            graph.AddVertex(newVertex3);
            var newEdge1 = new DirectedEdge(newVertex1, newVertex2);
            var newEdge2 = new DirectedEdge(newVertex1, newVertex3);

            graph.AddEdge(newEdge1);
            graph.AddEdge(newEdge2);

            var clonedGraph = graph.Clone() as IGraph;

            Assert.IsTrue(clonedGraph is DirectedGraph);
            Assert.AreEqual(graph.VerticesCount, clonedGraph.VerticesCount);
            foreach (var vertex in graph.Vertices)
            {
                var clonedVertex = clonedGraph.Vertices.Single(v => v.Equals(vertex));
                Assert.AreNotSame(clonedVertex, vertex);
            }
            Assert.AreEqual(graph.EdgesCount, clonedGraph.EdgesCount);
            foreach (var clonedEdge in clonedGraph.Edges)
            {
                Assert.IsTrue(clonedEdge is DirectedEdge);
                var edge = graph.Edges.Single(e => e.Equals(clonedEdge));
                Assert.AreNotSame(edge, clonedEdge);
            }
        }
Ejemplo n.º 3
0
        public void TestClone()
        {
            var original = new DirectedGraph <string, string>()
            {
                "a",
                "b",
                { "a", "b", "a-b" },
            };

            var cloned = original.Clone() as DirectedGraph <string, string>;

            original.Add("c");

            Assert.False(cloned.Contains("c"));
        }
Ejemplo n.º 4
0
        private static void SaveGraph(Schema schema, DirectedGraph <Entity> identifiables)
        {
            //takes apart the 'forbidden' connections from the good ones
            DirectedGraph <Entity> backEdges = identifiables.FeedbackEdgeSet();

            if (backEdges.IsEmpty())
            {
                backEdges = null;
            }
            else
            {
                identifiables.RemoveEdges(backEdges.Edges);
            }

            Dictionary <TypeNew, int> stats = identifiables.GroupCount(ident => new TypeNew(ident.GetType(), ident.IsNew));

            DirectedGraph <Entity> clone = identifiables.Clone();
            DirectedGraph <Entity> inv   = identifiables.Inverse();

            while (clone.Count > 0)
            {
                IGrouping <TypeNew, Entity> group = clone.Sinks()
                                                    .GroupBy(ident => new TypeNew(ident.GetType(), ident.IsNew))
                                                    .WithMin(g => stats[g.Key] - g.Count());

                foreach (var node in group)
                {
                    clone.RemoveFullNode(node, inv.RelatedTo(node));
                }

                stats[group.Key] -= group.Count();

                SaveGroup(schema, group, backEdges);
            }

            if (backEdges != null)
            {
                foreach (var gr in backEdges.Edges.Select(e => e.From).Distinct().GroupBy(ident => new TypeNew(ident.GetType(), ident.IsNew)))
                {
                    SaveGroup(schema, gr, null);
                }
            }
        }
Ejemplo n.º 5
0
        public void Clone()
        {
            var myGraph = new DirectedGraph <int, EdgeData>();

            myGraph.AddNodes(1, 2, 3, 4);
            myGraph.AddEdges(
                (1, 2, dummyEdgeData),
                (2, 3, dummyEdgeData),
                (2, 1, dummyEdgeData),
                (3, 4, dummyEdgeData)
                );

            var clone = myGraph.Clone();

            Assert.That(clone, Is.Not.EqualTo(myGraph));
            clone.Nodes.Should().BeEquivalentTo(1, 2, 3, 4);
            clone.Neighbors(1).Should().BeEquivalentTo(2);
            clone.Neighbors(2).Should().BeEquivalentTo(3, 1);
            clone.Neighbors(3).Should().BeEquivalentTo(4);
        }
Ejemplo n.º 6
0
 public DirectedGraph <INodeMetadata> GetGraphSnapshot()
 {
     return(graph.Clone(vertex => (INodeMetadata) new NodeMetadata(vertex.Data.VisualisationInfo, vertex.Data.ToString(), vertex.Id)));
 }
Ejemplo n.º 7
0
        DirectedGraph<INodeMetadata> ExcludeFormulaNodes(DirectedGraph<INodeMetadata> directedGraph)
        {
            var newGraph = directedGraph.Clone(v => v.Data);
            var formulaNodes = newGraph.Verticies.Where(v => v.Data.VisualisationInfo.NodeType == NodeType.Formula).ToArray();
            // Add edge between formula successors and predecessors
            foreach (var formulaNode in formulaNodes)
            {
                var predecessors = formulaNode.Predecessors.ToArray();
                var successors = formulaNode.Successors.ToArray();
                newGraph.DeleteVertex(formulaNode.Data);

                foreach (var predecessor in predecessors)
                {
                    foreach (var successor in successors)
                    {
                        var source = predecessor.Source;
                        var target = successor.Target;
                        newGraph.AddEdge(source.Data, target.Data, source.Id, target.Id);
                    }
                }
            }

            return newGraph;
        }