public void Add(Edge edge, Vertex vertex1, Vertex vertex2) { Edges?.Add(edge); //добавить изменние в матрице инциндетности AdjacencyMatrix.AddEdge(vertex1.Id - 1, vertex2.Id - 1); }
public void AddNode(int node) { if (node < 0) { return; } if (!Nodes.Contains(node)) { Nodes.Add(node); } if (Edges.Count <= node) { for (int i = Edges.Count; i <= node; i++) { Edges.Add(new List <float?>()); } } }
public void AddEdge(IVertex from, IVertex to, string label, double cost = 0.0) { switch (Type) { case GraphType.Directed: Edges.Add(new Edge { Cost = cost, From = from, To = to, Label = label }); break; case GraphType.Undirected: Edges.Add(new Edge { Cost = cost, From = from, To = to, Label = label }); Edges.Add(new Edge { Cost = cost, From = to, To = from, Label = label }); break; } }
/// <summary> /// Scan the supplied enumerable and collect nodes, edges and graphs /// </summary> /// <param name="content">Enumerator to scan</param> public void Scan(IEnumerable content) { foreach (var o in content) { if (o == null) { continue; } var node = o as Node; if (node != null) { Nodes.Add(node); continue; } var edge = o as Edge; if (edge != null) { Edges.Add(edge); continue; } var graph = o as Graph; if (graph != null) { Graphs.Add(graph); continue; } var enumerable = o as IEnumerable; if (enumerable != null) { Scan(enumerable); continue; } var message = string.Format("Instance of type {0} not supported", o.GetType()); throw new InvalidOperationException(message); } }
/// <summary> /// Add the edges of the mesh /// </summary> public void AddEdges() { int counter = 0; for (int i = 0; i < (NU + 1); i++) { for (int j = 0; j < (NV); j++) { Edges.Add(new UVMeshEdge(this, this.Vertices[j * (NU + 1) + i], this.Vertices[(j + 1) * (NU + 1) + i], counter)); counter++; } } for (int i = 0; i < (NV + 1); i++) { for (int j = 0; j < (NU); j++) { Edges.Add(new UVMeshEdge(this, this.Vertices[j * (NU + 1) + i], this.Vertices[j * (NU + 1) + i + 1], counter)); counter++; } } }
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); } }
protected void AddEdgeForNode(INode node, IEdge edge) { if (Edges.ContainsKey(node)) { if (Edges[node].Contains(edge)) { throw new ArgumentException( string.Format("The edge {0}-{1} already exists for node {2}", edge.FirstNode.ID, edge.SecondNode.ID, node.ID)); } Edges[node].Add(edge); } else { IList <IEdge> edges = new List <IEdge>(); edges.Add(edge); Edges.Add(node, edges); } }
/// <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 void SmartGraphPathParentChanged() { GraphVM previous = Graph; Graph = GraphPath?.Parent; if (Graph != null && Graph == previous) { return; } previous = Graph; Nodes.Clear(); Edges.Clear(); NodesNames.Clear(); EdgesPath.Clear(); NodesPathOrder.Clear(); if (Graph == null) { return; } positioner = new CircleGraphPositioner(Graph); double actualWidth = ActualWidth; double actualHeight = ActualHeight; foreach (var node in Graph.Nodes) { Nodes[node] = CalculatePosition(node, NodesMargin, actualWidth, actualHeight); NodesNames[node] = CalculatePosition(node, NamesMargin, actualWidth, actualHeight); } foreach (var edge in Graph.Edges) { Edges.Add(edge); } ++ChangeCount; }
/// <summary> /// Adds the edge. /// </summary> /// <param name="edge">The edge.</param> internal void AddEdge(Edge edge) { var vertFromIndex = Vertices.IndexOf(edge.From); var vertToIndex = Vertices.IndexOf(edge.To); int index; var lastIndex = Vertices.Count - 1; if ((vertFromIndex == 0 && vertToIndex == lastIndex) || (vertFromIndex == lastIndex && vertToIndex == 0)) { index = lastIndex; } else { index = Math.Min(vertFromIndex, vertToIndex); } while (Edges.Count <= index) { Edges.Add(null); } Edges[index] = edge; }
public Ngon(double[][] edgeVectors) { this.EdgeVectors = encodeArray(edgeVectors); this.Verticies = new List <Vertex>(); this.Edges = new List <Edge>(); double[] cumulative = new double[] { 0, 0 }; foreach (double[] entry in edgeVectors) { Vertex from = new Vertex(cumulative[0], cumulative[1]); Verticies.Add(from); cumulative[0] += entry[0]; cumulative[1] += entry[1]; Vertex to = new Vertex(cumulative[0], cumulative[1]); Edges.Add(new Edge(to, from, entry)); } if (Math.Round(cumulative[0], 8) != 0 && Math.Round(cumulative[1], 8) != 0) { throw (new Exception("Ngon is not closed!")); } calculateAngles(); this.Type = getType(); }
public IEdge AddEdge(object from, object to) { if (!(from is double) || !(to is double)) { throw new ArgumentException("Only double accepted"); } if (!Nodes.ContainsKey(from) || !Nodes.ContainsKey(to)) { throw new ArgumentException("Node not find"); } if ((double)from == (double)to) { throw new ArgumentException("No loop"); } IEdge e = new DefaultUndirectedEdge(); e.From = from; e.To = to; Edges.Add(e); return(e); }
public void Barabasi_Albert()//модель Барабаши-Альберта { GenerateInitGraphics(InitverticesNumber); for (int iCount = InitverticesNumber; iCount < MaxverticesNumber; iCount++) { Vertices.Add(iCount); int targetVertice = FindTheNextToConnect(); Edges.Add(iCount, new List <int>() { targetVertice }); if (Edges[targetVertice] == null) { Edges[targetVertice] = new List <int>(); } Edges[targetVertice].Add(iCount); } }
public PolygonDrawResult AddVerticleAndDraw(MyPoint p) { if (MyPoint.AreNear(p, StartingVerticle, (double)Globals.VerticleClickRadiusSize / 2.0) == true) { if (Edges.Count < 2) { return(PolygonDrawResult.NotEnoughEdges); } MyEdge e = new MyEdge(LastVerticle, StartingVerticle); Draw.Edge(e, canvas); Edges.Add(e); return(PolygonDrawResult.DrawFinished); } else { Draw.Verticle(p, canvas); MyEdge e = new MyEdge(LastVerticle, p); Draw.Edge(e, canvas); LastVerticle = p; Edges.Add(e); return(PolygonDrawResult.DrawInProgress); } }
public void AddCountur(Contour cnt) { Conturs.Add(cnt); cnt.Points.ForEach(x => { if (Vertexs.FindIndex(y => y.X == x.X && y.Y == x.Y) == -1) { Vertexs.Add(cnt.Points.FindAll(y => y.X == x.X && y.Y == x.Y).First()); } }); //Все ребра кроме последнего for (int i = 0; i < cnt.Points.Count - 1; i++) { int pointFirst = Vertexs.FindIndex(y => y.X == cnt.Points[i].X && y.Y == cnt.Points[i].Y); int pointSecond = Vertexs.FindIndex(y => y.X == cnt.Points[i + 1].X && y.Y == cnt.Points[i + 1].Y); Edges.Add(new Edge(pointFirst, pointSecond)); } //Последнее ребро из конца в начало Edges.Add(new Edge( Vertexs.FindIndex(y => y.X == cnt.Points[0].X && y.Y == cnt.Points[0].Y), Vertexs.FindIndex(y => y.X == cnt.Points[cnt.Points.Count - 1].X && y.Y == cnt.Points[cnt.Points.Count - 1].Y))); //Перекраиваем карту навигации CurrentNodesMap = InitNavMap(); }
public void Fill(int numVertices, int numEdges, int numFaces) { Clear(); Vertices.Capacity = numVertices; Edges.Capacity = numEdges; Faces.Capacity = numFaces; for (int i = 0; i < numVertices; i++) { Vertices.Add(new VERTEX()); } for (int i = 0; i < numEdges; i++) { Edges.Add(new EDGE()); } for (int i = 0; i < numFaces; i++) { Faces.Add(new FACE()); } }
public SimpleOrderedLayoutWithSubgraph() : base("Simple Graph (ordered layout with subgraph)") { var a = new StandardItem("A"); var b = new CompositeItem("B"); var b1 = new StandardItem("B1"); var b2 = new StandardItem("B2"); var b3 = new StandardItem("B3"); var b4 = new StandardItem("B4"); var c = new StandardItem("C"); var d = new StandardItem("D"); Edges.Add(new Edge(a, b)); Edges.Add(new Edge(a, c)); Edges.Add(new Edge(b, d)); Edges.Add(new Edge(c, d)); Edges.Add(new Edge(b1, b2)); Edges.Add(new Edge(b1, b3)); Edges.Add(new Edge(b2, b4)); Edges.Add(new Edge(b3, b4)); Parent[b1] = b; Parent[b2] = b; Parent[b3] = b; Parent[b4] = b;
//??????????????? public void AddAdjacencyList(int idVertex, Dictionary <int, double> adjDictionary) { int indexL = idZeroStart ? idVertex : idVertex - 1; Vertex vertexL = Vertices[indexL]; foreach (var v in adjDictionary) { int idR = v.Key; double weight = v.Value; int indexR = idZeroStart ? idR : idR - 1; Vertex vertexR = Vertices[indexR]; Edge edge = new Edge(vertexL, vertexR, weight, IsDirectedGraph); Edges.Add(edge); if (Matrix != null) { Matrix[indexL, indexR] = weight; if (!IsDirectedGraph) { Matrix[indexR, indexL] = weight; } } } }
public void AddEdge(int edgeId, int vertexVal1, int vertexVal2, int weight) { Vertex vertex1 = Verticies.FirstOrDefault(item => item.Id == vertexVal1); Edge edge = new Edge(edgeId); if (vertex1 != null) { vertex1 = Verticies[vertexVal1]; } else { vertex1 = new Vertex(vertexVal1); Verticies.Add(vertex1); } Vertex vertex2 = Verticies.FirstOrDefault(item => item.Id == vertexVal2); if (vertex2 != null) { vertex2 = Verticies[vertexVal2]; } else { vertex2 = new Vertex(vertexVal2); Verticies.Add(vertex2); } edge.StartVertex = vertexVal1; edge.EndVertex = vertexVal2; edge.Weight = weight; Edges.Add(edge); vertex1.ForwardEdges.Add(edge.Id); vertex2.BackwardEdges.Add(edge.Id); Console.WriteLine(edgeId + ". " + vertexVal1 + " - " + vertexVal2 + " - " + weight); }
public void AddEdge(long id1, long id2, int weight) { Vertex vertex1 = null; if (Verticies.ContainsKey(id1)) { vertex1 = Verticies[id1]; } else { vertex1 = new Vertex(id1); Verticies[id1] = vertex1; } Vertex vertex2 = null; if (Verticies.ContainsKey(id2)) { vertex2 = Verticies[id2]; } else { vertex2 = new Vertex(id2); Verticies[id2] = vertex2; } Edge edge = new Edge(vertex1, vertex2, IsDirected, weight); Edges.Add(edge); vertex1.AddAdjacentVertex(edge, vertex2); if (!IsDirected) { vertex2.AddAdjacentVertex(edge, vertex1); } }
public Graph.ILaneRow Advance() { var newLaneRow = new SavedLaneRow(this); var newEdges = new Edges(); for (int i = 0; i < edges.CountNext(); i++) { int edgeCount = edges.CountNext(i); if (edgeCount > 0) { Graph.LaneInfo info = edges.Next(i, 0).Clone(); for (int j = 1; j < edgeCount; j++) { Graph.LaneInfo edgeInfo = edges.Next(i, j); info.UnionWith(edgeInfo); } newEdges.Add(i, info); } } edges = newEdges; return(newLaneRow); }
public void AddVertexOnEdge(Point edgePoint, Edge edge) { _window.DrawPoints(edge.Points, DefaultColor); ParallelPairs.RemoveAll(pair => pair.Edges.Contains(edge.Id)); var prevVertex = edge.Vertices[0]; var nextVertex = edge.Vertices[1]; var maxVertexId = Vertices.Select(v => v.Id).Max(); var maxEdgeId = Edges.Select(e => e.Id).Max(); var prevEdgePoints = GetLine(edgePoint.X, edgePoint.Y, prevVertex.Point.X, prevVertex.Point.Y); var nextEdgePoints = GetLine(edgePoint.X, edgePoint.Y, nextVertex.Point.X, nextVertex.Point.Y); var newVertex = new Vertex(maxVertexId + 1, edgePoint); var newPrevEdge = new Edge(maxEdgeId + 1, prevEdgePoints); var newNextEdge = new Edge(maxEdgeId + 2, nextEdgePoints); newVertex.Edges[0] = newPrevEdge; newVertex.Edges[1] = newNextEdge; newPrevEdge.Vertices[0] = prevVertex; newPrevEdge.Vertices[1] = newVertex; newNextEdge.Vertices[0] = newVertex; newNextEdge.Vertices[1] = nextVertex; prevVertex.Edges[1] = newPrevEdge; nextVertex.Edges[0] = newNextEdge; Edges.Remove(edge); Edges.Add(newPrevEdge); Edges.Add(newNextEdge); Vertices.Add(newVertex); _window.RedrawAll(); }
/// <summary> /// Generates a list of int arrays /// The arrays correspond to x,y cooridnates /// </summary> public void GenerateEdges() { // Top and Bottom row for (var i = 0; i < Width; i++) { Edges.Add(new int[2] { Position[0], Position[1] + i }); Edges.Add(new int[2] { Position[0] + Height - 1, Position[1] + i }); } // Left and Right side for (var i = 0; i < Width; i++) { Edges.Add(new int[2] { Position[0], Position[1] + i }); Edges.Add(new int[2] { Position[0] + Height - 1, Position[1] + i }); } }
public void GenerateRandomDistances() { Edges.Clear(); NeighbourMatrix = new int[Cities.Count, Cities.Count]; for (int i = 0; i < Cities.Count; i++) { for (int j = 0; j < Cities.Count; j++) { if (j > i) { int value = rnd.Next(1, 20); if (rnd.Next(0, 100) > -1) { NeighbourMatrix[i, j] = value; NeighbourMatrix[j, i] = value; if (NeighbourMatrix[i, j] > 0) { Edges.Add(new Edge(Cities[i], Cities[j], NeighbourMatrix[i, j])); } } } } } }
public virtual void AddEdge(Relation <T, P> relation) { if (relation == null || relation.Source == null || relation.Target == null) { Log.Error("Relation or vertex is null."); return; } if (!VerticesData.ContainsKey(relation.Source)) { Log.Error("Relation source is missing from the graph: " + relation.Source); return; } if (!VerticesData.ContainsKey(relation.Target)) { Log.Error("Relation target is missing from the graph: " + relation.Target); return; } if (!Edges.Add(relation)) { Log.Error("Relation is already part of the graph: " + relation); return; } VerticesData[relation.Source].OutEdges.Add(relation); VerticesData[relation.Target].InEdges.Add(relation); // maintain root data if (!relation.IsSelfRelation) { recalcIsTree = true; RootVertices.Remove(relation.Target); } }
public void Add(GraphvizEdge edge) => Edges.Add(edge);
private void generarGrafo() { while (xml.Read()) { switch (xml.NodeType) { case XmlNodeType.Element: if (xml.Name == "nodo") { if (xml.HasAttributes) { atributos = new Dictionary <string, string>(); string label = ""; string id = ""; while (xml.MoveToNextAttribute()) { if (xml.Name == "label") { label = xml.Value; } else if (xml.Name == "id") { id = xml.Value; } } nodo = new Nodo(id, atributos, label); } } else if (xml.Name == "edge") { if (xml.HasAttributes) { atributos = new Dictionary <string, string>(); string label = ""; string origen = ""; string destino = ""; while (xml.MoveToNextAttribute()) { if (xml.Name == "label") { label = xml.Value; } else if (xml.Name == "origen") { origen = xml.Value; } else if (xml.Name == "destino") { destino = xml.Value; } } edge = new Edge(origen, destino, atributos, label); } } else { key = xml.Name; } break; case XmlNodeType.EndElement: if (xml.Name == "nodo" && nodo != null) { Nodos.Add(nodo); nodo = null; } else if (xml.Name == "edge" && edge != null) { Edges.Add(edge); edge = null; } break; case XmlNodeType.Text: if (nodo != null) { nodo.Atributos.Add(key, xml.Value); } else if (edge != null) { edge.Atributos.Add(key, xml.Value); } break; } } }
public void AddChild(Node child) { Children.Add(child); Edges.Add(child, new Edge(this, child)); _maxChildrenCount = Children.Count > _maxChildrenCount ? Children.Count : _maxChildrenCount; }
/// <summary> /// Добавить ребро /// </summary> /// <param name="newEdge">Ребро</param> public void AddEdge(GraphEdge newEdge) { Edges.Add(newEdge); }
/// <summary> /// Adiciona um arco com nó origem igual ao nó atual, e destino e custo de acordo com os parâmetros. /// </summary> /// <param name="to">O nó destino.</param> /// <param name="cost">O custo associado ao arco.</param> public void AddEdge(Node to, double cost) { Edges.Add(new Edge(this, to, cost)); }