예제 #1
0
        public void TestGraphConstructor_3PointsTriangleNotDirected_GraphArray()
        {
            Point3d   pointA     = new Point3d(0.01, 0.2, 0.5);
            Point3d   pointB     = new Point3d(1, 7, 10);
            Point3d   pointC     = new Point3d(1.2, 5.3, 10);
            GraphPart graphPart1 = new GraphPart(pointA, pointB, false);
            GraphPart graphPart2 = new GraphPart(pointB, pointC, false);
            GraphPart graphPart3 = new GraphPart(pointC, pointA, false);

            Graph graph = new Graph(new List <GraphPart> {
                graphPart1, graphPart2, graphPart3
            }, 0.001);

            int[,] expectedGraphArray = new int[2, 6];

            expectedGraphArray[0, 0] = 0;
            expectedGraphArray[1, 0] = 1;
            expectedGraphArray[0, 1] = 1;
            expectedGraphArray[1, 1] = 0;
            expectedGraphArray[0, 2] = 1;
            expectedGraphArray[1, 2] = 2;
            expectedGraphArray[0, 3] = 2;
            expectedGraphArray[1, 3] = 1;
            expectedGraphArray[0, 4] = 2;
            expectedGraphArray[1, 4] = 0;
            expectedGraphArray[0, 5] = 0;
            expectedGraphArray[1, 5] = 2;
            Assert.Equal(expectedGraphArray.Length, graph.GraphArray.Length);
            Assert.Equal(expectedGraphArray, graph.GraphArray);
        }
예제 #2
0
        internal void GenerateDGML(string saveFilePath, GraphPart part, IEnumerable <string> nodeTypes, IEnumerable <string> linkTypes)
        {
            var rootNode = new XElement(XName.Get("DirectedGraph", dgmlNS),
                                        new XAttribute("GraphDirection", "LeftToRight"),
                                        new XElement(XName.Get("Nodes", dgmlNS),
                                                     from item in part.Nodes
                                                     select
                                                     new XElement(XName.Get("Node", dgmlNS),
                                                                  new XAttribute("Id", item.Id),
                                                                  new XAttribute("Label", item.Title),
                                                                  new XAttribute("Project", item.Project),
                                                                  new XAttribute("Category", item.Category),
                                                                  new XAttribute("SourceLocation", item.SourceLocation))),
                                        new XElement(XName.Get("Categories", dgmlNS),
                                                     nodeTypes.Select(t => new XElement(XName.Get("Category", dgmlNS), new XAttribute("Id", t))),
                                                     linkTypes.Select(t => new XElement(XName.Get("Category", dgmlNS), new XAttribute("Id", t)))),
                                        GenerateStyles(nodeTypes, linkTypes));

            var linksNode = new XElement(XName.Get("Links", dgmlNS),
                                         from item in part.Links
                                         select new XElement(XName.Get("Link", dgmlNS), new XAttribute("Source", item.SourceId), new XAttribute("Target", item.TargetId),
                                                             new XAttribute("Category", item.Category),
                                                             new XAttribute("Label", item.LinkEndType)));

            rootNode.Add(linksNode);

            var document = new XDocument(rootNode);

            document.Save(saveFilePath);
        }
예제 #3
0
        public void TestGraphDegrees_3PointsSame1Edge_VertexDegrees()
        {
            Point3d   pointA     = new Point3d(0.01, 0.2, 0.5);
            Point3d   pointB     = new Point3d(1, 7, 10);
            Point3d   pointC     = new Point3d(1.2, 5.3, 10);
            GraphPart graphPart1 = new GraphPart(pointA, pointB, true);
            GraphPart graphPart2 = new GraphPart(pointB, pointC, true);
            GraphPart graphPart3 = new GraphPart(pointA, pointB, true);

            Graph graph = new Graph(new List <GraphPart> {
                graphPart1, graphPart2, graphPart3
            }, 0.001);

            Assert.Equal(2, graph.GetVertexDegree(0));
            Assert.Equal(2, graph.GetVertexOutdegree(0));
            Assert.Equal(0, graph.GetVertexIndegree(0));

            Assert.Equal(3, graph.GetVertexDegree(1));
            Assert.Equal(1, graph.GetVertexOutdegree(1));
            Assert.Equal(2, graph.GetVertexIndegree(1));

            Assert.Equal(1, graph.GetVertexDegree(2));
            Assert.Equal(0, graph.GetVertexOutdegree(2));
            Assert.Equal(1, graph.GetVertexIndegree(2));
        }
예제 #4
0
        internal void Render(GraphPart part)
        {
            foreach (var node in part.Nodes)
            {
                var graphNode = _graph.Nodes.GetOrCreate(node.Id.ToString());
                graphNode.Label = node.Title;
                graphNode.SetValue <string>(_projectProperty, node.Project);
                GraphCategory category;
                if (_categories.TryGetValue(node.Category, out category))
                {
                    graphNode.AddCategory(category);
                }
            }

            foreach (var link in part.Links)
            {
                var graphLink = _graph.Links.GetOrCreate(
                    _graph.Nodes.Get(link.SourceId.ToString()),
                    _graph.Nodes.Get(link.TargetId.ToString()));
                graphLink.Label = link.LinkEndType;

                GraphCategory category;
                if (_categories.TryGetValue(link.Category, out category))
                {
                    graphLink.AddCategory(category);
                }

                _graph.Links.Add(graphLink);
            }
        }
        private GraphRender GetRender(IServiceProvider provider, EnvDTE.DTE dte,
                                      GraphPart part, string path, IEnumerable <string> nodeTypes, IEnumerable <string> linkTypes)
        {
            var serializer = new GraphSerializer();

            serializer.GenerateDGML(path, part, nodeTypes, linkTypes);

            var window     = dte.ItemOperations.OpenFile(path);
            var automation = window.Object as GraphControlAutomationObject;

            if (automation == null)
            {
                throw new ApplicationException("Missing graph control automation.");
            }

            try
            {
                File.Delete(path);
            }
            catch (Exception ex)
            {
                OutputWindowHelper.OutputString(provider, ex.Message);
            }

            var graph = automation.Graph;

            return(new GraphRender(graph));
        }
예제 #6
0
        public void TestGraphConstructor_3PointsSame1Edge_AdjacencyList()
        {
            Point3d   pointA     = new Point3d(0.01, 0.2, 0.5);
            Point3d   pointB     = new Point3d(1, 7, 10);
            Point3d   pointC     = new Point3d(1.2, 5.3, 10);
            GraphPart graphPart1 = new GraphPart(pointA, pointB, true);
            GraphPart graphPart2 = new GraphPart(pointB, pointC, true);
            GraphPart graphPart3 = new GraphPart(pointA, pointB, true);

            Graph graph = new Graph(new List <GraphPart> {
                graphPart1, graphPart2, graphPart3
            }, 0.001);

            List <int>[] expectedAdjacencyListVertices = new List <int> [3];
            List <int>[] expectedAdjacencyListEdges    = new List <int> [3];

            expectedAdjacencyListVertices[0] = new List <int> {
                1, 1
            };
            expectedAdjacencyListVertices[1] = new List <int> {
                2
            };
            expectedAdjacencyListVertices[2] = new List <int>();

            expectedAdjacencyListEdges[0] = new List <int> {
                0, 2
            };
            expectedAdjacencyListEdges[1] = new List <int> {
                1
            };
            expectedAdjacencyListEdges[2] = new List <int>();

            Assert.Equal(expectedAdjacencyListVertices, graph.AdjacencyList.Vertices);
            Assert.Equal(expectedAdjacencyListEdges, graph.AdjacencyList.Edges);
        }
예제 #7
0
        public double getRoadWeightToNode(Node end)
        {
            GraphPart partOfEndNode = this.graph.GraphPart.Find(x => x.Node.Label == end.Label);

            if (partOfEndNode == default)
            {
                return(default);
예제 #8
0
        public void TestGraphConstructor_2Points2Times_AdjacencyList()
        {
            Point3d   pointA     = new Point3d(0.01, 0.2, 0.5);
            Point3d   pointB     = new Point3d(1, 7, 10);
            GraphPart graphPart1 = new GraphPart(pointA, pointB, true);
            GraphPart graphPart2 = new GraphPart(pointA, pointB, true);

            Graph graph = new Graph(new List <GraphPart> {
                graphPart1, graphPart2
            }, 0.001);

            List <int>[] expectedAdjacencyListVertices = new List <int> [2];
            List <int>[] expectedAdjacencyListEdges    = new List <int> [2];

            expectedAdjacencyListVertices[0] = new List <int> {
                1, 1
            };
            expectedAdjacencyListVertices[1] = new List <int>();
            expectedAdjacencyListEdges[0]    = new List <int> {
                0, 1
            };
            expectedAdjacencyListEdges[1] = new List <int>();

            Assert.Equal(expectedAdjacencyListVertices, graph.AdjacencyList.Vertices);
            Assert.Equal(expectedAdjacencyListEdges, graph.AdjacencyList.Edges);
        }
예제 #9
0
        public GraphPart findPart(GraphPart start)
        {
            GraphPart p = new GraphPart();

            foreach (Vertex v in start.Vertices)
            {

                if (p.Vertices.Contains(v)) { continue; }

                Stack<Vertex> st = new Stack<Vertex>();
                st.Push(v);

                while (st.Count != 0)
                {
                    Vertex act = st.Pop();
                    p.Vertices.Add(act);

                    foreach (IEdge e in innerGraph.nextEdges(act))
                    {
                        Vertex son;
                        if (!p.Edges.Contains(e)) { p.Edges.Add(e); }

                        if (e.Vertex_1 == act) { son = e.Vertex_2; }
                        else {son= e.Vertex_1;}

                        if (!p.Vertices.Contains(son)) {st.Push(son); }
                    }

                }

            }

            return p;
        }
예제 #10
0
        public void moveGraphPartToLayer(GraphPart p, string targetLayer)
        {
            Layer l = null;

            foreach (Layer lay in layers)
            {
                if (lay.Name == targetLayer)
                {
                    l = lay; break;
                }
            }

            if (l == null || p == null)
            {
                return;
            }

            l.PartOfGraph.Union(p);

            foreach (IEdge e in p.Edges)
            {
                dictEdge[e].PartOfGraph.Edges.Remove(e);
                dictEdge[e] = l;
            }

            foreach (Vertex v in p.Vertices)
            {
                dictVertex[v].PartOfGraph.Vertices.Remove(v);
                dictVertex[v] = l;
            }
        }
예제 #11
0
        public void AddEdgeTest()
        {
            var graph = _graphService.NewGraph(true);
            var nodeA = _graphService.AddNode(ref graph, "nodeA");
            var nodeB = _graphService.AddNode(ref graph, "nodeB");
            var nodeC = _graphService.AddNode(ref graph, "nodeC");

            _graphService.AddEdge(nodeA, nodeB, ref graph, 10.0D);
            GraphPart graphPart = graph.GraphPart.ToList().Find(part => part.Node.Uid == nodeA.Uid);

            Assert.That(graphPart.IsNotNull);
            Edge edgeFromAToB = graphPart.Edge.ToList().Find(edge => edge.Destination.Uid == nodeB.Uid);

            Assert.NotNull(edgeFromAToB);
            Assert.That(edgeFromAToB.Weight.IsNotNull);
            Assert.That(edgeFromAToB.Uid.IsNotNull);
            Assert.That(edgeFromAToB.Weight == 10.0D);
            // Assert.NotNull(edgeFromAToB.GraphPart); - nie można sprawdzić bo ustawia to pole entity framework

            _graphService.AddEdge(nodeA, nodeB, ref graph, 5.0D);
            GraphPart graphPart1 = graph.GraphPart.ToList().Find(part => part.Node.Uid == nodeA.Uid);

            Assert.That(graphPart1.IsNotNull);
            Assert.That(graphPart.Edge.Count == 1);
            Edge edgeFromAToBMod = graphPart.Edge.ToList().Find(edge => edge.Destination.Uid == nodeB.Uid);

            Assert.NotNull(edgeFromAToBMod);
            Assert.That(edgeFromAToBMod.Weight == 5.0D);
            Assert.That(edgeFromAToB.Uid == edgeFromAToBMod.Uid);
        }
예제 #12
0
        public void PushPartWithControl(GraphPart g)
        {
            switch (innerActOp)
            {
            case Operation.Union:
            {
                innerGp.Union(g);

                break;
            }

            case Operation.Intersect:
            {
                innerGp.Intersect(g);
                break;
            }

            case Operation.Except:
            {
                innerGp.Except(g);
                break;
            }
            }

            innerFilter.filterPart(innerGp);
        }
예제 #13
0
        public GraphPart PopSelectedPart()
        {
            GraphPart g = innerGp;

            innerGp = new GraphPart();
            return(g);
        }
예제 #14
0
        public void TestGraphDegrees_3PointsTriangleNotDirected_VertexDegrees()
        {
            Point3d   pointA     = new Point3d(0.01, 0.2, 0.5);
            Point3d   pointB     = new Point3d(1, 7, 10);
            Point3d   pointC     = new Point3d(1.2, 5.3, 10);
            GraphPart graphPart1 = new GraphPart(pointA, pointB, false);
            GraphPart graphPart2 = new GraphPart(pointB, pointC, false);
            GraphPart graphPart3 = new GraphPart(pointC, pointA, false);

            Graph graph = new Graph(new List <GraphPart> {
                graphPart1, graphPart2, graphPart3
            }, 0.001);

            Assert.Equal(4, graph.GetVertexDegree(0));
            Assert.Equal(2, graph.GetVertexOutdegree(0));
            Assert.Equal(2, graph.GetVertexIndegree(0));

            Assert.Equal(4, graph.GetVertexDegree(1));
            Assert.Equal(2, graph.GetVertexOutdegree(1));
            Assert.Equal(2, graph.GetVertexIndegree(1));

            Assert.Equal(4, graph.GetVertexDegree(2));
            Assert.Equal(2, graph.GetVertexOutdegree(2));
            Assert.Equal(2, graph.GetVertexIndegree(2));
        }
예제 #15
0
        /// <summary>
        /// Return all cycles in grpah
        /// </summary>
        /// <returns></returns>
        public GraphPart getInvalidPart()
        {
            GraphPart gr = new GraphPart();

            // gr = najdiKruznici();

            return(gr);
        }
예제 #16
0
        public Node AddNode(ref Graph graph, string label)
        {
            string    uid       = Guid.NewGuid().ToString();
            Node      node      = new Node(label, uid);
            GraphPart graphPart = NewGraphPart(node);

            graph.GraphPart.Add(graphPart);
            return(node);
        }
예제 #17
0
        /// <summary>
        /// Create string with defined name
        /// </summary>
        /// <param name="name"></param>
        public Layer(string name)
        {
            innerName   = name;
            innerPart   = new GraphPart();
            locked      = false;
            lockedSaved = false;

            visible = true;
        }
예제 #18
0
        /// <summary>
        /// Create string with defined name
        /// </summary>
        /// <param name="name"></param>
        public Layer(string name)
        {
            innerName = name;
            innerPart = new GraphPart();
            locked = false;
            lockedSaved = false;

            visible = true;
        }
예제 #19
0
        public GraphPart getInvalidPart()
        {
            GraphPart gp = new GraphPart();

            foreach (Vertex v in innerGraph.Vertices)
            {
                if (innerGraph.nextEdges(v).Count != innerK) { gp.Vertices.Add(v); }
            }

            return gp;
        }
예제 #20
0
        public Edge IsEdgeExists(Node source, Node dest, Graph graph)
        {
            GraphPart partGraph = graph.GraphPart.ToList().Find(part => part.Node.Uid == source.Uid);
            Edge      edge      = partGraph.Edge.ToList().Find(x => x.Destination.Uid == dest.Uid);

            if (edge.IsNotNull())
            {
                return(edge);
            }
            return(null);
        }
예제 #21
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Curve curve      = null;
            bool  isDirected = true;

            DA.GetData(0, ref curve);
            DA.GetData(1, ref isDirected);

            GraphPart graphPart = new GraphPart(curve, isDirected);

            DA.SetData(0, graphPart);
        }
예제 #22
0
        public void TestGraphDegrees_2Points_Degree()
        {
            Point3d   pointA    = new Point3d(0.01, 0.2, 0.5);
            Point3d   pointB    = new Point3d(1, 7, 10);
            GraphPart graphPart = new GraphPart(pointA, pointB, false);

            Graph graph = new Graph(new List <GraphPart> {
                graphPart
            }, 0.001);

            Assert.Equal(2, graph.GetGraphDegree());
        }
예제 #23
0
        private async Task <int> getMinPathWeight(int grapid, GraphPart from, GraphPart to)
        {
            int weight = await _apiService.GetMinimalPathWeight(grapid, from.Node.Label, to.Node.Label);

            if (weight >= 0)
            {
                return(weight);
            }
            else
            {
                return(0);
            }
        }
예제 #24
0
        public Node AddNode(ref Graph graph, string label)
        {
            Node node = new Node(label)
            {
                Uid = Guid.NewGuid().ToString()
            };
            GraphPart graphPart = new GraphPart {
                Uid = Guid.NewGuid().ToString(), Edge = new List <Edge>(), Node = node
            };

            graph.GraphPart.Add(graphPart);
            return(node);
        }
예제 #25
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GraphPart graphPart = null;

            DA.GetData(0, ref graphPart);

            DA.SetDataList(0, new List <Point3d> {
                graphPart.StartVertex, graphPart.EndVertex
            });
            DA.SetData(1, graphPart.Edge);
            DA.SetData(2, graphPart.IsDirected);
            DA.SetData(3, graphPart.EdgeWeight);
        }
예제 #26
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Point3d pointA     = Point3d.Unset;
            Point3d pointB     = Point3d.Unset;
            bool    isDirected = true;

            DA.GetData(0, ref pointA);
            DA.GetData(1, ref pointB);
            DA.GetData(2, ref isDirected);

            GraphPart graphPart = new GraphPart(pointA, pointB, isDirected);

            DA.SetData(0, graphPart);
        }
예제 #27
0
        public GraphPart getInvalidPart()
        {
            GraphPart gp = new GraphPart();

            foreach (Vertex v in innerGraph.Vertices)
            {
                if (innerGraph.nextEdges(v).Count != innerK)
                {
                    gp.Vertices.Add(v);
                }
            }

            return(gp);
        }
예제 #28
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Vector3d vector     = Vector3d.Unset;
            Point3d  point      = Point3d.Unset;
            bool     isDirected = true;

            DA.GetData(0, ref vector);
            DA.GetData(1, ref point);
            DA.GetData(2, ref isDirected);

            GraphPart graphPart = new GraphPart(vector, point, isDirected);

            DA.SetData(0, graphPart);
        }
예제 #29
0
        public void TestGraphDegrees_3Points_Degree()
        {
            Point3d   pointA     = new Point3d(0.01, 0.2, 0.5);
            Point3d   pointB     = new Point3d(1, 7, 10);
            Point3d   pointC     = new Point3d(1.2, 5.3, 10);
            GraphPart graphPart1 = new GraphPart(pointA, pointB, true);
            GraphPart graphPart2 = new GraphPart(pointB, pointC, true);

            Graph graph = new Graph(new List <GraphPart> {
                graphPart1, graphPart2
            }, 0.001);

            Assert.Equal(2, graph.GetGraphDegree());
        }
예제 #30
0
 private void processAllDestinations(GraphPart part)
 {
     foreach (Edge edge in part.Edge)
     {
         GraphPart edgeDestinationPart = toProcess.Find(x => x.Node.Label == edge.Destination.Label);
         if (edgeDestinationPart == null)
         {
             continue;
         }
         if (d[graph.GraphPart.IndexOf(edgeDestinationPart)] > (d[graph.GraphPart.IndexOf(part)] + edge.Weight))
         {
             d[graph.GraphPart.IndexOf(edgeDestinationPart)] = d[graph.GraphPart.IndexOf(part)] + edge.Weight;
             p[graph.GraphPart.IndexOf(edgeDestinationPart)] = part;
         }
     }
 }
예제 #31
0
        public void TestGraphPartConstructor_2Points()
        {
            Point3d pointA     = new Point3d(0.01, 0.2, 0.5);
            Point3d pointB     = new Point3d(1, 7, 10);
            bool    isDirected = false;

            GraphPart graphPart = new GraphPart(pointA, pointB, isDirected);

            Assert.Equal(0.01, graphPart.StartVertex.X);
            Assert.Equal(0.2, graphPart.StartVertex.Y);
            Assert.Equal(0.5, graphPart.StartVertex.Z);
            Assert.Equal(1, graphPart.EndVertex.X);
            Assert.Equal(7, graphPart.EndVertex.Y);
            Assert.Equal(10, graphPart.EndVertex.Z);
            Assert.False(graphPart.IsDirected);
        }
예제 #32
0
        public void TestGraphPartConstructor_PointAndVector()
        {
            Point3d  point      = new Point3d(0.01, 0.2, 0.5);
            Vector3d vector     = new Vector3d(1, 7, 10);
            bool     isDirected = true;

            GraphPart graphPart = new GraphPart(vector, point, isDirected);

            Assert.Equal(0.01, graphPart.StartVertex.X);
            Assert.Equal(0.2, graphPart.StartVertex.Y);
            Assert.Equal(0.5, graphPart.StartVertex.Z);
            Assert.Equal(1.01, graphPart.EndVertex.X);
            Assert.Equal(7.2, graphPart.EndVertex.Y);
            Assert.Equal(10.5, graphPart.EndVertex.Z);
            Assert.True(graphPart.IsDirected);
        }
예제 #33
0
        public GraphPart findPart(GraphPart start)
        {
            GraphPart p = new GraphPart();

            foreach (Vertex v in start.Vertices)
            {
                if (p.Vertices.Contains(v))
                {
                    continue;
                }

                Stack <Vertex> st = new Stack <Vertex>();
                st.Push(v);


                while (st.Count != 0)
                {
                    Vertex act = st.Pop();
                    p.Vertices.Add(act);

                    foreach (IEdge e in innerGraph.nextEdges(act))
                    {
                        Vertex son;
                        if (!p.Edges.Contains(e))
                        {
                            p.Edges.Add(e);
                        }

                        if (e.Vertex_1 == act)
                        {
                            son = e.Vertex_2;
                        }
                        else
                        {
                            son = e.Vertex_1;
                        }

                        if (!p.Vertices.Contains(son))
                        {
                            st.Push(son);
                        }
                    }
                }
            }

            return(p);
        }
예제 #34
0
        public void filterPart(GraphPart gp)
        {
            List<IEdge> forRemove = new List<IEdge>();

            foreach (IEdge e in gp.Edges)
            {
                if (!gp.Vertices.Contains(e.Vertex_1) || !gp.Vertices.Contains(e.Vertex_2))
                {
                    forRemove.Add(e);
                }
            }

            foreach (IEdge e in forRemove)
            {
                gp.Edges.Remove(e);
            }
        }
예제 #35
0
        /// <summary>
        /// Return all cycles in grpah
        /// </summary>
        /// <returns></returns>
        public GraphPart getInvalidPart()
        {
            GraphPart gr = new GraphPart();
            // gr = najdiKruznici();

            return gr;
        }