Skip to content

Commit 9de21c8

Browse files
committed
fixed simplex
1 parent 389a8a5 commit 9de21c8

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

combinatorial_opt/simplex.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ template <typename Float = double, int DEPS = 30, bool Randomize = true> struct
120120
_initialize(A, b, c);
121121
_solve();
122122

123-
if (Randomize) {
123+
if (Randomize and x.size() == c.size()) {
124124
auto xtmp = x;
125125
for (unsigned j = 0; j < c.size(); j++) x[shuffle_idx[j]] = xtmp[j];
126126
}

combinatorial_opt/simplex.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ $
6767
- さもなくば原点が実行可能領域から飛び出るので
6868
- 複数存在する場合は添字番号最小(Bland's rule)
6969

70-
#### ワーストケースの回避
70+
### ワーストケースの回避
7171

7272
- 指数回のステップを要する恣意的なケースが知られている.
7373
- 特に [1] の p.43 (2.71) で挙げられているケースに関しては,変数・制約の順序をランダムに取り換えることで回避が可能であることを経験的に確認したので,デフォルトでこれを行うことにした.
74+
- ただし,常にシャッフルした方がよいわけではなく,[最小費用流の問題](https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_B) ではむしろ遅くなった.
7475

7576
## 問題例
7677

combinatorial_opt/test/simplex.mcf.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ int main() {
2424
b.push_back(cap);
2525
c.push_back(-cost);
2626
}
27-
Simplex<Float, 20> simplex(A, b, c);
27+
Simplex<Float, 20, false> simplex(A, b, c);
2828
cout << (simplex.infeasible ? -1 : -llround(simplex.ans)) << '\n';
2929
}

0 commit comments

Comments
 (0)