Grafalgo
Library of useful data structures and algorithms
|
00001 00009 #include "ppFifo.h" 00010 00019 ppFifo::ppFifo(Flograph& fg1, int& floVal, bool batch) : prePush(fg1,floVal) { 00020 doit(batch); floVal = flowValue(); 00021 } 00022 00033 ppFifo::ppFifo(Flograph& fg1, int& floVal, bool batch, string& stats) 00034 : prePush(fg1,floVal) { 00035 doit(batch); floVal = flowValue(); 00036 stringstream ss; 00037 ss << satCount << " " << nonSatCount << " " << newDistCount 00038 << " " << relabCount; 00039 stats = ss.str(); 00040 } 00041 00047 void ppFifo::doit(bool batch) { 00048 unbal = new List(fg->n()); 00049 00050 // initialization 00051 vertex s = fg->src(); 00052 for (edge e = fg->firstOut(s); e != 0; e = fg->nextOut(s,e)) { 00053 vertex v = fg->head(e); 00054 if (v != fg->snk()) unbal->addLast(v); 00055 } 00056 00057 vertex u; 00058 if (!batch) { // incremental relabeling 00059 while (!unbal->empty()) { 00060 u = unbal->first(); unbal->removeFirst(); 00061 if (!balance(u)) { 00062 d[u] = 1 + minlabel(u); 00063 nextedge[u] = fg->firstAt(u); 00064 unbal->addLast(u); 00065 relabCount++; 00066 } 00067 } 00068 } else { // batch relabeling 00069 while (!unbal->empty()) { 00070 while (!unbal->empty()) { 00071 u = unbal->first(); unbal->removeFirst(); 00072 balance(u); 00073 } 00074 initdist(); 00075 for (u = 1; u <= fg->n(); u++) { 00076 if (u == fg->src() || u == fg->snk()) continue; 00077 nextedge[u] = fg->firstAt(u); 00078 if (excess[u] > 0) unbal->addLast(u); 00079 } 00080 } 00081 } 00082 delete unbal; 00083 } 00084 00090 void ppFifo::newUnbal(vertex u) { 00091 if (!unbal->member(u)) unbal->addLast(u); 00092 }