Skip to content

Commit 9772ef5

Browse files
committed
Examples and get functions
1 parent ad3eac5 commit 9772ef5

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

src/SimpleTableaux.jl

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import Base: show
88

99
TabEntry = Rational{BigInt}
1010

11-
export DataFrame, Tableau
11+
export DataFrame, Tableau, get_A, get_b, get_c
12+
1213
"""
1314
Tableau(A::Matrix, b::Vector, c::Vector)
1415
15-
Create a `Tableau` datastructure for the linear program maximize `c'x` subject to `Ax ≤ b`.
16+
Create a `Tableau` data structure for the linear program maximize `c'x` subject to `Ax ≤ b`.
1617
"""
1718
struct Tableau
1819
M::Matrix{TabEntry} # place to hold the entire Tableau
@@ -32,6 +33,34 @@ struct Tableau
3233
end
3334
end
3435

36+
"""
37+
get_A(T::Tableau)
38+
39+
Return the coefficient matrix of this `Tableau`.
40+
"""
41+
function get_A(T::Tableau)
42+
return copy(T.M[1:(T.n_cons), 1:(T.n_vars)])
43+
end
44+
45+
"""
46+
get_b(T::Tableau)
47+
48+
Return the RHS of this `Tableau`.
49+
"""
50+
function get_b(T::Tableau)
51+
return copy(T.M[1:(T.n_cons), end])
52+
end
53+
54+
"""
55+
get_c(T::Tableau)
56+
57+
Return the objective function of this `Tableau`.
58+
"""
59+
function get_c(T::Tableau)
60+
c = T.M[end, 1:(T.n_vars)]
61+
return collect(-c)
62+
end
63+
3564
include("Exact.jl")
3665
include("DataFrame.jl")
3766

test/examples.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using SimpleTableaux
2+
3+
"""
4+
example1()
5+
6+
Sample linear program from here: https://www.youtube.com/watch?v=rzRZLGD_aeE
7+
"""
8+
function example1()
9+
A = [3 5; 4 1]
10+
b = [78; 36]
11+
c = [5; 4]
12+
return Tableau(A, b, c)
13+
end
14+
15+
"""
16+
example2()
17+
18+
Sample linear program from here: https://www.youtube.com/watch?v=rzRZLGD_aeE
19+
"""
20+
function example2()
21+
A = [3 5 10; 5 2 8; 8 10 3]
22+
b = [120; 6; 105]
23+
c = [3; 4; 1]
24+
return Tableau(A, b, c)
25+
end

0 commit comments

Comments
 (0)