Skip to content

Commit

Permalink
Test not calling setpi in MCMF stress test
Browse files Browse the repository at this point in the history
  • Loading branch information
simonlindholm committed Jan 14, 2024
1 parent 7868c30 commit 8a7738f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions stress-tests/graph/MinCostMaxFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,18 @@ void testMatching() {
}

void testNeg() {
const int ITS = 1000000;
int ed[100][100];
rep(it,0,1000000) {
int negs = 0;
rep(it,0,ITS) {
size_t lasti = ::i;
int N = rand() % 7 + 2;
int M = rand() % 17;
int S = 0, T = 1;
MCMF mcmf(N);
MCMF2 mcmf2(N);
rep(i,0,N) rep(j,0,N) ed[i][j] = 0;
bool anyneg = false;
rep(eid,0,M) {
int i = rand() % N, j = rand() % N;
if (i != j && !ed[i][j]) {
Expand All @@ -181,15 +184,20 @@ void testNeg() {
int co = rand() % 11 - 3;
mcmf.addEdge(i, j, fl, co);
mcmf2.addEdge(i, j, fl, co);
if (co < 0) anyneg = true;
}
}
if (!mcmf.setpi(S)) // has negative loops
continue;
negs += anyneg;
if (anyneg || rand() % 3 == 0) {
if (!mcmf.setpi(S)) // has negative loops
continue;
}
auto pa = mcmf.maxflow(S, T);
auto pa2 = mcmf2.maxflow(S, T);
assert(pa == pa2);
::i = lasti;
}
// cerr << negs << "/" << ITS << " graphs with negative edge costs" << endl;
cout<<"Tests passed!"<<endl;
}

Expand Down

0 comments on commit 8a7738f

Please sign in to comment.