/// <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); }
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); } }
public void AddEdge(Node edge) { if (!Edges.Contains(edge)) { Edges.Add(edge); edge.AddEdge(this); } }
/// <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))); }
/// <summary> /// Удаление существующего ребра /// </summary> protected void RemoveEdge(TE edge) { if (!Edges.Contains(edge)) { throw new Exception("Такого ребра не существует"); } edge.Previous.NextVertex.Remove(edge); }
/// <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)); }
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))); }
public void AddEdge(ISimpleGraphEdge <T> edge) { if (!Edges.Contains(edge)) { Edges.Add(edge); } TopologicalSort(); }
public void SetEdgeWeight(IEdge edge, double weight) { if (Edges.Contains(edge)) { edge.Weight = weight; } else { throw new ArgumentException("Edge not found"); } }
/// <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); }
/// <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); }
/// <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(); }
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); } }
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); }
/// <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); } }
/// <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); } } }
// ----------------------------------------------------------------------------/// /// <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); }
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); } }
/// <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); } }
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); }
public bool ContainsEdge(Relation <T, P> relation) { return(Edges.Contains(relation)); }
public bool IsMatchFor(Face face) { return(face.Edges.All(e => Edges.Contains(e))); }
public bool ContainsEdge(object edge) => Edges.Contains(edge);
/// <summary> /// Contains method for Edges in graph /// </summary> /// <param name="edge"></param> /// <returns></returns> public bool Contains(Edge edge) { return(Edges.Contains(edge)); }