public void Visit(EdgeWeightedGraph g, int v) { marked[v] = true; foreach (var edge in g.Adj(v)) { int v2 = edge.Other(v); if (marked[v2]) { continue; } if (edge.Weight < distanceTo[v2]) { edgeTo[v2] = edge; distanceTo[v2] = edge.Weight; if (pq.Contains(v2)) { pq.Change(v2, distanceTo[v2]); } else { pq.Insert(v2, distanceTo[v2]); } } } }
private void Visit(EdgeWeightedGraph graph, int vertex) { marked[vertex] = true; foreach (var edge in graph.Adj(vertex)) { int otherVertex = edge.Other(vertex); if (marked[otherVertex]) { continue; } if (edge.Weight < distTo[otherVertex]) { edgeTo[otherVertex] = edge; distTo[otherVertex] = edge.Weight; if (prioryQueue.Contains(otherVertex)) { prioryQueue.Change(otherVertex, distTo[otherVertex]); } else { prioryQueue.Insert(otherVertex, distTo[otherVertex]); } } } }
private void Relax(EdgeWeightedDigraph g, int v) { foreach (var e in g.Adj(v)) { int w = e.To; if (_distTo[v] + e.Weight < _distTo[w]) { _edgeTo[w] = e; _distTo[w] = _distTo[v] + e.Weight; if (_pq.Contains(e.To)) { _pq.Change(e.To, _distTo[w]); } else { _pq.Insert(e.To, _distTo[w]); } } } }
void Relax(EdgeWeightedDirectedGraph graph, int vertex) { foreach (var edge in graph.Adj(vertex)) { int v2 = edge.End; if (DistTo[v2] > DistTo[vertex] + edge.Weight) { DistTo[v2] = DistTo[vertex] + edge.Weight; EdgeTo[v2] = edge; if (pq.Contains(v2)) { pq.Change(v2, DistTo[v2]); } pq.Insert(v2, DistTo[v2]); } } }
private void Relax(EdgeWeightedDigraph graph, int vertex) { foreach (var edge in graph.Adj(vertex)) { int w = edge.DestinationVertex; if (distTo[w] > distTo[vertex] + edge.Weight) { distTo[w] = distTo[vertex] + edge.Weight; edgeTo[w] = edge; if (priorityQueue.Contains(w)) { priorityQueue.Change(w, distTo[w]); } else { priorityQueue.Insert(w, distTo[w]); } } } }
private void Relax(EdgeWeightedDiGraph g, int v) { foreach (var edge in g.Adj(v)) { //test if current weight of path to W is more than going through v; ie v 'relaxes' the path int w = edge.To(); double distViaV = _distTo[v] + edge.Weight(); //if current distTo w is greater than (distTo v + this.edge weight), then add/or replace on arrays and PQ if (distViaV < _distTo[w]) { _distTo[w] = distViaV; _edgeTo[w] = edge; if (_pq.Contains(w)) { _pq.Change(w, distViaV); } else { _pq.Insert(w, distViaV); } } } }