public void AddDoubleLinkedList() { DoubleLinkedList dll = new DoubleLinkedList(); FibonacciNode n1= new FibonacciNode(){StationID = 1}; FibonacciNode n2= new FibonacciNode(){StationID = 2}; FibonacciNode n3 = new FibonacciNode() { StationID = 3 }; dll.Add(n1); Assert.AreEqual(1, dll.head.StationID); Assert.AreEqual(1, dll.head.RightNode.StationID); Assert.AreEqual(1, dll.head.LeftNode.StationID); dll.Add(n2); Assert.AreEqual(1, dll.head.StationID); Assert.AreEqual(2, dll.head.RightNode.StationID); Assert.AreEqual(1, dll.head.RightNode.RightNode.StationID); dll.Add(n3); Assert.AreEqual(1, dll.head.StationID); Assert.AreEqual(2, dll.head.RightNode.StationID); Assert.AreEqual(3, dll.head.RightNode.RightNode.StationID); Assert.AreEqual(1, dll.head.LeftNode.RightNode.StationID); }
public void CascadingCut() { FibonacciHeap heap = new FibonacciHeap(); DoubleLinkedList list = new DoubleLinkedList(); FibonacciNode y = new FibonacciNode() { StationID = 1, MinPathValue = 10 }; FibonacciNode x = new FibonacciNode() { StationID = 2, MinPathValue = 20, Mark = true }; FibonacciNode z = new FibonacciNode() { StationID = 3, MinPathValue = 21, Mark = true }; x.Parent = y; y.Child = x; z.Parent = x; x.Child = z; list.Add(y); heap.CascadingCut(list, z); Assert.AreEqual(null, x.Child); Assert.AreEqual(null, y.Child); Assert.AreEqual(null, x.Parent); Assert.AreEqual(null, z.Parent); Assert.AreEqual(1, list.head.StationID); Assert.AreEqual(3, list.head.RightNode.StationID); Assert.AreEqual(2, list.head.RightNode.RightNode.StationID); }
public void Cut() { FibonacciHeap heap = new FibonacciHeap(); DoubleLinkedList list = new DoubleLinkedList(); FibonacciNode y = new FibonacciNode() { StationID = 1, MinPathValue = 10 }; FibonacciNode x = new FibonacciNode() { StationID = 2, MinPathValue = 20 }; x.Parent = y; y.Child = x; list.Add(y); heap.Cut(list, x, y); Assert.AreEqual(null, x.Parent); Assert.AreEqual(false, x.Mark); Assert.AreEqual(1, list.head.StationID); Assert.AreEqual(2, list.head.RightNode.StationID); }
public void Link() { FibonacciHeap heap1 = new FibonacciHeap(); DoubleLinkedList root1 = new DoubleLinkedList(); FibonacciNode y = new FibonacciNode() { StationID = 1, MinPathValue = 10 }; FibonacciNode x = new FibonacciNode() { StationID = 2, MinPathValue = 5 }; root1.Add(y); root1.Add(x); heap1.Link(root1, y, x); Assert.AreEqual(2, root1.head.StationID); Assert.AreEqual(1, x.Child.StationID); Assert.AreEqual(1, x.Degree); Assert.AreEqual(2, root1.head.RightNode.StationID); FibonacciHeap heap2 = new FibonacciHeap(); DoubleLinkedList root2 = new DoubleLinkedList(); FibonacciNode z = new FibonacciNode() { StationID = 3, MinPathValue = 10 }; x.Child = z; z.Parent = x; x.Degree = 1; root1.Add(y); root1.Add(x); heap2.Link(root2, y, x); Assert.AreEqual(2, root1.head.StationID); Assert.AreEqual(3, x.Child.StationID); Assert.AreEqual(2, x.Degree); Assert.AreEqual(2, root1.head.RightNode.StationID); Assert.AreEqual(3, x.Child.StationID); Assert.AreEqual(1, x.Child.RightNode.StationID); }
public void consolidateTree(DoubleLinkedList root) { FibonacciNode[] A = new FibonacciNode[calculateArraySize(numberOfNodes)]; //FibonacciNode[] A = new FibonacciNode[1000000]; for (int i = 0; i < A.Length; i++) { A[i] = null; } FibonacciNode w = root.head; //pointer for tranverse nodes int size = root.Size; for (int i = 0; i < size; i++) { FibonacciNode x = w; int d = x.Degree; while (A[d] != null) { FibonacciNode y = A[d]; if (x.MinPathValue > y.MinPathValue) { //exchange x and y FibonacciNode c = x; x = y; y = c; //w = w.LeftNode;//set the pointer back to the node on the left } if ( w==y) { w = w.LeftNode; } Link(root, y, x); //x (w) is to be deleted in root list //w = x; //TODO could be bug A[d] = null; d += 1; } A[d] = x; w = w.RightNode; //pointer continue move to next node } minNode = null; root = new DoubleLinkedList(); for (int j = 0; j < A.Length; j++) { if (A[j] != null) { root.Add(A[j]); if (minNode == null || A[j].MinPathValue < minNode.MinPathValue) { minNode = A[j]; } } } }
public void Cut(DoubleLinkedList list, FibonacciNode x, FibonacciNode y) { //remove x from y child least if (x == x.LeftNode) { y.Child = null; } else { if (x == y.Child) { y.Child = x.RightNode; } FibonacciNode leftNode = x.LeftNode; FibonacciNode rightNode = x.RightNode; leftNode.RightNode = rightNode; rightNode.LeftNode = leftNode; } y.Degree--; //add x to the list list.Add(x); //FibonacciNode lastNode = list.head.LeftNode; //lastNode.RightNode = x; //x.LeftNode = lastNode; //x.RightNode = list.head; //list.head.LeftNode = x; //list.Size++; x.Parent = null; x.Mark = false; }