Added the stress test. Ignore disconnected nodes when checking the residual error.
[mtp.git] / mtp_graph.cc
index d3c3c12..ecbbab5 100644 (file)
@@ -189,15 +189,25 @@ void MTPGraph::force_positivized_lengths() {
   scalar_t residual_error = 0.0;
   scalar_t max_error = 0.0;
 #endif
-  for(int n = 0; n < _nb_vertices; n++) {
-    for(Edge *e = _vertices[n].leaving_edges; e; e = e->next_leaving_edge) {
-      if(e->positivized_length < 0) {
+  for(int k = 0; k < _nb_edges; k++) {
+    Edge *e = _edges + k;
+
+    if(e->positivized_length < 0) {
+
 #ifdef VERBOSE
+      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;
       }
+#endif
+      e->positivized_length = 0.0;
     }
   }
 #ifdef VERBOSE