Example #1
0
        /// <summary>
        /// Removes an edge, if the edge doesn't exist then nothing happens.
        /// </summary>
        /// <param name="edge">edge reference</param>
        virtual public void RemoveEdge(Edge edge)
        {
            if (edge == null)
            {
                return;
            }
            if (!Edges.Contains(edge))
            {
                return;
            }
            Node source = edge.SourceNode;
            Node target = edge.TargetNode;

            if (source != target)
            {
                source.RemoveOutEdge(edge);
                target.RemoveInEdge(edge);
            }
            else
            {
                source.RemoveSelfEdge(edge);
            }
            Edges.Remove(edge);
            GeometryGraph.RemoveEdge(edge.GeometryObject as Msagl.Edge);
        }
Example #2
0
 public void AddEdge(Edge edge)
 {
     if (!Edges.Contains(edge))
     {
         Edges.Add(edge);
     }
 }
 /// <summary>
 /// Adds the edge.
 /// </summary>
 /// <param name="argEdge">
 /// The argument edge.
 /// </param>
 private void AddEdge(EdgeItem argEdge)
 {
     if (!Edges.Contains(argEdge))
     {
         Edges.Add(argEdge);
     }
 }
Example #4
0
 public void AddEdge(Node edge)
 {
     if (!Edges.Contains(edge))
     {
         Edges.Add(edge);
         edge.AddEdge(this);
     }
 }
Example #5
0
 /// <summary>
 /// Finds edge that connects to the vertex and is not equal to given edge.
 /// </summary>
 /// <param name="a_edge"></param>
 /// <param name="a_vertex"></param>
 /// <returns></returns>
 public TriangleEdge OtherEdge(TriangleEdge a_edge, Vector2 a_vertex)
 {
     if (!Edges.Contains(a_edge) || !Vertices.Contains(a_vertex))
     {
         throw new GeomException("Edge or vertex not contained in triangle");
     }
     return(Edges.Find(e => e != a_edge && e.IsEndpoint(a_vertex)));
 }
Example #6
0
 /// <summary>
 /// Удаление существующего ребра
 /// </summary>
 protected void RemoveEdge(TE edge)
 {
     if (!Edges.Contains(edge))
     {
         throw new Exception("Такого ребра не существует");
     }
     edge.Previous.NextVertex.Remove(edge);
 }
Example #7
0
 /// <summary>
 /// Finds the edge that is not equal to given two.
 /// </summary>
 /// <param name="a_edge0"></param>
 /// <param name="a_edge1"></param>
 /// <returns></returns>
 public TriangleEdge OtherEdge(TriangleEdge a_edge0, TriangleEdge a_edge1)
 {
     if (!Edges.Contains(a_edge0) || !Edges.Contains(a_edge1))
     {
         throw new GeomException("One of the edges not contained in triangle");
     }
     return(Edges.Find(e => e != a_edge0 && e != a_edge1));
 }
Example #8
0
        public Edge GetOppositeSide(Edge side)
        {
            if (!Edges.Contains(side))
            {
                throw new Exception("Side is not part of this quadrangle.");
            }

            return(Edges.Find(s => !s.HasVertex(side.A) && !s.HasVertex(side.B)));
        }
Example #9
0
        public void AddEdge(ISimpleGraphEdge <T> edge)
        {
            if (!Edges.Contains(edge))
            {
                Edges.Add(edge);
            }

            TopologicalSort();
        }
Example #10
0
 public void SetEdgeWeight(IEdge edge, double weight)
 {
     if (Edges.Contains(edge))
     {
         edge.Weight = weight;
     }
     else
     {
         throw new ArgumentException("Edge not found");
     }
 }
Example #11
0
 /// <summary>
 /// Adds an edge to the graph
 /// </summary>
 /// <param name="first">First vertex</param>
 /// <param name="second">Second vertex</param>
 /// <param name="data">Data saved in edge</param>
 /// <returns>Reference to the created edge</returns>
 public void AddEdge(Edge edge)
 {
     AssertEdge(edge);
     if (Edges.Contains(edge))
     {
         throw new System.ArgumentException("Edge already present in Graph!");
     }
     Edges.Add(edge);
     edge.V1.Edges.Add(edge);
     edge.V2.Edges.Add(edge);
 }
Example #12
0
 /// <summary>
 /// removes an edge from the graph
 /// </summary>
 /// <param name="edge">Edge to remove</param>
 public void RemoveEdge(Edge edge)
 {
     AssertEdge(edge);
     if (!Edges.Contains(edge))
     {
         throw new System.ArgumentException("Edge not in Graph!");
     }
     Edges.Remove(edge);
     // remove the edge from both end vertices
     edge.V1.Edges.Remove(edge);
     edge.V2.Edges.Remove(edge);
 }
Example #13
0
 /// <summary>
 /// Adding edge to graph, if it still doesn't exist in graph. And adding vertexes FROM and TO if they still doesn't exist in graph.
 /// </summary>
 /// <param name="from"></param>
 /// <param name="to"></param>
 /// <param name="weight"></param>
 public void AddEdge(Edge edge)
 {
     //TODO: check coming data to class MYGRAPH.
     if (!Edges.Contains(edge))
     {
         Edges.Add(edge);
     }
     AddVertex(edge.From);
     AddVertex(edge.To);
     MaxLength      += edge.Weight;
     AllShortestWays = HelpGetAllShortestWays();
 }
Example #14
0
        public static IEnumerable <Edge> Split(this Edges edges)
        {
            if (edges.Contains(Edge.Top))
            {
                yield return(Edge.Top);
            }

            if (edges.Contains(Edge.Bottom))
            {
                yield return(Edge.Bottom);
            }

            if (edges.Contains(Edge.Left))
            {
                yield return(Edge.Left);
            }

            if (edges.Contains(Edge.Right))
            {
                yield return(Edge.Right);
            }
        }
Example #15
0
        public Edges TriangleEdges(Triangles triangles)
        {
            if (triangles == null)
            {
                return(null);
            }

            Edges edges = new Edges();
            int   max   = triangles.Count;
            int   pos   = 0;

            foreach (Triangle triangle in triangles)
            {
                Edge e1 = new Edge(triangle.p1, triangle.p2);
                Edge e2 = new Edge(triangle.p1, triangle.p3);
                Edge e3 = new Edge(triangle.p2, triangle.p3);

                if (!edges.Contains(e1))
                {
                    edges.Add(e1);
                }
                if (!edges.Contains(e2))
                {
                    edges.Add(e2);
                }
                if (!edges.Contains(e3))
                {
                    edges.Add(e3);
                }

                if (Progress != null)
                {
                    Progress(pos++, max);
                }
            }

            return(edges);
        }
Example #16
0
        /// <summary>
        /// Добавление вершины в одну сторону
        /// </summary>
        protected void AddEdge(TE edge)
        {
            var c = (Edges.Where(w => (edge.Previous == w.Previous) && (w.NextVertex == edge.NextVertex))).ToArray();

            if (Edges.Contains(edge) || c.Any())
            {
                throw new Exception("Ребро уже присутствует в графе " + edge.Previous.Name + " -> " + edge.NextVertex.Name);
            }
            if (Vertex.Contains(edge.Previous) && Vertex.Contains(edge.NextVertex))
            {
                NameVertex[edge.Previous.Name].NextVertex.Add(edge);
            }
            else
            {
                IsExistVertex(edge.NextVertex.Name);
                IsExistVertex(edge.Previous.Name);
            }
        }
Example #17
0
 /// <summary>
 /// Adds a vertex to the graph
 /// </summary>
 /// <returns>Reference to the created vertex</returns>
 public void AddVertex <TVertex>(TVertex vertex) where TVertex : Vertex
 {
     if (vertex == null)
     {
         throw new ArgumentException("Can't add a vertex that is null!");
     }
     if (Vertices.Contains(vertex))
     {
         throw new ArgumentException("Can't add a vertex twice! " + vertex);
     }
     Vertices.Add(vertex);
     foreach (var edge in vertex.Edges)
     {
         if (!Edges.Contains(edge))
         {
             Edges.Add(edge);
         }
     }
 }
Example #18
0
        // ----------------------------------------------------------------------------///

        /// <summary>
        /// Adds a vertex to the graph
        /// </summary>
        /// <param name="data">Data saved in vertex</param>
        /// <returns>Reference to the created vertex</returns>
        public VType AddVertex <VType>(VType vertex) where VType : Vertex
        {
            if (vertex == null)
            {
                throw new System.ArgumentException("Can't add a vertex that is null!");
            }
            if (Vertices.Contains(vertex))
            {
                throw new System.ArgumentException("Can't add a vertex twice! " + vertex);
            }
            Vertices.Add(vertex);
            foreach (var edge in vertex.Edges)
            {
                if (!Edges.Contains(edge))
                {
                    Edges.Add(edge);
                }
            }
            return(vertex);
        }
Example #19
0
        public void Connect(int from, int to)
        {
            NodeViewModel fromNode = Nodes.First(i => i.Key == from);
            NodeViewModel toNode   = Nodes.First(i => i.Key == to);

            var edge1 = new EdgeViewModel(new SwapablePair <NodeViewModel>(fromNode, toNode));
            var edge2 = new EdgeViewModel(new SwapablePair <NodeViewModel>(toNode, fromNode));

            if (!Edges.Contains(edge1) && !Edges.Contains(edge2))
            {
                Edges.Add(edge1);
            }
            else if (Edges.Contains(edge1))
            {
                Edges.Remove(edge1);
            }
            else if (Edges.Contains(edge2))
            {
                Edges.Remove(edge2);
            }
        }
Example #20
0
        /// <summary>
        /// Add edge to the analisys graph
        /// </summary>
        /// <param name="edge">New edge</param>
        public void AddEdge(Edge edge)
        {
            List <Edge> startEdgesList = new List <Edge>();
            List <Edge> endEdgesList   = new List <Edge>();

            if (_vertexEdgesDict.TryGetValue(edge.StartVertex, out startEdgesList))
            {
                if (!startEdgesList.Contains(edge))
                {
                    startEdgesList.Add(edge);
                }
            }
            else
            {
                _vertexEdgesDict.Add(edge.StartVertex, new List <Edge>()
                {
                    edge
                });
            }

            if (_vertexEdgesDict.TryGetValue(edge.EndVertex, out endEdgesList))
            {
                if (!endEdgesList.Contains(edge))
                {
                    endEdgesList.Add(edge);
                }
            }
            else
            {
                _vertexEdgesDict.Add(edge.EndVertex, new List <Edge>()
                {
                    edge
                });
            }

            if (!Edges.Contains(edge))
            {
                Edges.Add(edge);
            }
        }
Example #21
0
        private bool IsMatch(string key, out string matchingEdge)
        {
            matchingEdge = null;
            string reversedKey = Reverse(key);

            //if (key == reversedKey) throw new Exception($"{key} is a palindrome");

            if (Edges.Contains(key))
            {
                matchingEdge = key;
                return(true);
            }
            else
            {
                if (Edges.Contains(reversedKey))
                {
                    matchingEdge = reversedKey;
                    return(true);
                }
            }
            return(false);
        }
Example #22
0
 public bool ContainsEdge(Relation <T, P> relation)
 {
     return(Edges.Contains(relation));
 }
Example #23
0
 public bool IsMatchFor(Face face)
 {
     return(face.Edges.All(e => Edges.Contains(e)));
 }
Example #24
0
 public bool ContainsEdge(object edge) => Edges.Contains(edge);
Example #25
0
 /// <summary>
 /// Contains method for Edges in graph
 /// </summary>
 /// <param name="edge"></param>
 /// <returns></returns>
 public bool Contains(Edge edge)
 {
     return(Edges.Contains(edge));
 }