Skip to content

Commit a2880f7

Browse files
committed
duality fixed
1 parent 45a2fba commit a2880f7

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Dual.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ function dual(T::Tableau)::Tableau
1717
m = T.n_cons
1818
n = T.n_vars
1919

20-
II = -T.M[2:end, (n - 1):(end - 1)]
20+
II = -A[:, end-m+1:end]
2121

2222
if II eye(Int, m)
2323
error(msg)
2424
end
25-
A = A[:, 1:(n - m)]
25+
A = A[:, 1:n-m]
2626

2727
if !iszero(c[(n - m + 1):end])
2828
error(msg)

test/runtests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,19 @@ using SimplexTableaux
1717
set_basis!(T, [3, 4])
1818
@test !is_feasible(T)
1919
end
20+
21+
@testset "Duality" begin
22+
A = [11 2 11; 8 6 9; 8 8 5; 6 5 8; 4 1 2; 2 -1 4]
23+
b = [0, 1, 10, 3, 2, 5]
24+
c = [3, 4, 7]
25+
26+
T = Tableau(A, b, c)
27+
dT = dual(T)
28+
29+
simplex_solve!(T, false)
30+
v = value(T)
31+
32+
simplex_solve!(dT, false)
33+
dv = value(dT)
34+
@test v == -dv
35+
end

0 commit comments

Comments
 (0)