// rank of a node is the iteration at which is it removed, and we
// set the distance_from_source fields to this value.
- Vertex **active = new Vertex *[_nb_vertices];
+ Vertex **unreached = new Vertex *[_nb_vertices];
- // All the nodes are active at first
+ // All the nodes are unreached at first
for(int k = 0; k < _nb_vertices; k++) {
_vertices[k].distance_from_source = 0;
- active[k] = &_vertices[k];
+ unreached[k] = &_vertices[k];
}
scalar_t rank = 1;
- int nb_active = _nb_vertices, pred_nb_active;
+ int nb_unreached = _nb_vertices, pred_nb_unreached;
do {
// We set the distance_from_source field of all the vertices with incoming
// edges to the current rank value
- for(int f = 0; f < nb_active; f++) {
- v = active[f];
+ for(int f = 0; f < nb_unreached; f++) {
+ v = unreached[f];
for(e = v->leaving_edges; e; e = e->next_leaving_edge) {
e->terminal_vertex->distance_from_source = rank;
}
}
- pred_nb_active = nb_active;
- nb_active = 0;
+ pred_nb_unreached = nb_unreached;
+ nb_unreached = 0;
// We keep all the vertices with incoming nodes
- for(int f = 0; f < pred_nb_active; f++) {
- v = active[f];
+ for(int f = 0; f < pred_nb_unreached; f++) {
+ v = unreached[f];
if(v->distance_from_source == rank) {
- active[nb_active++] = v;
+ unreached[nb_unreached++] = v;
}
}
rank++;
- } while(nb_active < pred_nb_active);
+ } while(nb_unreached < pred_nb_unreached);
- delete[] active;
+ delete[] unreached;
- return nb_active == 0;
+ return nb_unreached == 0;
}
//////////////////////////////////////////////////////////////////////
}
void MTPGraph::find_best_paths(scalar_t *lengths) {
- scalar_t total_length;
+ scalar_t shortest_path_length;
Vertex *v;
Edge *e;
find_shortest_path();
- total_length = 0.0;
+ shortest_path_length = 0.0;
// Do we reach the sink?
if(_sink->pred_edge_toward_source) {
// original edge lengths
v = _sink;
while(v->pred_edge_toward_source) {
- total_length += v->pred_edge_toward_source->length;
+ shortest_path_length += v->pred_edge_toward_source->length;
v = v->pred_edge_toward_source->origin_vertex;
}
// If that length is negative
- if(total_length < 0.0) {
+ if(shortest_path_length < 0.0) {
#ifdef VERBOSE
- cerr << __FILE__ << ": Found a path of length " << total_length << endl;
+ cerr << __FILE__ << ": Found a path of length " << shortest_path_length << endl;
#endif
// Invert all the edges along the best path
v = _sink;
}
}
- } while(total_length < 0.0);
+ } while(shortest_path_length < 0.0);
// Put back the graph in its original state (i.e. invert edges which
// have been inverted in the process)