public void Clear() { Commits?.Clear(); Branches?.Clear(); Edges?.Clear(); CommitToModel?.Clear(); ContentCleared?.Invoke(); }
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; }
private void Clear() { if (Edges != null) { Edges.Clear(); Edges = null; } if (EdgeOrientations != null) { EdgeOrientations.Clear(); EdgeOrientations = null; } if (region == null) { return; } region.Clear(); region = null; }
public void Reset() { //if (!this.beachline) //{ // this.beachline = new this.RBTree(); //} //// Move leftover beachsections to the beachsection junkyard. //if (this.beachline.root) //{ // var beachsection = this.beachline.getFirst(this.beachline.root); // while (beachsection) // { // this.beachsectionJunkyard.push(beachsection); // mark for reuse // beachsection = beachsection.rbNext; // } //} //this.beachline.root = null; //if (!this.circleEvents) //{ // this.circleEvents = new this.RBTree(); //} //this.circleEvents.root = this.firstCircleEvent = null; //this.vertices = []; //this.edges = []; //this.cells = []; BeachLine = new RBTree(); CircleEvents = new RBTree(); BeachLine.Name = "BeachLine"; CircleEvents.Name = "CircleEvents"; firstCircleEvent = null; Vertices.Clear(); Edges.Clear(); Cells.Clear(); }
public void Dispose() { int i, n; if (sites != null) { sites.Dispose(); sites = null; } if (Edges != null) { n = Edges.Count; for (i = 0; i < n; ++i) { Edges[i].Dispose(); } Edges.Clear(); Edges = null; } sitesIndexedByLocation = null; }
public void Dispose() { sites.Clear(); sites = null; #if TRIANGLES foreach (Triangle t in triangles) { t.Dispose(); } triangles.Clear(); #endif foreach (Edge e in Edges) { e.Dispose(); } Edges.Clear(); PlotBounds = Rectf.zero; SitesIndexedByLocation.Clear(); //SitesIndexedByLocation = null; }
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 void Reorder(int width, int height) { //Checks if the site is fully included in the frame : if (Edges.Select(e => e.VVertexA).All(p => IsVectorInRange(p, width, height)) && Edges.Select(e => e.VVertexB).All(p => IsVectorInRange(p, width, height))) { IsOnBorder = false; } else { IsOnBorder = true; Vector previousIntersection = null; for (int i = Edges.Count - 1; i >= 0; i--) { VoronoiEdge edge = Edges[i]; bool isAIn = IsVectorInRange(edge.VVertexA, width, height); bool isBIn = IsVectorInRange(edge.VVertexB, width, height); if (isAIn && isBIn) // Edge is fully in, nothing to do { continue; } if (isAIn || isBIn) // One point in in, needs to be clipped { double slope = edge.DirectionVector[1] / edge.DirectionVector[0]; Vector pointIn = isAIn ? new Vector(edge.VVertexA) : new Vector(edge.VVertexB); List <Vector> intersections = new List <Vector>(); //Test collision with (0,0) => (width,0) edge : intersections.Add(new Vector(pointIn[0] - pointIn[1] / slope, 0)); //Test collision with (0,height) => (width,height) edge : intersections.Add(new Vector(pointIn[0] + (height - pointIn[1]) / slope, height)); //Test collision with (0,0) => (0,height) edge : intersections.Add(new Vector(0, pointIn[1] - pointIn[0] * slope)); //Test collision with (width,0) => (width,height) edge : intersections.Add(new Vector(width, pointIn[1] + (width - pointIn[0]) * slope)); Vector intersection = intersections.MinBy(p => Vector.Dist(p, pointIn)); Edges.RemoveAt(i); Edges.Add(new VoronoiEdge { VVertexA = intersection, VVertexB = pointIn }); if (previousIntersection == null) { previousIntersection = intersection; } else { if (intersection[0].Equals(previousIntersection[0]) || intersection[1].Equals(previousIntersection[1])) { Edges.Add(new VoronoiEdge { VVertexA = intersection, VVertexB = previousIntersection }); IsOnBorder = true; previousIntersection = null; } else { List <Vector> corners = new List <Vector> { new Vector(0, 0), new Vector(width, 0), new Vector(width, height), new Vector(0, height) }; foreach (Vector corner in corners) { if ((corner[0].Equals(previousIntersection[0]) || corner[0].Equals(intersection[0])) && (corner[1].Equals(previousIntersection[1]) || corner[1].Equals(intersection[1]))) { Edges.Add(new VoronoiEdge { VVertexA = corner, VVertexB = previousIntersection }); Edges.Add(new VoronoiEdge { VVertexA = corner, VVertexB = intersection }); IsOnBorder = true; break; } } previousIntersection = null; } } } else // Edge fully out, can be safely removed { Edges.RemoveAt(i); } } if (previousIntersection != null) { throw new InvalidOperationException("Error"); } } if (Edges.Count == 0) { throw new InvalidOperationException("No edges"); } VoronoiEdge first = Edges[Edges.Count - 1]; Edges.RemoveAt(Edges.Count - 1); Vector point; VoronoiPoints.Add(point = first.VVertexA); Edges.RemoveAll((e) => Equals(e.VVertexA, e.VVertexB)); do { VoronoiEdge edge = Edges.Single(e => e.VVertexA.Equals(point) || e.VVertexB.Equals(point)); Edges.Remove(edge); if (Equals(edge.VVertexA, point)) { VoronoiPoints.Add(point = edge.VVertexB); } else { VoronoiPoints.Add(point = edge.VVertexA); } } while (!Equals(point, first.VVertexB)); Edges.Clear(); //Reverse ordering of the points if needed : Vector v1 = VoronoiPoints[0] - VoronoiPoints[1]; Vector v2 = VoronoiCenter - VoronoiPoints[0]; if (v1[0] * v2[1] - v1[1] * v2[0] > 0) { VoronoiPoints.Reverse(); } }
internal void ClearEdges() { numEdges -= Edges.Count; Edges.Clear(); }
public void NextExercise() { int nodes; int solutionPaths; float extraEdgeProbability; int nodesRequiered; Scale = 10; _solutionPaths.Clear(); Nodes.Clear(); Edges.Clear(); switch (_currentLevel) { case 0: nodes = 2; solutionPaths = 1; _edgesBySolutionPath = new List <int>(solutionPaths) { 1 }; extraEdgeProbability = 0; break; case 1: nodes = Random.Range(3, 6); solutionPaths = 1; _edgesBySolutionPath = new List <int>(solutionPaths) { 2 }; extraEdgeProbability = 0; break; case 2: nodes = Random.Range(5, 8); solutionPaths = 1; _edgesBySolutionPath = new List <int>(solutionPaths) { GetEdgesToSolutionPath(nodes) }; extraEdgeProbability = 0.25f; break; case 3: nodes = Random.Range(5, 8); solutionPaths = 2; _edgesBySolutionPath = new List <int>(solutionPaths) { GetEdgesToSolutionPath(nodes) , GetEdgesToSolutionPath(nodes) }; nodesRequiered = GetQuantityNodesRequiered(_edgesBySolutionPath[0] + _edgesBySolutionPath[1]); if (nodes < nodesRequiered) { nodes = nodesRequiered; } extraEdgeProbability = 0; break; default: nodes = Random.Range(6, 9); solutionPaths = 2; _edgesBySolutionPath = new List <int>(solutionPaths) { GetEdgesToSolutionPath(nodes) , GetEdgesToSolutionPath(nodes) }; nodesRequiered = GetQuantityNodesRequiered(_edgesBySolutionPath[0] + _edgesBySolutionPath[1]); if (nodes < nodesRequiered) { nodes = nodesRequiered; } extraEdgeProbability = 1f; break; } // Necesito que haya una cantidad mÃnima de nodos, para poder cumplir las restricciones if (!CheckMinNodes(nodes)) { NextExercise(); return; } GenerateNodes(nodes); /* ShipmentsPath shipmentsPath = new ShipmentsPath(); * shipmentsPath.NodesList = new List<ShipmentNode>(4); * shipmentsPath.NodesList.Add(Nodes[0]); * shipmentsPath.NodesList.Add(Nodes[1]); * shipmentsPath.NodesList.Add(Nodes[2]); * shipmentsPath.NodesList.Add(Nodes[Nodes.Count - 1]); * * ShipmentsPath shipmentsPath2 = new ShipmentsPath(); * shipmentsPath2.NodesList = new List<ShipmentNode>(4); * shipmentsPath2.NodesList.Add(Nodes[0]); * shipmentsPath2.NodesList.Add(Nodes[3]); * shipmentsPath2.NodesList.Add(Nodes[4]); * shipmentsPath2.NodesList.Add(Nodes[Nodes.Count - 1]); * _solutionPaths.Add(shipmentsPath); * _solutionPaths.Add(shipmentsPath2);*/ GenerateSolutionPaths(solutionPaths, _edgesBySolutionPath); while (SolutionsPathsAreEquals()) { _solutionPaths.Clear(); _edges.Clear(); GenerateSolutionPaths(solutionPaths, _edgesBySolutionPath); } if (!IsValidGraph()) { NextExercise(); return; } RemainExercises--; /* * GenerateExtraEdges(extraEdgeProbability); */ }
public Triangles Triangulate(Nodes nodes) { int nv = nodes.Count; if (nv < 3) { throw new ArgumentException("Need at least three vertices for triangulation"); } int trimax = 4 * nv; // Find the maximum and minimum vertex bounds. // This is to allow calculation of the bounding supertriangle double xmin = nodes[0].X; double ymin = nodes[0].Y; double xmax = xmin; double ymax = ymin; for (int i = 1; i < nv; i++) { if (nodes[i].X < xmin) { xmin = nodes[i].X; } if (nodes[i].X > xmax) { xmax = nodes[i].X; } if (nodes[i].Y < ymin) { ymin = nodes[i].Y; } if (nodes[i].Y > ymax) { ymax = nodes[i].Y; } } double dx = xmax - xmin; double dy = ymax - ymin; double dmax = (dx > dy) ? dx : dy; double xmid = (xmax + xmin) * 0.5; double ymid = (ymax + ymin) * 0.5; // Set up the supertriangle // This is a triangle which encompasses all the sample points. // The supertriangle coordinates are added to the end of the // vertex list. The supertriangle is the first triangle in // the triangle list. nodes.Add(new Point((xmid - 2 * dmax), (ymid - dmax))); nodes.Add(new Point(xmid, (ymid + 2 * dmax))); nodes.Add(new Point((xmid + 2 * dmax), (ymid - dmax))); Triangles Triangle = new Triangles(); Triangle.Add(new Triangle(nv, nv + 1, nv + 2)); //SuperTriangle placed at index 0 // Include each point one at a time into the existing mesh for (int i = 0; i < nv; i++) { if (Progress != null) { Progress(i, nv); } Edges Edges = new Edges(); //[trimax * 3]; // Set up the edge buffer. // If the point (Vertex(i).x,Vertex(i).y) lies inside the circumcircle then the // three edges of that triangle are added to the edge buffer and the triangle is removed from list. for (int j = 0; j < Triangle.Count; j++) { if (InCircle(nodes[i], nodes[Triangle[j].p1], nodes[Triangle[j].p2], nodes[Triangle[j].p3])) { Edges.Add(new Edge(Triangle[j].p1, Triangle[j].p2)); Edges.Add(new Edge(Triangle[j].p2, Triangle[j].p3)); Edges.Add(new Edge(Triangle[j].p3, Triangle[j].p1)); Triangle.RemoveAt(j); j--; } } if (i >= nv) { continue; //In case we the last duplicate point we removed was the last in the array } // Remove duplicate edges // Note: if all triangles are specified anticlockwise then all // interior edges are opposite pointing in direction. for (int j = Edges.Count - 2; j >= 0; j--) { for (int k = Edges.Count - 1; k >= j + 1; k--) { if (Edges[j].Equals(Edges[k])) { Edges.RemoveAt(k); Edges.RemoveAt(j); k--; continue; } } } // Form new triangles for the current point // Skipping over any tagged edges. // All edges are arranged in clockwise order. for (int j = 0; j < Edges.Count; j++) { if (Triangle.Count >= trimax) { throw new ApplicationException("Exceeded maximum edges"); } Triangle.Add(new Triangle(Edges[j].p1, Edges[j].p2, i)); } Edges.Clear(); Edges = null; } // Remove triangles with supertriangle vertices // These are triangles which have a vertex number greater than nv for (int i = Triangle.Count - 1; i >= 0; i--) { if (Triangle[i].p1 >= nv || Triangle[i].p2 >= nv || Triangle[i].p3 >= nv) { Triangle.RemoveAt(i); } } //Remove SuperTriangle vertices nodes.RemoveAt(nodes.Count - 1); nodes.RemoveAt(nodes.Count - 1); nodes.RemoveAt(nodes.Count - 1); Triangle.TrimExcess(); return(Triangle); }
/// <summary> /// Clears the graph ready for new node insertions. /// </summary> public void Clear() { NextNodeIndex = 0; Nodes.Clear(); Edges.Clear(); }
private void _graph_CollectionPropertyChanged(object sender, Collections.VulcanCollectionPropertyChangedEventArgs e) { if (e.PropertyName == "Nodes") { if (e.Action == NotifyCollectionChangedAction.Reset) { Nodes.Clear(); return; } if (e.OldItems != null) { foreach (GraphNode <T> oldGraphNode in e.OldItems) { GraphNode <BasicBlock <T> > basicBlockNode = _blockMapping[oldGraphNode]; if (basicBlockNode.Item.Count > 1 || oldGraphNode.IncomingEdges.Count > 0 || oldGraphNode.OutgoingEdges.Count > 0) { throw new InvalidOperationException("The Graph attempted to remove a node that still had connections."); } _blockMapping.Remove(oldGraphNode); RemoveNode(basicBlockNode); } } if (e.NewItems != null) { foreach (GraphNode <T> newGraphNode in e.NewItems) { var basicBlock = new BasicBlock <T> { newGraphNode.Item }; _blockMapping[newGraphNode] = AddNode(basicBlock); } } } if (e.PropertyName == "Edges") { if (e.Action == NotifyCollectionChangedAction.Reset) { Edges.Clear(); return; } if (e.OldItems != null) { foreach (GraphEdge <T> oldGraphEdge in e.OldItems) { OnSourceGraphEdgeRemoved(oldGraphEdge); } } if (e.NewItems != null) { foreach (GraphEdge <T> newGraphEdge in e.NewItems) { OnSourceGraphEdgeAdded(newGraphEdge); } } } }
public void ClearGraph() { Nodes.Clear(); Edges.Clear(); NodeMap.Clear(); }
public void Clear() { Nodes.Clear(); Edges.Clear(); Roots.Clear(); }
public void RefreshEdgesVertices() { Vertices.Clear(); Edges.Clear(); AddEdgesAndVerticesFrom(Faces); }
public void Clear() { Vertices.Clear(); Edges.Clear(); Faces.Clear(); }