X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=mtp_graph.cc;h=6537a7fe062318d05ad9c6577191e9654e88888d;hb=ea25591f0875e7fffdd398a661b6e52f2af81faf;hp=2dd145d31c0ff612159bab431e939b5c7cfb933c;hpb=fa06c8a9f47351526c626703be5c75591a499f76;p=mtp.git diff --git a/mtp_graph.cc b/mtp_graph.cc index 2dd145d..6537a7f 100644 --- a/mtp_graph.cc +++ b/mtp_graph.cc @@ -24,7 +24,6 @@ #include "mtp_graph.h" -// #include #include using namespace std; @@ -161,9 +160,6 @@ void MTPGraph::print_dot(ostream *os) { (*os) << " " << _sink->id << " [peripheries=2];" << endl; for(int k = 0; k < _nb_edges; k++) { Edge *e = _edges + k; - // (*os) << " " << e->origin_vertex->id << " -> " << e->terminal_vertex->id - // << ";" - // << endl; (*os) << " " << e->origin_vertex->id << " -> " << e->terminal_vertex->id << " ["; if(e->occupied) { @@ -191,10 +187,21 @@ void MTPGraph::force_positivized_lengths() { #endif for(int k = 0; k < _nb_edges; k++) { Edge *e = _edges + k; + if(e->positivized_length < 0) { + #ifdef VERBOSE - residual_error -= e->positivized_length; - max_error = max(max_error, - e->positivized_length); + if((e->origin_vertex->last_change < 0 && e->terminal_vertex->last_change >= 0) || + (e->origin_vertex->last_change >= 0 && e->terminal_vertex->last_change < 0)) { + cout << "Inconsistent non-connexity (this should never happen)." << endl; + abort(); + } + if(e->origin_vertex->last_change >= 0 && + e->terminal_vertex->last_change >= 0 && + e->positivized_length < 0) { + residual_error -= e->positivized_length; + max_error = max(max_error, - e->positivized_length); + } #endif e->positivized_length = 0.0; } @@ -218,8 +225,8 @@ int MTPGraph::is_dag() { int front_size = _nb_vertices, pred_front_size; do { - // We set the iteration field of all vertex with incoming edges to - // the current iteration value + // We set the last_change field of all the vertices with incoming + // edges to the current iteration value for(int f = 0; f < front_size; f++) { v = _front[f]; for(e = v->leaving_edges; e; e = e->next_leaving_edge) { @@ -230,7 +237,7 @@ int MTPGraph::is_dag() { pred_front_size = front_size; front_size = 0; - // We remove all the vertices without incoming edge + // We keep all the vertices with incoming nodes for(int f = 0; f < pred_front_size; f++) { v = _front[f]; if(v->last_change == iteration) { @@ -245,7 +252,7 @@ int MTPGraph::is_dag() { } // This method does not change the edge occupation. It only set -// properly for every vertex the fields distance_from_source and +// properly, for every vertex, the fields distance_from_source and // pred_edge_toward_source. void MTPGraph::find_shortest_path() { @@ -359,14 +366,14 @@ void MTPGraph::find_best_paths(scalar_t *lengths) { // Put back the graph in its original state (i.e. invert edges which // have been inverted in the process) for(int k = 0; k < _nb_edges; k++) { - Edge *e = _edges + k; + e = _edges + k; if(e->occupied) { e->invert(); } } } int MTPGraph::retrieve_one_path(Edge *e, Path *path) { Edge *f, *next = 0; - int l = 0; + int l = 0, nb_occupied_next; if(path) { path->nodes[l++] = e->origin_vertex->id; @@ -378,18 +385,24 @@ int MTPGraph::retrieve_one_path(Edge *e, Path *path) { path->nodes[l++] = e->terminal_vertex->id; path->length += e->length; } else l++; - int nb_choices = 0; + + nb_occupied_next = 0; for(f = e->terminal_vertex->leaving_edges; f; f = f->next_leaving_edge) { - if(f->occupied) { nb_choices++; next = f; } - if(nb_choices == 0) { - cerr << "retrieve_one_path: Non-sink end point." << endl; - abort(); - } - if(nb_choices > 1) { - cerr << "retrieve_one_path: Non node-disjoint paths." << endl; - abort(); - } + if(f->occupied) { nb_occupied_next++; next = f; } + } + +#ifdef DEBUG + if(nb_occupied_next == 0) { + cerr << "retrieve_one_path: Non-sink end point." << endl; + abort(); } + + else if(nb_occupied_next > 1) { + cerr << "retrieve_one_path: Non node-disjoint paths." << endl; + abort(); + } +#endif + e = next; } @@ -403,6 +416,7 @@ int MTPGraph::retrieve_one_path(Edge *e, Path *path) { void MTPGraph::retrieve_disjoint_paths() { Edge *e; + int p, l; for(int p = 0; p < nb_paths; p++) delete paths[p]; delete[] paths; @@ -414,10 +428,10 @@ void MTPGraph::retrieve_disjoint_paths() { paths = new Path *[nb_paths]; - int p = 0; + p = 0; for(e = _source->leaving_edges; e; e = e->next_leaving_edge) { if(e->occupied) { - int l = retrieve_one_path(e, 0); + l = retrieve_one_path(e, 0); paths[p] = new Path(l); retrieve_one_path(e, paths[p]); p++;