Update, seems to work!
authorFrancois Fleuret <francois@fleuret.org>
Tue, 21 Aug 2012 19:59:32 +0000 (12:59 -0700)
committerFrancois Fleuret <francois@fleuret.org>
Tue, 21 Aug 2012 19:59:32 +0000 (12:59 -0700)
ksp.cc

diff --git a/ksp.cc b/ksp.cc
index c40856f..1e55a33 100644 (file)
--- a/ksp.cc
+++ b/ksp.cc
@@ -20,7 +20,7 @@
 // END_IP_HEADER                                                         //
 ///////////////////////////////////////////////////////////////////////////
 
-#define VERBOSE
+// #define VERBOSE
 
 #include <iostream>
 #include <fstream>
@@ -54,6 +54,7 @@ public:
 
 class Vertex {
 public:
+  int id;
   // These are the leaving edges
   Edge *first_edge;
   scalar_t distance;
@@ -93,15 +94,26 @@ public:
   void find_shortest_path();
   void find_best_paths();
   void print();
+  void print_occupied_edges();
 };
 
 void Graph::print() {
   for(int n = 0; n < nb_vertices; n++) {
-    cout << "VERTEX [" << n << "] ";
     for(Edge *e = vertices[n].first_edge; e; e = e->next) {
-      cout << " " << e->length;
+      cout << n << " -> " << e->terminal_vertex->id << " " << e->length << endl;
+    }
+  }
+}
+
+void Graph::print_occupied_edges() {
+  for(int n = 0; n < nb_vertices; n++) {
+    for(Edge *e = vertices[n].first_edge; e; e = e->next) {
+      if(e->occupied) {
+        int a = n, b = e->terminal_vertex->id;
+        if(a > b) { int c = a; a = b; b = c; }
+        cout << a << " " << b << endl;
+      }
     }
-    cout << endl;
   }
 }
 
@@ -116,6 +128,10 @@ Graph::Graph(int nb_vrt, int nb_edges,
   source = &vertices[src];
   sink = &vertices[snk];
 
+  for(int v = 0; v < nb_vertices; v++) {
+    vertices[v].id = v;
+  }
+
   for(int e = 0; e < nb_edges; e++) {
     vertices[from[e]].add_edge(&edge_heap[e]);
     edge_heap[e].occupied = 0;
@@ -205,7 +221,6 @@ void Graph::find_shortest_path() {
     tmp_front_size = new_front_size;
     new_front_size = front_size;
     front_size = tmp_front_size;
-    cout << "front_size = " << front_size << endl;
   } while(front_size > 0);
 
   delete[] front;
@@ -218,7 +233,9 @@ void Graph::find_best_paths() {
   initialize_fixed_lengths();
 
   do {
+#ifdef VERBOSE
     print();
+#endif
 
     total_length = 0.0;
     find_shortest_path();
@@ -251,7 +268,6 @@ void Graph::find_best_paths() {
           e->fixed_length = - e->fixed_length;
           v->pred_vertex->del_edge(e);
           v->add_edge(e);
-          cout << "INVERT!" << endl;
         }
       }
     }
@@ -294,6 +310,7 @@ int main(int argc, char **argv) {
     Graph graph(nb_vertices, nb_edges, ea, eb, el, source, sink);
 
     graph.find_best_paths();
+    graph.print_occupied_edges();
 
     delete[] el;
     delete[] ea;