- do {
- new_front_size = 0;
- iteration++;
- for(int f = 0; f < front_size; f++) {
- v = front[f];
- for(Edge *e = v->root_edge; e; e = e->next) {
- d = v->distance_from_source + e->work_length;
- tv = e->terminal_vertex;
- if(d < tv->distance_from_source) {
- tv->distance_from_source = d;
- tv->pred_vertex = v;
- tv->pred_edge = e;
- if(tv->iteration < iteration) {
- new_front[new_front_size++] = tv;
- tv->iteration = iteration;
- }
- }
- }
- }
-
- tmp_front = new_front;
- new_front = front;
- front = tmp_front;
-
- tmp_front_size = new_front_size;
- new_front_size = front_size;
- front_size = tmp_front_size;
- } while(front_size > 0);
-}
-
-void Graph::find_best_paths(int *result_edge_occupation) {
- Vertex **front = new Vertex *[nb_vertices];
- Vertex **new_front = new Vertex *[nb_vertices];
-
- scalar_t total_length;
-
- initialize_work_lengths();
-
- do {
- total_length = 0.0;
- find_shortest_path(front, new_front);
- update_work_length();
-
- // Do we reach the sink?
- if(sink->pred_edge) {
-
- // If yes, compute the length of the best path
- for(Vertex *v = sink; v->pred_edge; v = v->pred_vertex) {
- total_length += v->pred_edge->length;
- }
-
- // If that length is negative
- if(total_length < 0.0) {
- // Invert all the edges along the best path
- for(Vertex *v = sink; v->pred_edge; v = v->pred_vertex) {
- Edge *e = v->pred_edge;
- e->terminal_vertex = v->pred_vertex;
- e->occupied = 1 - e->occupied;
- e->length = - e->length;
- e->work_length = - e->work_length;
- v->pred_vertex->del_edge(e);
- v->add_edge(e);
- }
- }
- }
- } while(total_length < 0.0);
-
- delete[] front;
- delete[] new_front;
-
- for(int n = 0; n < nb_vertices; n++) {
- Vertex *v = &vertices[n];
- for(Edge *e = v->root_edge; e; e = e->next) {
- result_edge_occupation[e->id] = e->occupied;