+// This method does not change the edge occupation. It only sets
+// properly, for every vertex, the fields distance_from_source and
+// pred_edge_toward_source.
+
+void MTPGraph::find_shortest_path() {
+ Vertex *v, *tv, **a, **b;
+ Edge *e;
+ scalar_t d;
+
+ for(int k = 0; k < _nb_vertices; k++) {
+ _vertices[k].distance_from_source = FLT_MAX;
+ _vertices[k].pred_edge_toward_source = 0;
+ }
+
+ _heap_size = _nb_vertices;
+ _source->distance_from_source = 0;
+ _source->decrease_distance_in_heap(_heap);
+
+ do {
+ // Get the closest to the source
+ v = _heap[0];
+
+ // Remove it from the heap (swap it with the last in the heap, and
+ // update the distance of that one)
+ _heap_size--;
+ a = _heap;
+ b = _heap + _heap_size;
+ swap(*a, *b); swap((*a)->heap_slot, (*b)->heap_slot);
+ _heap[0]->increase_distance_in_heap(_heap, _heap_size);
+
+ // Now update the neighbors of the currently closest to the source
+ for(e = v->leaving_edges; e; e = e->next_leaving_edge) {
+ d = v->distance_from_source + e->positivized_length;
+ tv = e->terminal_vertex;
+ if(d < tv->distance_from_source) {
+ ASSERT(tv->heap_slot - _heap < _heap_size);
+ tv->distance_from_source = d;
+ tv->pred_edge_toward_source = e;
+ tv->decrease_distance_in_heap(_heap);
+ }
+ }
+ } while(_heap_size > 0);
+}