+
+ scalar_t rank = 1;
+ while(nb_without_predecessors > 0) {
+ new_nb_without_predecessors = 0;
+ for(int l = 0; l < nb_without_predecessors; l++) {
+ v = _vertices + without_predecessors[l];
+ v->distance_from_source = rank;
+ for(e = v->leaving_edge_list_root; e; e = e->next_leaving_edge) {
+ tv = int(e->terminal_vertex - _vertices);
+ nb_predecessors[tv]--;
+ ASSERT(nb_predecessors[tv] >= 0);
+ if(nb_predecessors[tv] == 0) {
+ new_without_predecessors[new_nb_without_predecessors++] = tv;
+ }
+ }
+ }
+
+ swap(without_predecessors, new_without_predecessors);
+ nb_without_predecessors = new_nb_without_predecessors;
+ rank++;
+ }
+
+ for(int k = 0; k < _nb_vertices; k++) {
+ if(nb_predecessors[k] > 0) {
+ cerr << __FILE__ << ": The graph is not a DAG." << endl;
+ abort();
+ }
+ }
+
+ delete[] nb_predecessors;
+ delete[] without_predecessors;
+ delete[] new_without_predecessors;
+}
+
+//////////////////////////////////////////////////////////////////////
+
+void MTPGraph::print(ostream *os) {
+ for(int k = 0; k < _nb_edges; k++) {
+ Edge *e = _edges + k;
+ (*os) << e->origin_vertex - _vertices
+ << " -> "
+ << e->terminal_vertex - _vertices
+ << " (" << e->length << ")";
+ if(e->occupied) { (*os) << " *"; }
+ (*os) << endl;
+ }