예제 #1
0
        private Path BuildPathToDestination()
        {
            List<PathVertex> vertices = new List<PathVertex>();

            if (destination != null)
            {
                var vertex = new PathVertex(destination, 0);

                while (vertex != null)
                {
                    vertices.Add(vertex);
                    vertex = P[vertex.Hex];
                }

                vertices.Reverse();

                return new Path(vertices);
            }
            else
                return new Path();
        }
예제 #2
0
        private bool Find()
        {
            for (int i = 0; i < map.Count - 1; i++)
            {
                Hex v = PriorityGetMin();
                H[v] = v;

                foreach (var u in v.Neighbors)
                {
                    if (!H.ContainsKey(u))
                    {
                        if (!D.ContainsKey(u))
                        {
                            D[u] = UNDEFINED;
                            PriorityInsert(u, UNDEFINED);
                        }

                        var cost = GetCost(v, u);

                        if (D[v] + cost < D[u])
                        {
                            D[u] = D[v] + cost;
                            PriorityDecrease(u, D[u]);
                            P[u] = new PathVertex(v, cost);
                        }
                    }
                }
            }

            return destination == null || P.ContainsKey(destination);
        }