public NXTNode(NXTNode parent, Point position, uint price) { this.parent = parent; this.position = position; this.price = price; this.neighbours = new List <NXTNode>(); }
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)); }
public bool Equals(NXTNode obj) { if (obj.position.Equals(this.position)) { return(true); } else { return(false); } }
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); } } }
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); }
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); } } }
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); }
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); } } }
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); } }