Ejemplo n.º 1
0
		/// <summary>
		/// Liefert den Pfad zum Knoten d
		/// </summary>
		/// <param name="d">Zielknote<n/param>
		/// <returns></returns>
		public List<Node> getPathTo(Node d)
		{
            if (d == null)
            {
                return new List<Node>();
            }

			List<Node> path = new List<Node>();

			path.Insert(0, d);

			while (Previous[d.Name] != null)
			{
				d = Previous[d.Name];
				path.Insert(0, d);
			}

			if (d.Name.Equals(_startNode.Name))
			{
				return path;
			}
			else
			{
				return new List<Node>();
			}
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Berechnet die kürzesten Wege vom start
        /// Knoten zu allen anderen Knoten
        /// </summary>
        /// <param name="start">Startknoten</param>
        public void calculateDistance(Node start)
        {
	        _startNode = start;
            Dist[start.Name] = 0;

            while (Basis.Count > 0)
            {
                Node u = getNodeWithSmallestDistance();
                if (u == null)
                {
                    Basis.Clear();
                }
                else
                {
                    foreach (Node v in getNeighbors(u))
                    {
                        double alt = Dist[u.Name] +
                                getDistanceBetween(u, v);
                        if (alt < Dist[v.Name])
                        {
                            Dist[v.Name] = alt;
                            Previous[v.Name] = u;
                        }
                    }
                    Basis.Remove(u);
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Konstruktor
 /// </summary>
 /// <param name="origin">Startknoten</param>
 /// <param name="destination">Zielknoten</param>
 /// <param name="distance">Distanz</param>
 public Edge(Node origin, Node destination, double distance)
 {
     this._origin = origin;
     this._destination = destination;
     this._distance = distance;
 }
        private void CreateNode(int startX, int startY, int range, MapExplored mapExplored)
        {
            for (int i = startX; i < startX + range; i++)
            {
                for (int j = startY; j < startY + range; j++)
                {
                    MapElementStatus status = mapExplored.GetStatus(i, j);

                    // don't create node if any pixel in range x range is blocked
                    if (status == MapElementStatus.Blocked)
                    {
                        return;
                    }
                }
            }

            // if node is free -> save
            Node node = new Node(GenerateName(startX / GRID_SIZE, startY / GRID_SIZE));
            _nodeMatrix[startX / GRID_SIZE, startY / GRID_SIZE] = node;
            _nodeList.Add(node);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Liefert die Distanz zwischen zwei Knoten
        /// </summary>
        /// <param name="o">Startknoten</param>
        /// <param name="d">Endknoten</param>
        /// <returns></returns>
        public double getDistanceBetween(Node o, Node d)
        {
            foreach (Edge e in Edges)
            {
                if (e.Origin.Equals(o) && e.Destination.Equals(d))
                {
                    return e.Distance;
                }
            }

            return 0;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Liefert alle Nachbarn von n die noch in der Basis sind
        /// </summary>
        /// <param name="n">Knoten</param>
        /// <returns></returns>
        public List<Node> getNeighbors(Node n)
        {
            List<Node> neighbors = new List<Node>();

            foreach (Edge e in Edges)
            {
                if (e.Origin.Equals(n) && Basis.Contains(n))
                {
                    neighbors.Add(e.Destination);
                }
            }

            return neighbors;
        }