Ejemplo n.º 1
0
        PointD PossiblyCombinePoint(PointD point, Double distance)
        {
            PointD ret = point;

            foreach (KeyValuePair <String, TreePathVertice> kvp in _vertices)
            {
                TreePathVertice vertice = kvp.Value;
                if (point.Equals(vertice.Position) == false && FlatGeo.Distance(point, vertice.Position) < distance)
                {
                    ret = vertice.Position;
                    DebugLogText(LogLevel.DEBUG, "Combining {0} into {1}", point, ret);
                    break;
                }
            }
            return(ret);
        }
Ejemplo n.º 2
0
        public bool Cycle()
        {
            /** get the vertice with the lowest distance from the origin */
            TreePathVertice current = null;

            foreach (TreePathVertice vertice in m_UnvisitedVertices)
            {
                if (current == null || vertice.Distance <= current.Distance)
                {
                    current = vertice;
                }
            }
            DebugLogText(LogLevel.DEBUG, "Cycle set current vertice to {0}", current);

            if (current.Distance != Double.PositiveInfinity)
            {
                /** go through each neighbor of the current */
                foreach (KeyValuePair <String, TreePathVertice> kvp in current.Neighbors)
                {
                    TreePathVertice neighbor = kvp.Value;
                    if (neighbor.State == TreePathVertice.VerticeState.Unvisited)
                    {
                        Double nDistance = FlatGeo.Distance(current.Position, neighbor.Position);
                        if (current.Distance + nDistance < neighbor.Distance)
                        {
                            neighbor.Distance = current.Distance + nDistance;
                            neighbor.Source   = current;
                            DebugLogText(LogLevel.DEBUG, "---      set neighbor {0} to distance of {1:0.00}", neighbor, GetNativeDistance(neighbor.Distance));
                        }
                    }
                }

                /** move this node from visited to unvisited */
                current.State = TreePathVertice.VerticeState.Visited;
                DebugLogText(LogLevel.DEBUG, "Set vertice {0} to Visited", current);

                m_UnvisitedVertices.Remove(current);
                m_VisitedVertices.Add(current);
            }
            else
            {
                m_UnvisitedVertices.Remove(current);
                DebugLogText(LogLevel.ERROR, "VERTICE {0} has no solution!", current);
            }

            return(m_UnvisitedVertices.Count > 0);
        }