From: Francois Fleuret Date: Tue, 21 Aug 2012 19:59:32 +0000 (-0700) Subject: Update, seems to work! X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=79367565818d082d7cc94117be91384ba93dfe97;p=mtp.git Update, seems to work! --- diff --git a/ksp.cc b/ksp.cc index c40856f..1e55a33 100644 --- a/ksp.cc +++ b/ksp.cc @@ -20,7 +20,7 @@ // END_IP_HEADER // /////////////////////////////////////////////////////////////////////////// -#define VERBOSE +// #define VERBOSE #include #include @@ -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;