+int MTPGraph::is_dag() {
+ Vertex *v, *tv;
+ Edge *e;
+
+ // We put everybody in the front
+ for(int k = 0; k < _nb_vertices; k++) {
+ _vertices[k].iteration = 0;
+ _front[k] = &_vertices[k];
+ }
+
+ int front_size = _nb_vertices, nb_with_incoming;
+ int iteration = 0;
+ int new_front_size, pred_front_size;
+
+ do {
+ iteration++;
+ nb_with_incoming = 0;
+
+ // We set the iteration field of all vertex with incoming edges to
+ // the current iteration value
+ for(int f = 0; f < front_size; f++) {
+ v = _front[f];
+ for(e = v->leaving_edges; e; e = e->next_leaving_edge) {
+ tv = e->terminal_vertex;
+ tv->iteration = iteration;
+ }
+ }
+
+ new_front_size = 0;
+ // We remove all vertex without incoming edge
+ for(int f = 0; f < front_size; f++) {
+ v = _front[f];
+ if(v->iteration == iteration) {
+ _front[new_front_size++] = v;
+ }
+ }
+
+ pred_front_size = front_size;
+ front_size = new_front_size;
+ } while(front_size < pred_front_size);
+
+ return front_size == 0;
+}
+