Skip to content

Commit 45a2fba

Browse files
committed
Better messages, new dual
1 parent bc21e63 commit 45a2fba

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SimplexTableaux"
22
uuid = "b49aa546-d643-4829-bb91-bc1e5e539d80"
33
authors = ["Ed Scheinerman <ers@jhu.edu>"]
4-
version = "0.1.4"
4+
version = "0.1.5"
55

66
[deps]
77
ChooseOptimizer = "858a232f-1959-5553-8cfc-91e1fd5304e2"

src/Dual.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
dual(T::Tableau)
3+
4+
Create a tableau that is dual to `T`.
5+
6+
Caveats:
7+
* `T` should have been created from canonical data (not standard). If not, an error is thrown.
8+
* The returned tableau is set up as a minimization problem so the value of the solved LP is negative the desired value. However, the basic feasible vector is correct.
9+
"""
10+
function dual(T::Tableau)::Tableau
11+
msg = "Tableau not from a canonical LP"
12+
13+
T = deepcopy(T)
14+
restore!(T)
15+
A, b, c = get_Abc(T)
16+
17+
m = T.n_cons
18+
n = T.n_vars
19+
20+
II = -T.M[2:end, (n - 1):(end - 1)]
21+
22+
if II eye(Int, m)
23+
error(msg)
24+
end
25+
A = A[:, 1:(n - m)]
26+
27+
if !iszero(c[(n - m + 1):end])
28+
error(msg)
29+
end
30+
c = c[1:(n - m)]
31+
32+
return Tableau(-A', -c, -b)
33+
end

src/LPsolve.jl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,29 @@ function lp_solve(T::Tableau, verbose::Bool=true)
1818
optimize!(MOD)
1919
status = Int(termination_status(MOD))
2020

21-
if status 1
22-
error("Linear program is either infeasible or unbounded. Status = $status")
21+
if status == 1
22+
if verbose
23+
obj_val = objective_value(MOD)
24+
println("Minimal objective value = $obj_val\n")
25+
end
26+
xval = JuMP.value.(x)
27+
return xval
2328
end
24-
if verbose
25-
obj_val = objective_value(MOD)
26-
println("Minimal objective value = $obj_val\n")
29+
30+
if status == 2
31+
if verbose
32+
@info "This linear program is infeasible."
33+
end
34+
return nothing
2735
end
2836

29-
xval = JuMP.value.(x)
37+
if status == 3
38+
if verbose
39+
@info "This linear program is unbounded"
40+
end
41+
return nothing
42+
end
3043

31-
return xval
44+
@info "Unknown termination status = $status"
45+
nothing
3246
end

src/SimplexTableaux.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export Tableau,
1818
big_M_solve!,
1919
big_M_tableau,
2020
check_basis,
21+
dual,
2122
set_basis!,
2223
find_a_basis,
2324
find_all_bases,
@@ -42,6 +43,7 @@ include("Solver.jl")
4243
include("LPsolve.jl")
4344
include("lap.jl")
4445
include("Pretty.jl")
46+
include("Dual.jl")
4547

4648
"""
4749
is_feasible(T::Tableau)::Bool

0 commit comments

Comments
 (0)