///////////////////////////////////////////////////////////////////////////
-// START_IP_HEADER //
-// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the version 3 of the GNU General Public License //
// as published by the Free Software Foundation. //
// //
// Written by and Copyright (C) Francois Fleuret //
// Contact <francois.fleuret@idiap.ch> for comments & bug reports //
-// //
-// END_IP_HEADER //
///////////////////////////////////////////////////////////////////////////
+// Multi-Tracked Path
+
// #define VERBOSE
#include <iostream>
class Edge {
public:
int occupied;
- scalar_t length, fixed_length;
+ scalar_t length, work_length;
Vertex *terminal_vertex;
Edge *next, *pred;
};
int source, int sink);
~Graph();
- void initialize_fixed_lengths();
- void update_fixed_length();
+ void initialize_work_lengths();
+ void update_work_length();
void find_shortest_path();
void find_best_paths();
void print();
delete[] edge_heap;
}
-void Graph::initialize_fixed_lengths() {
+void Graph::initialize_work_lengths() {
scalar_t length_min = 0;
for(int n = 0; n < nb_vertices; n++) {
for(Edge *e = vertices[n].first_edge; e; e = e->next) {
}
for(int n = 0; n < nb_vertices; n++) {
for(Edge *e = vertices[n].first_edge; e; e = e->next) {
- e->fixed_length = e->length - length_min;
+ e->work_length = e->length - length_min;
}
}
}
-void Graph::update_fixed_length() {
+void Graph::update_work_length() {
for(int n = 0; n < nb_vertices; n++) {
scalar_t d = vertices[n].distance;
for(Edge *e = vertices[n].first_edge; e; e = e->next) {
- e->fixed_length += d - e->terminal_vertex->distance;
+ e->work_length += d - e->terminal_vertex->distance;
}
}
}
#ifdef DEBUG
for(int n = 0; n < nb_vertices; n++) {
for(Edge *e = vertices[n].first_edge; e; e = e->next) {
- if(e->fixed_length < 0) {
+ if(e->work_length < 0) {
cerr << "DEBUG error in find_shortest_path: Edge fixed lengths have to be positive."
<< endl;
abort();
for(int f = 0; f < front_size; f++) {
v = front[f];
for(Edge *e = v->first_edge; e; e = e->next) {
- d = v->distance + e->fixed_length;
+ d = v->distance + e->work_length;
tv = e->terminal_vertex;
if(d < tv->distance) {
tv->distance = d;
void Graph::find_best_paths() {
scalar_t total_length;
- initialize_fixed_lengths();
+ initialize_work_lengths();
do {
#ifdef VERBOSE
total_length = 0.0;
find_shortest_path();
- update_fixed_length();
+ update_work_length();
// Do we reach the sink?
if(sink->pred_edge) {
e->terminal_vertex = v->pred_vertex;
e->occupied = 1 - e->occupied;
e->length = - e->length;
- e->fixed_length = - e->fixed_length;
+ e->work_length = - e->work_length;
v->pred_vertex->del_edge(e);
v->add_edge(e);
}