MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / Simplex

Method Simplex

code/other/simplex.cpp:28–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26 D[r][s] = inv;
27 swap(B[r], N[s]); }
28 bool Simplex(int phase) {
29 int x = phase == 1 ? m + 1 : m;
30 while (true) {
31 int s = -1;
32 for (int j = 0; j <= n; j++) {
33 if (phase == 2 && N[j] == -1) continue;
34 if (s == -1 || D[x][j] < D[x][s] ||
35 D[x][j] == D[x][s] && N[j] < N[s]) s = j; }
36 if (D[x][s] > -EPS) return true;
37 int r = -1;
38 for (int i = 0; i < m; i++) {
39 if (D[i][s] < EPS) continue;
40 if (r == -1 || D[i][n + 1] / D[i][s] < D[r][n + 1] /
41 D[r][s] || (D[i][n + 1] / D[i][s]) == (D[r][n + 1] /
42 D[r][s]) && B[i] < B[r]) r = i; }
43 if (r == -1) return false;
44 Pivot(r, s); } }
45 DOUBLE Solve(VD &x) {
46 int r = 0;
47 for (int i = 1; i < m; i++) if (D[i][n + 1] < D[r][n + 1])

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected