示例#1
0
 public NXTNode(NXTNode parent, Point position, uint price)
 {
     this.parent     = parent;
     this.position   = position;
     this.price      = price;
     this.neighbours = new List <NXTNode>();
 }
示例#2
0
        public List <Point> ComputeDijkstra(Point start, Point goal)
        {
            Initialize(start);
            List <NXTNode> q  = new List <NXTNode>(nodes);
            NXTNode        s1 = null;

            while (q.Count > 0)
            {
                s1 = GetMin(q);
                q.Remove(s1);

                if (s1.position.Equals(goal))
                {
                    break;
                }

                sptSet[s1.position] = true;
                foreach (NXTNode s2 in s1.neighbours)
                {
                    UpdatePrice(s1, s2);
                }
            }

            return(ComputePath(s1));
        }
示例#3
0
 public bool Equals(NXTNode obj)
 {
     if (obj.position.Equals(this.position))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#4
0
 private void CreateChilds(Point start, NXTNode current)
 {
     foreach (Point p in circuit.GetNeighbours(current.position))
     {
         if (accessibleCases.Contains(p))
         {
             NXTNode node = new NXTNode(current, p, uint.MaxValue);
             nodes.Add(node);
             accessibleCases.Remove(p);
             sptSet.Add(node.position, false);
             CreateChilds(start, node);
         }
     }
 }
示例#5
0
        private List <Point> ComputePath(NXTNode finalNode)
        {
            List <Point> path  = new List <Point>();
            NXTNode      cNode = finalNode;

            while (cNode.price != 0)
            {
                path.Add(cNode.position);
                cNode = cNode.parent;
            }

            path.Reverse();
            return(path);
        }
示例#6
0
 private void UpdatePrice(NXTNode na, NXTNode nb)
 {
     if (nb != null)
     {
         uint nPrice = na.price + (uint)GetManhattanHeuristic(na.position, nb.position);
         if (!sptSet[nb.position] && na.price != uint.MaxValue && nPrice < nb.price)
         {
             nb.price  = nPrice;
             nb.parent = na;
             //this.circuit.getCase(nb.position).CaseColor = new Color(nb.price / 10f, (10 - nb.price) / 10f, 0f); // Donne une couleur aux cases selon l'heuristique
             //Console.WriteLine("Parent updated " + na.position + " -> " + nb.position);
         }
     }
 }
示例#7
0
        private NXTNode GetMin(List <NXTNode> nodes)
        {
            uint    mini = uint.MaxValue;
            NXTNode node = null;

            foreach (NXTNode n in nodes)
            {
                if (n.price < mini)
                {
                    mini = n.price;
                    node = n;
                }
            }

            return(node);
        }
示例#8
0
        protected void Initialize(Point start)
        {
            nodes.Clear();
            sptSet.Clear();

            accessibleCases = circuit.getAllCases();
            NXTNode sNode = new NXTNode(start, 0);

            nodes.Add(sNode);
            accessibleCases.Remove(start);

            CreateChilds(start, sNode);

            foreach (NXTNode n in nodes)
            {
                foreach (Point p in circuit.GetNeighbours(n.position))
                {
                    NXTNode neighbour = FindNodeAt(p);
                    n.neighbours.Add(neighbour);
                }
            }
        }
示例#9
0
        protected bool RemoveFullNode(NXTNode node)
        {
            if (this.nodes.Remove(node))
            {
                foreach (NXTNode n in node.neighbours)
                {
                    foreach (NXTNode nn in n.neighbours)
                    {
                        if (nn == node)
                        {
                            n.neighbours.Remove(nn);
                        }
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }