Skip to content

Commit 150df59

Browse files
committed
New make_canonical/make_standard
1 parent 40c095b commit 150df59

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

Project.toml

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

66
[deps]

src/Dual.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function dual(T::Tableau)::Tableau
1111
if is_canonical(T)
1212
return _canonical_dual(T)
1313
end
14-
@info "Dual of non-canonical LPs not implemented yet"
14+
@info "Dual of non-canonical LPs not implemented yet. You may try: dual(make_canonical(T))"
1515
return T
1616
end
1717

src/SimplexTableaux.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export Tableau,
3636
is_infeasible,
3737
is_unbounded,
3838
lp_solve,
39+
make_canonical,
40+
make_standard,
3941
phase_one_tableau,
4042
pivot!,
4143
ratios,
@@ -60,5 +62,6 @@ include("Status.jl")
6062
include("Bases.jl")
6163
include("big_M.jl")
6264
include("Ratios.jl")
65+
include("Swap_Types.jl")
6366

6467
end # module SimpleTableaux

src/Swap_Types.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
make_standard(T::Tableau)
3+
4+
Convert a Tableau for a canonical LP into a new, equivalent Tableau in standard form.
5+
"""
6+
function make_standard(T::Tableau)
7+
if !is_canonical(T)
8+
@info "This tabelau is already in standard form"
9+
return T
10+
end
11+
12+
AA, bb, cc = _make_standard(get_Abc(T)...)
13+
return Tableau(AA, bb, cc)
14+
end
15+
16+
"""
17+
make_canonical(T::Tableau)
18+
19+
Convert a Tableau for a standard form LP into a new, equivalent Tableau in canonical form.
20+
"""
21+
function make_canonical(T::Tableau)
22+
if is_canonical(T)
23+
@info "This tableau is already in canonical form"
24+
return T
25+
end
26+
AA, bb, cc = _make_canonical(get_Abc(T)...)
27+
return Tableau(AA, bb, cc, true)
28+
end

src/Tableau.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mutable struct Tableau
3131
end
3232

3333
if canonical
34-
A, b, c = make_standard(A, b, c)
34+
A, b, c = _make_standard(A, b, c)
3535
end
3636
A, b = _rank_fix(A, b)
3737

@@ -48,13 +48,13 @@ mutable struct Tableau
4848
end
4949
5050
"""
51-
make_standard(A::AbstractMatrix, b::Vector, c::Vector)
51+
_make_standard(A::AbstractMatrix, b::Vector, c::Vector)
5252
5353
Expand the `A` matrix with an identity matrix on the right and the `c`
5454
vector with zeros to convert a canonical LP min `c'*x` st `A*x b, x 0` into
5555
min `c'*x` st `A*x = b, x ≥ 0`. Returns the new matrices/vectors `A`, `b`, and `c`.
5656
"""
57-
function make_standard(A::AbstractMatrix, b::Vector, c::Vector)
57+
function _make_standard(A::AbstractMatrix, b::Vector, c::Vector)
5858
m, n = size(A)
5959
if length(b) ≠ m || length(c) ≠ n
6060
throw(ArgumentError("Size mismatch"))
@@ -66,6 +66,18 @@ function make_standard(A::AbstractMatrix, b::Vector, c::Vector)
6666
return AA, bb, cc
6767
end
6868
69+
"""
70+
_make_canonical(A::AbstractMatrix, b::Vector, c::Vector)
71+
72+
Convert data for a canonical LP into a standard LP. The equality constraints
73+
`Ax=b` are replaced by `Ax ≥ b` and `-Ax ≥ -b`.
74+
"""
75+
function _make_canonical(A::AbstractMatrix, b::Vector, c::Vector)
76+
new_A = [A; -A]
77+
new_b = [b; -b]
78+
return new_A, new_b, c
79+
end
80+
6981
"""
7082
restore(T::Tableau)
7183

0 commit comments

Comments
 (0)