@@ -32,117 +32,8 @@ export Tableau,
3232 swap!,
3333 value
3434
35- # Tableau struture is based on standard minimization LP:
36- # min c'*x st Ax ≥ b, x≥0
37- #
38- # 1 | -c^T | 0 <== single row
39- # ---+------+----
40- # 0 | A | b <== m rows
41-
42- """
43- Tableau(A::Matrix, b::Vector, c::Vector)
44-
45- Create a `Tableau` data structure for the linear program minimize `c' * x` subject to `A * x ≥ b, x ≥ 0`.
46-
47- If matrix and vectors are already in standard form, then use `Tableau(A, b, c, false)`.
48- """
49- struct Tableau
50- M:: Matrix{_Exact} # place to hold the entire Tableau
51- A:: Matrix # (original) A matrix
52- b:: Vector # (original) RHS, b vector
53- c:: Vector # (original) objective coefficients, c vector
54- n_vars:: Int # number of variables in the LP
55- n_cons:: Int # number of constraints in the LP
56-
57- function Tableau(A:: AbstractMatrix , b:: Vector , c:: Vector , is_cannonical:: Bool = true )
58- m, n = size(A)
59- if length(b) ≠ m || length(c) ≠ n
60- throw(ArgumentError(" Size mismatch" ))
61- end
62-
63- if is_cannonical
64- A, b, c = make_standard(A, b, c)
65- end
66- m, n = size(A)
67- top_row = hcat(1 , - c' , 0)
68- body = hcat(zeros(Int, m), A, b)
69-
70- M = vcat(top_row, body)
71-
72- # test rank of M[2:end,2:end-1]
73- if rankx(M[2:end, 2:(end - 1)]) ≠ m
74- @warn("Rank difficient Tableau")
75- end
76-
77- return new(M, A, b, c, n, m)
78- end
79- end
80-
81- """
82- make_standard(A::AbstractMatrix, b::Vector, c::Vector)
83-
84- Exand the `A` matrix with an identity matrix on the right and the `b`
85- vector with zeros to convert a canonical LP min `c' * x` st ` A* x ≥ b, x ≥ 0 ` into
86- min ` c' *x` st `A*x = b, x ≥ 0`. Returns the new matrices/vectors `A`, `b`, and `c`.
87- """
88- function make_standard(A::AbstractMatrix, b::Vector, c::Vector)
89- m, n = size(A)
90- if length(b) ≠ m || length(c) ≠ n
91- throw(ArgumentError("Size mismatch"))
92- end
93- AA = hcat(A, -Matrix(I, m, m))
94- bb = b
95- cc = vcat(c, zeros(Int, m))
96-
97- return AA, bb, cc
98- end
99-
100- """
101- restore(T::Tableau)
102-
103- Create a new `Tableau` based on the original data used to create `T`.
104-
105- See also `restore!`.
106- """
107- function restore(T::Tableau)
108- return Tableau(T.A, T.b, T.c, false)
109- end
110-
111- """
112- get_Abc(T::Tableau)
113-
114- Returns a 3-tuple containing copies of the matrix `A`
115- and the vectors `b` and `c` used to create `T`.
116- """
117- function get_Abc(T::Tableau)
118- return copy(T.A), copy(T.b), copy(T.c)
119- end
120-
121- """
122- restore!(T::Tableau)
123-
124- Restore a `Tableau` based on the original data used to create it.
125- """
126- function restore!(T::Tableau)
127- TT = restore(T)
128- m, n = size(TT.M)
129- for i in 1:m
130- for j in 1:n
131- T.M[i, j] = TT.M[i, j]
132- end
133- end
134- return T
135- end
136-
137- """
138- value(T::Tableau, x::Vector)
139-
140- Return the value of the LP in `T` at the point `x`.
141- """
142- function value(T::Tableau, x::Vector)
143- return T.c' * x
144- end
14535
36+ include(" Tableau.jl" )
14637include(" Pivoting.jl" )
14738include(" Solver.jl" )
14839include(" LPsolve.jl" )
0 commit comments