void Graph<captype,tcaptype,flowtype>::maxflow_reuse_trees_init() { node* i; node* j; node* queue = queue_first[1]; arc* a; nodeptr* np; queue_first[0] = queue_last[0] = NULL; queue_first[1] = queue_last[1] = NULL; orphan_first = orphan_last = NULL; TIME ++; while ((i=queue)) { queue = i->next; if (queue == i) queue = NULL; i->next = NULL; i->is_marked = 0; set_active(i); if (i->tr_cap == 0) { if (i->parent) set_orphan_rear(i); continue; } if (i->tr_cap> 0) { if (!i->parent || i->is_sink) { i->is_sink = 0; for (a=i->first; a; a=a->next) { j = a->head; if (!j->is_marked) { if (j->parent == a->sister) set_orphan_rear(j); if (j->parent && j->is_sink && a->r_cap> 0) set_active(j); } } add_to_changed_list(i); } } else { if (!i->parent || !i->is_sink) { i->is_sink = 1; for (a=i->first; a; a=a->next) { j = a->head; if (!j->is_marked) { if (j->parent == a->sister) set_orphan_rear(j); if (j->parent && !j->is_sink && a->sister->r_cap> 0) set_active(j); } } add_to_changed_list(i); } } i->parent = TERMINAL; i -> TS = TIME; i -> DIST = 1; } //test_consistency(); /* adoption */ while ((np=orphan_first)) { orphan_first = np -> next; i = np -> ptr; nodeptr_block -> Delete(np); if (!orphan_first) orphan_last = NULL; if (i->is_sink) process_sink_orphan(i); else process_source_orphan(i); } /* adoption end */ //test_consistency(); }
void Graph<captype,tcaptype,flowtype>::process_sink_orphan(node *i) { node *j; arc *a0, *a0_min = NULL, *a; int d, d_min = INFINITE_D; /* trying to find a new parent */ for (a0=i->first; a0; a0=a0->next) if (a0->r_cap) { j = a0 -> head; if (j->is_sink && (a=j->parent)) { /* checking the origin of j */ d = 0; while ( 1 ) { if (j->TS == TIME) { d += j -> DIST; break; } a = j -> parent; d ++; if (a==TERMINAL) { j -> TS = TIME; j -> DIST = 1; break; } if (a==ORPHAN) { d = INFINITE_D; break; } j = a -> head; } if (d<INFINITE_D) /* j originates from the sink - done */ { if (d<d_min) { a0_min = a0; d_min = d; } /* set marks along the path */ for (j=a0->head; j->TS!=TIME; j=j->parent->head) { j -> TS = TIME; j -> DIST = d --; } } } } if (i->parent = a0_min) { i -> TS = TIME; i -> DIST = d_min + 1; } else { /* no parent is found */ add_to_changed_list(i); /* process neighbors */ for (a0=i->first; a0; a0=a0->next) { j = a0 -> head; if (j->is_sink && (a=j->parent)) { if (a0->r_cap) set_active(j); if (a!=TERMINAL && a!=ORPHAN && a->head==i) { set_orphan_rear(j); // add j to the end of the adoption list } } } } }
void QPBO<REAL>::maxflow_reuse_trees_init() { Node* i; Node* j; Node* queue = queue_first[1]; Arc* a; nodeptr* np; queue_first[0] = queue_last[0] = NULL; queue_first[1] = queue_last[1] = NULL; orphan_first = orphan_last = NULL; TIME ++; while ((i=queue)) { queue = i->next; if (queue == i) queue = NULL; if (IsNode0(i)) { if (i->is_removed) continue; } else { if (GetMate1(i)->is_removed) continue; } i->next = NULL; i->is_marked = 0; set_active(i); if (i->tr_cap == 0) { if (i->parent) set_orphan_rear(i); continue; } if (i->tr_cap > 0) { if (!i->parent || i->is_sink) { i->is_sink = 0; for (a=i->first; a; a=a->next) { j = a->head; if (!j->is_marked) { if (j->parent == a->sister) set_orphan_rear(j); if (j->parent && j->is_sink && a->r_cap > 0) set_active(j); } } add_to_changed_list(i); } } else { if (!i->parent || !i->is_sink) { i->is_sink = 1; for (a=i->first; a; a=a->next) { j = a->head; if (!j->is_marked) { if (j->parent == a->sister) set_orphan_rear(j); if (j->parent && !j->is_sink && a->sister->r_cap > 0) set_active(j); } } add_to_changed_list(i); } } i->parent = QPBO_MAXFLOW_TERMINAL; i -> TS = TIME; i -> DIST = 1; } code_assert(stage == 1); //test_consistency(); /* adoption */ while ((np=orphan_first)) { orphan_first = np -> next; i = np -> ptr; nodeptr_block -> Delete(np); if (!orphan_first) orphan_last = NULL; if (i->is_sink) process_sink_orphan(i); else process_source_orphan(i); } /* adoption end */ //test_consistency(); }