Properly puts the edge occupancy back to 0 when starting tracking.
[mtp.git] / mtp_graph.cc
index 32bdfdf..c213a07 100644 (file)
@@ -135,35 +135,35 @@ MTPGraph::~MTPGraph() {
 
 //////////////////////////////////////////////////////////////////////
 
-void MTPGraph::print() {
+void MTPGraph::print(ostream *os) {
   for(int k = 0; k < _nb_edges; k++) {
     Edge *e = _edges + k;
-    cout << e->origin_vertex->id
+    (*os) << e->origin_vertex->id
          << " -> "
          << e->terminal_vertex->id
          << " "
          << e->length;
     if(e->occupied) {
-      cout << " *";
+      (*os) << " *";
     }
-    cout << endl;
+    (*os) << endl;
   }
 }
 
-void MTPGraph::print_dot() {
-  cout << "digraph {" << endl;
-  cout << "  node[shape=circle];" << endl;
+void MTPGraph::print_dot(ostream *os) {
+  (*os) << "digraph {" << endl;
+  (*os) << "  node[shape=circle];" << endl;
   for(int k = 0; k < _nb_edges; k++) {
     Edge *e = _edges + k;
     if(e->occupied) {
-      cout << "  " << e->origin_vertex->id << " -> " << e->terminal_vertex->id
-           << " [style=bold,color=black,label=\"" << -e->length << "\"];" << endl;
+      (*os) << "  " << e->origin_vertex->id << " -> " << e->terminal_vertex->id
+           << " [style=bold,color=black,label=\"" << e->length << "\"];" << endl;
     } else {
-      cout << "  " << e->origin_vertex->id << " -> " << e->terminal_vertex->id
+      (*os) << "  " << e->origin_vertex->id << " -> " << e->terminal_vertex->id
            << " [color=gray,label=\"" << e->length << "\"];" << endl;
     }
   }
-  cout << "}" << endl;
+  (*os) << "}" << endl;
 }
 
 //////////////////////////////////////////////////////////////////////
@@ -265,6 +265,7 @@ void MTPGraph::find_best_paths(scalar_t *lengths) {
 
   for(int e = 0; e < _nb_edges; e++) {
     _edges[e].length = lengths[e];
+    _edges[e].occupied = 0;
     _edges[e].positivized_length = _edges[e].length;
   }
 
@@ -294,7 +295,7 @@ void MTPGraph::find_best_paths(scalar_t *lengths) {
       // If that length is negative
       if(total_length < 0.0) {
 #ifdef VERBOSE
-        cout << "Found a path of length " << total_length << endl;
+        cerr << "Found a path of length " << total_length << endl;
 #endif
         // Invert all the edges along the best path
         v = _sink;