Properly puts the edge occupancy back to 0 when starting tracking.
[mtp.git] / mtp_graph.cc
index 8c79416..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;
 }
 
 //////////////////////////////////////////////////////////////////////
@@ -258,13 +258,14 @@ void MTPGraph::find_shortest_path(Vertex **_front, Vertex **_new_front) {
   } while(_front_size > 0);
 }
 
-void MTPGraph::find_best_paths(scalar_t *lengths, int *result_edge_occupation) {
+void MTPGraph::find_best_paths(scalar_t *lengths) {
   scalar_t total_length;
   Vertex *v;
   Edge *e;
 
   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, int *result_edge_occupation) {
       // 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;
@@ -314,11 +315,9 @@ void MTPGraph::find_best_paths(scalar_t *lengths, int *result_edge_occupation) {
   for(int k = 0; k < _nb_edges; k++) {
     Edge *e = _edges + k;
     if(e->occupied) { e->revert(); }
-    result_edge_occupation[k] = e->occupied;
   }
 }
 
-
 int MTPGraph::retrieve_one_path(Edge *e, int *nodes) {
   Edge *f, *next;
   int l = 0;
@@ -350,7 +349,7 @@ int MTPGraph::retrieve_one_path(Edge *e, int *nodes) {
   return l;
 }
 
-void MTPGraph::retrieve_paths() {
+void MTPGraph::retrieve_disjoint_paths() {
   Edge *e;
 
   for(int p = 0; p < nb_paths; p++) delete paths[p];
@@ -372,6 +371,4 @@ void MTPGraph::retrieve_paths() {
       p++;
     }
   }
-
-  cout << "NB_PATHS " << nb_paths << endl;
 }