Skip to content

Commit 7abee96

Browse files
committed
working
1 parent fb97e97 commit 7abee96

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

development/examples.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ function phase_one_example()
183183
return Tableau(A, b, c, false)
184184
end
185185

186+
function phase_one_infeasible()
187+
A = [
188+
2 0 5 2
189+
2 1 3 1
190+
-1 1 4 3
191+
]
192+
b = [5, -1, 2]
193+
c = [1, -1, 4, 4]
194+
return Tableau(A, b, c, false)
195+
end
196+
186197
function phase_one_trouble()
187198
A = [5 1 3; 1 1 3]
188199
b = [5, 5]

src/SimplexTableaux.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ include("Exact.jl")
2020
export Tableau,
2121
basic_vector,
2222
big_M_solve,
23+
big_M_tableau,
2324
check_basis,
2425
set_basis!,
2526
find_a_basis,

src/big_M.jl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function big_M_tableau(T::Tableau, M::Int=1000)
1717
AA = hcat(AA, eye(Int, m))
1818

1919
# create artifical c
20-
cc = vcat(0*c, M*ones(Int, m))
20+
cc = vcat(c, M*ones(Int, m))
2121

2222
TT = Tableau(AA, bb, cc, false)
2323

@@ -34,11 +34,25 @@ Solve the LP `T` using the big-M method.
3434
"""
3535
function big_M_solve(T::Tableau, M::Int=1000)
3636
TT = big_M_tableau(T, M)
37+
println("Solving augmented tableau")
3738
x = simplex_solve!(TT)
39+
40+
if isnothing(x)
41+
return nothing
42+
end
43+
# check that artificial vars are all zero
44+
45+
arts = x[(T.n_vars + 1):end]
46+
47+
if any(arts .≠ 0)
48+
@info "LP is possibly infeasible. Try a larger value than M = $M?"
49+
return nothing
50+
end
51+
3852
x = x[1:T.n_vars]
3953
B = infer_basis!(T, x)
4054
set_basis!(T, B)
41-
println("Final tableau\n")
55+
println("\nFinal tableau\n")
4256
println(T)
4357
v = value(T)
4458
println("Minimial value = $v = $(Float64(v))")

0 commit comments

Comments
 (0)