public AdjacencyList <TNode, TWeight> GetMinimumSpanningTree() { AdjacencyList <TNode, TWeight> result = new AdjacencyList <TNode, TWeight>(this.network.NumberOfNodes); TNode currentNode = this.network[0]; UpdateNewEdges(currentNode); this.newNodes = new List <TNode>(); this.newNodes.Add(this.network[0]); Initialize(); while (result.NumberOfNodes != network.NumberOfNodes) { Edge <TNode, TWeight> safeEdge = GetMinimumConnection(connections); connections.Remove(safeEdge); //this.newNodes = ProceedNode(this.newNodes); LinkedListNode <TNode> first = nodeList[safeEdge.Connection.Node]; LinkedListNode <TNode> second = nodeList[safeEdge.Node]; if (first.List != second.List) { result.AddUndirectedEdge(first.Value, second.Value, safeEdge.Connection.Weight); LinkedList <TNode> tempList = second.List; do { LinkedListNode <TNode> tempNode = tempList.First; tempList.RemoveFirst(); first.List.AddLast(tempNode); } while (tempList.Count > 0); UpdateNewEdges(first.Value); UpdateNewEdges(second.Value); } } return(result); }
public AdjacencyList <Point, double> GetSlopeGraph() { AdjacencyList <Point, double> result = new AdjacencyList <Point, double>();//this.triangulation.triangles.Count); for (int i = 0; i < this.triangulation.triangles.Count; i++) { QuasiTriangle tempQuasiTriangle = this.triangulation.triangles[i]; int tempCode = tempQuasiTriangle.GetHashCode(); Triangle tempTriangle = this.triangulation.GeTriangle(tempCode); Point firstPoint = tempTriangle.CalculateCentroid(); double currentSlope = CalculateSlope(tempTriangle); foreach (int neighbour in tempQuasiTriangle.OrderedNeighbours) { if (neighbour != -1) { Triangle neighbourTriangle = this.triangulation.GeTriangle(neighbour); Point secondPoint = neighbourTriangle.CalculateCentroid(); double neighbourSlope = CalculateSlope(tempTriangle); double weight = currentSlope + neighbourSlope; Connection <Point, double> tempConnection = new Connection <Point, double>(secondPoint, weight); result.AddUndirectedEdge(firstPoint, secondPoint, weight); } } } return(result); }