Exemple #1
0
        public void ChangeValueTest()
        {
            var heap = new MinHeap <int, int>();

            heap.Add(3, 5);
            heap.ChangeValue(3, 10);
            Assert.AreEqual(10, heap[3]);
        }
        public void ChangeValueTest()
        {
            var heap = new MinHeap <string, int, Dictionary <string, int> >();

            heap.Add("item1", 3);
            heap.Add("item2", 4);
            heap.Add("item3", 8);
            heap.Add("item4", 10);
            heap.Add("item5", 1);
            heap.Add("item6", 2);

            heap.ChangeValue("item2", 20);
            heap.ChangeValue("item6", 0);

            Assert.AreEqual(0, heap.ExtractMin().Value);
            Assert.AreEqual(1, heap.ExtractMin().Value);
            Assert.AreEqual(3, heap.ExtractMin().Value);
            Assert.AreEqual(8, heap.ExtractMin().Value);
            Assert.AreEqual(10, heap.ExtractMin().Value);
            Assert.AreEqual(20, heap.ExtractMin().Value);
        }
Exemple #3
0
        private void UpdateNeighbors(
            int currentWptIndex,
            RouteSeachRegion regionPara,
            RouteFindingData findRouteData,
            MinHeap <int, double> unvisited,
            double currentDis)
        {
            foreach (var edgeIndex in wptList.EdgesFrom(currentWptIndex))
            {
                var wptData     = findRouteData.WaypointData;
                var edge        = wptList.GetEdge(edgeIndex);
                int index       = edge.ToNodeIndex;
                var countryCode = wptList[index].CountryCode;

                if (WptWithinRange(findRouteData, index, regionPara) &&
                    avoidedCountry.Contains(countryCode) == false)
                {
                    double newDis = currentDis + GetEdgeDistance(edge);

                    if (wptData[index].CurrentDistance == double.PositiveInfinity)
                    {
                        // The node was never touched.
                        unvisited.Add(index, newDis);
                        wptData[index] = new RouteFindingData.WaypointStatus(
                            edge,
                            newDis,
                            InRange.Yes);
                    }
                    else if (unvisited.ContainsKey(index) && newDis < unvisited[index])
                    {
                        unvisited.ChangeValue(index, newDis);
                        wptData[index] = new RouteFindingData.WaypointStatus(
                            edge,
                            newDis,
                            InRange.Yes);
                    }
                }
            }
        }
Exemple #4
0
        public void ChangeValueShouldThrow()
        {
            var heap = new MinHeap <int, int>();

            Assert.Throws <KeyNotFoundException>(() => heap.ChangeValue(3, 10));
        }
        public void ChangeValueKeyDoesNotExist()
        {
            var heap = new MinHeap <string, int, Dictionary <string, int> >();

            Assert.Throws <KeyNotFoundException>(() => heap.ChangeValue("item1", 20));
        }