Vertex *v;
Edge *e;
+ // This procedure computes for each node the longest link from the
+ // source and abort if the graph is not a DAG. It works by removing
+ // successively nodes without predecessor: At the first iteration it
+ // removes the source, then the nodes with incoming edge only from
+ // the source, etc. If it can remove all the nodes that way, the
+ // graph is a DAG. If at some point it can not remove node anymore
+ // and there are some remaining nodes, the graph is not a DAG.
+
Vertex **active = new Vertex *[_nb_vertices];
- // We put everybody in the active
+ // All the nodes are active at first
for(int k = 0; k < _nb_vertices; k++) {
_vertices[k].distance_from_source = 0;
active[k] = &_vertices[k];
}
- int iteration = 1;
+ scalar_t nb_iterations = 1;
int nb_active = _nb_vertices, pred_nb_active;
do {
// We set the distance_from_source field of all the vertices with incoming
- // edges to the current iteration value
+ // edges to the current nb_iterations value
for(int f = 0; f < nb_active; f++) {
v = active[f];
for(e = v->leaving_edges; e; e = e->next_leaving_edge) {
- e->terminal_vertex->distance_from_source = iteration;
+ e->terminal_vertex->distance_from_source = nb_iterations;
}
}
// We keep all the vertices with incoming nodes
for(int f = 0; f < pred_nb_active; f++) {
v = active[f];
- if(v->distance_from_source == iteration) {
+ if(v->distance_from_source == nb_iterations) {
active[nb_active++] = v;
}
}
- iteration++;
+ nb_iterations++;
} while(nb_active < pred_nb_active);
delete[] active;
void MTPGraph::increase_distance_in_heap(Vertex *v) {
Vertex **c1, **c2, **h;
- // There is some beauty in that
+ // omg, that's beautiful
h = v->heap_slot;
while(c1 = _heap + 2 * (h - _heap + 1) - 1, c2 = c1 + 1,
(c1 < _heap + _heap_size && (*c1)->distance_from_source < (*h)->distance_from_source)
}
}
-void MTPGraph::dp_distance_propagation() {
+void MTPGraph::dp_compute_distances() {
Vertex *v, *tv;
Edge *e;
scalar_t d;
// Update the distance to the source in "good order"
- dp_distance_propagation();
+ dp_compute_distances();
do {
update_positivized_lengths();