Пример #1
0
 internal QuadTreeArea FindArea(Vector2 candidateNodePosition)
 {
     if (this.Cover(candidateNodePosition))
     {
         if (IsFinalNode)
         {
             return(this);
         }
         else
         {
             QuadTreeArea area = this.GetCoveringChildArea(candidateNodePosition);
             return(area.FindArea(candidateNodePosition));
         }
     }
     else
     {
         if (this.Parent == null)
         {
             return(null);
         }
         else
         {
             return(Parent.FindArea(candidateNodePosition));
         }
     }
 }
Пример #2
0
        private QuadTreeArea GetCoveringChildArea(Vector2 Position)
        {
            QuadTreeArea selectedArea = null;

            if (Position.Y > this.CenterY)
            {
                if (Position.X < this.CenterX)
                {
                    selectedArea = NWest;
                }
                else
                {
                    selectedArea = NEast;
                }
            }
            else
            {
                if (Position.X < this.CenterX)
                {
                    selectedArea = SWest;
                }
                else
                {
                    selectedArea = SEast;
                }
            }
            return(selectedArea);
        }
Пример #3
0
 public static void onNewArea(QuadTreeArea quadTreeArea)
 {
     if (NewArea != null)
     {
         NewArea(quadTreeArea);
     }
 }
        public Node[] SolveFirst(Vector2 vqinit, Vector2 vqend)
        {
            QuadTreeArea currentArea = new QuadTreeArea(Math.Min(vqinit.X, vqend.X),
                                                Math.Max(vqinit.Y, vqend.Y),
                                                Math.Max(vqinit.X, vqend.X),
                                                Math.Min(vqinit.Y, vqend.Y));

            Node qend = new Node { Position = vqend};
            Node qinit = new Node { Position = vqinit };
            qinit.Heuristic = (vqend - vqinit).Module();

            currentArea.Add(qinit);
            ProblemContext.onNewNode(qinit);

            int CurrentIteration = 0;
            while (CurrentIteration < ProblemContext.MaxGenerations)
            {
                Node bestNode = currentArea.GetBestNodeFromMostUndenseArea();
                Node newNode = bestNode.TryExpand(qend);

                if (currentArea.Parent != null)
                    currentArea = currentArea.Antecesor;

                if (newNode == qend)
                {
                    return newNode.Predecesors.ToArray();
                }
                CurrentIteration++;
            }

            return null;
        }
Пример #5
0
        public Node GetBestNodeFromMostUndenseArea()
        {
            var areas = Descendency.Where(a => a.IsFinalNode && a.Density > 0.0).OrderBy(a => a.Density).ThenBy(a => a.BestNode);

            QuadTreeArea bestArea = areas.FirstOrDefault();

            if (bestArea == null)
            {
                return(GetBestNode());
            }
            else
            {
                return(bestArea.GetBestNode());
            }
        }
Пример #6
0
        public Node[] SolveFirst(Vector2 vqinit, Vector2 vqend)
        {
            QuadTreeArea currentArea = new QuadTreeArea(Math.Min(vqinit.X, vqend.X),
                                                        Math.Max(vqinit.Y, vqend.Y),
                                                        Math.Max(vqinit.X, vqend.X),
                                                        Math.Min(vqinit.Y, vqend.Y));


            Node qend = new Node {
                Position = vqend
            };
            Node qinit = new Node {
                Position = vqinit
            };

            qinit.Heuristic = (vqend - vqinit).Module();

            currentArea.Add(qinit);
            ProblemContext.onNewNode(qinit);

            int CurrentIteration = 0;

            while (CurrentIteration < ProblemContext.MaxGenerations)
            {
                Node bestNode = currentArea.GetBestNodeFromMostUndenseArea();
                Node newNode  = bestNode.TryExpand(qend);

                if (currentArea.Parent != null)
                {
                    currentArea = currentArea.Antecesor;
                }

                if (newNode == qend)
                {
                    return(newNode.Predecesors.ToArray());
                }
                CurrentIteration++;
            }

            return(null);
        }
        public void Add(Node node)
        {
            if (this.Cover(node))
            {
                if (IsFinalNode)
                {

                    if (Nodes.Count == ProblemContext.NodesPerArea && Area>=ProblemContext.MinAreaSize)
                    {
                        //SUBDIVISION
                        subdivide();
                        Nodes.Add(node);

                        foreach (Node n in Nodes)
                        {
                            QuadTreeArea selectedArea=GetCoveringChildArea(n);
                            selectedArea.Add(n);
                        }

                        this.Nodes.Clear();
                        this.Nodes = null;
                    }
                    else
                    {
                        //NORMAL ADDITION
                        //BASE CASE

                        Nodes.Add(node);
                        node.Area = this;
                        if (this.BestNode == null || node.PathQualityEstimation < this.BestNode.PathQualityEstimation)
                            this.BestNode = node;
                    }

                }
                else
                {
                    //RECURSIVE DOWN CASE
                    GetCoveringChildArea(node).Add(node);
                }
            }
            else
            {
                if (this.Parent == null)
                {

                    bool north = node.Position.Y > this.Top;
                    bool west = node.Position.X < this.Left;
                    bool south = node.Position.Y < this.Bottom;
                    bool east = node.Position.X > this.Right;

                    double width = this.Width;
                    double height = this.Height;

                    if (south || east)
                    {
                        Parent = new QuadTreeArea(this.Left, this.Top, this.Right + width, this.Bottom - height);
                        Parent.NWest = this;
                    }
                    else if (north || west)
                    {
                        Parent = new QuadTreeArea(this.Left - width, this.Top + height, this.Right, this.Bottom);
                        Parent.SEast = this;
                    }
                    else
                        throw new NotImplementedException();

                    this.Name = (north ? "N" : "S") + (east ? "E" : "W");
                    Parent.subdivide();

                }

                this.Parent.Add(node);
            }
        }
Пример #8
0
        public void Add(Node node)
        {
            if (this.Cover(node))
            {
                if (IsFinalNode)
                {
                    if (Nodes.Count == ProblemContext.NodesPerArea && Area >= ProblemContext.MinAreaSize)
                    {
                        //SUBDIVISION
                        subdivide();
                        Nodes.Add(node);

                        foreach (Node n in Nodes)
                        {
                            QuadTreeArea selectedArea = GetCoveringChildArea(n);
                            selectedArea.Add(n);
                        }

                        this.Nodes.Clear();
                        this.Nodes = null;
                    }
                    else
                    {
                        //NORMAL ADDITION
                        //BASE CASE

                        Nodes.Add(node);
                        node.Area = this;
                        if (this.BestNode == null || node.PathQualityEstimation < this.BestNode.PathQualityEstimation)
                        {
                            this.BestNode = node;
                        }
                    }
                }
                else
                {
                    //RECURSIVE DOWN CASE
                    GetCoveringChildArea(node).Add(node);
                }
            }
            else
            {
                if (this.Parent == null)
                {
                    bool north = node.Position.Y > this.Top;
                    bool west  = node.Position.X < this.Left;
                    bool south = node.Position.Y < this.Bottom;
                    bool east  = node.Position.X > this.Right;

                    double width  = this.Width;
                    double height = this.Height;

                    if (south || east)
                    {
                        Parent       = new QuadTreeArea(this.Left, this.Top, this.Right + width, this.Bottom - height);
                        Parent.NWest = this;
                    }
                    else if (north || west)
                    {
                        Parent       = new QuadTreeArea(this.Left - width, this.Top + height, this.Right, this.Bottom);
                        Parent.SEast = this;
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }

                    this.Name = (north ? "N" : "S") + (east ? "E" : "W");
                    Parent.subdivide();
                }

                this.Parent.Add(node);
            }
        }
 void ProblemContext_NewArea(QuadTreeArea newarea)
 {
     this.BeginInvoke((Action)delegate { interfaceNewArea(newarea); });
     //checkPoint()
 }
 void interfaceNewArea(QuadTreeArea newarea)
 {
     this.Text = "Paused on new Area";
     this.areas.Add(newarea);
     this.Invalidate();
 }
 void Form1_MouseClick(object sender, MouseEventArgs e)
 {
     selectedArea = areas.FirstOrDefault(a => a.IsFinalNode && a.Cover(new Vector2 { X = e.X, Y = e.Y }));
     clickedAndSelectedNode = nodes.FirstOrDefault(n => (n.Position - new Vector2 { X = (double)e.X, Y = (double)e.Y }).Module() <= 5.0);
     this.Invalidate();
 }