コード例 #1
0
        void enqueue_node_dense(int id, float dist)
        {
            GraphNodeStruct g = new GraphNodeStruct(id, -1, dist);

            DenseNodes[id] = g;
            DenseQueue.Insert(id, dist);
        }
コード例 #2
0
        void update_neighbours_dense(int parent_id)
        {
            GraphNodeStruct g        = DenseNodes[parent_id];
            float           cur_dist = g.distance;

            foreach (int nbr_id in NeighboursF(parent_id))
            {
                if (NodeFilterF(nbr_id) == false)
                {
                    continue;
                }

                GraphNodeStruct nbr = DenseNodes[nbr_id];
                if (nbr.frozen)
                {
                    continue;
                }

                float nbr_dist = NodeDistanceF(parent_id, nbr_id) + cur_dist;
                if (DenseQueue.Contains(nbr_id))
                {
                    if (nbr_dist < nbr.distance)
                    {
                        nbr.parent = parent_id;
                        DenseQueue.Update(nbr_id, nbr_dist);
                        DenseNodes[nbr_id] = nbr;
                    }
                }
                else
                {
                    enqueue_node_dense(nbr_id, nbr_dist);
                }
            }
        }
コード例 #3
0
        void enqueue_node_dense(int id, float dist, int parent_id)
        {
            var g = new GraphNodeStruct(id, parent_id, dist);

            DenseNodes[id] = g;
            DenseQueue.Insert(id, dist);
        }
コード例 #4
0
        /// <summary>
        /// Walk from node fromv back to the (graph-)nearest seed point.
        /// </summary>
        public bool GetPathToSeed(int fromv, List <int> path)
        {
            if (SparseNodes != null)
            {
                GraphNode g = get_node(fromv);
                if (g.frozen == false)
                {
                    return(false);
                }

                path.Add(fromv);
                while (g.parent != null)
                {
                    path.Add(g.parent.id);
                    g = g.parent;
                }
                return(true);
            }
            else
            {
                GraphNodeStruct g = DenseNodes[fromv];
                if (g.frozen == false)
                {
                    return(false);
                }

                path.Add(fromv);
                while (g.parent != -1)
                {
                    path.Add(g.parent);
                    g = DenseNodes[g.parent];
                }
                return(true);
            }
        }
コード例 #5
0
        protected int ComputeToNode_Dense(Func <int, bool> terminatingNodeF, float fMaxDistance)
        {
            while (DenseQueue.Count > 0)
            {
                float idx_priority = DenseQueue.FirstPriority;
                max_value = Math.Max(idx_priority, max_value);
                if (max_value > fMaxDistance)
                {
                    return(-1);
                }

                int             idx = DenseQueue.Dequeue();
                GraphNodeStruct g   = DenseNodes[idx];
                g.frozen = true;
                if (TrackOrder)
                {
                    order.Add(g.id);
                }

                g.distance      = max_value;
                DenseNodes[idx] = g;
                if (terminatingNodeF(g.id))
                {
                    return(g.id);
                }

                update_neighbours_dense(g.id);
            }
            return(-1);
        }
コード例 #6
0
        protected void ComputeToNode_Dense(int node_id, float fMaxDistance)
        {
            while (DenseQueue.Count > 0)
            {
                float idx_priority = DenseQueue.FirstPriority;
                max_value = Math.Max(idx_priority, max_value);
                if (max_value > fMaxDistance)
                {
                    return;
                }

                int             idx = DenseQueue.Dequeue();
                GraphNodeStruct g   = DenseNodes[idx];
                g.frozen = true;
                if (TrackOrder)
                {
                    order.Add(g.id);
                }

                g.distance      = max_value;
                DenseNodes[idx] = g;
                if (g.id == node_id)
                {
                    return;
                }

                update_neighbours_dense(g.id);
            }
        }
コード例 #7
0
 /// <summary>
 /// Get the computed distance at node id. returns InvalidValue if node was not computed.
 /// </summary>
 public float GetDistance(int id)
 {
     if (SparseNodes != null) {
         GraphNode g = SparseNodes[id];
         if (g == null)
             return InvalidValue;
         return g.priority;
     } else {
         GraphNodeStruct g = DenseNodes[id];
         return (g.frozen) ? g.distance : InvalidValue;
     }
 }
コード例 #8
0
 protected void Compute_Dense()
 {
     while (DenseQueue.Count > 0)
     {
         float           idx_priority = DenseQueue.FirstPriority;
         int             idx          = DenseQueue.Dequeue();
         GraphNodeStruct g            = DenseNodes[idx];
         g.frozen        = true;
         g.distance      = max_value;
         DenseNodes[idx] = g;
         max_value       = Math.Max(idx_priority, max_value);
         update_neighbours_dense(g.id);
     }
 }
コード例 #9
0
 /// <summary>
 /// Get the computed distance at node id. returns float.MaxValue if node was not computed.
 /// </summary>
 public float GetDistance(int id)
 {
     if (SparseNodes != null)
     {
         GraphNode g = SparseNodes[id];
         if (g == null)
         {
             return(float.MaxValue);
         }
         return(g.priority);
     }
     else
     {
         GraphNodeStruct g = DenseNodes[id];
         return(g.distance);
     }
 }