public void Connect(int v, int w) { if (IsConnected(w, v)) { return; } double d = GetDistance(w, v); DirectedWeightedEdge edge1 = new DirectedWeightedEdge(v, w, d); DirectedWeightedEdge edge2 = new DirectedWeightedEdge(w, v, d); adj[v].Add(edge1); adj[w].Add(edge2); }
private void Relax(GridWorld G, DirectedWeightedEdge e) { int v = e.From(); int w = e.To(); if (cost[w] > cost[v] + e.Weight) { cost[w] = cost[v] + e.Weight; edgeTo[w] = e; if (!pq.Contains(w)) { pq.Insert(w, cost[w]); } else { pq.DecreaseKey(w, cost[w]); } } }