Skip to content

Commit 57bfb73

Browse files
committed
basis tracking
1 parent 1223fdc commit 57bfb73

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

docs/make.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
using Documenter, SimplexTableaux
55
makedocs(;
6-
pages = [
6+
pages=[
77
"Overview" => "index.md",
88
"Creating and Solving LPs" => "create.md",
99
"Other Functions" => "other.md",
1010
],
11-
sitename = "SimplexTableaux",
11+
sitename="SimplexTableaux",
1212
)

src/Pivoting.jl

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function matrix_pivot!(T::Tableau, i::Int, j::Int)
2424
end
2525
M[a, :] += -M[a, j] * M[i, :]
2626
end
27-
27+
infer_basis!(T)
2828
return T
2929
end
3030

@@ -102,3 +102,35 @@ function basis_pivot!(T::Tableau, enter::Int, leave::Int)
102102
push!(B, enter)
103103
set_basis!(T, collect(B))
104104
end
105+
106+
"""
107+
_is_std_basis_vector(v::Vector)::Bool
108+
109+
Return `true` is `v` is a standard basis vector (single 1, rest 0s).
110+
"""
111+
function _is_std_basis_vector(v::Vector)::Bool
112+
if !all(x==0 || x==1 for x in v) # must be all 0s and 1s
113+
return false
114+
end
115+
if sum(v) 1 # must have a single 1
116+
return false
117+
end
118+
return true
119+
end
120+
121+
"""
122+
infer_basis!(T::Tableau)
123+
124+
Determine the basic variables by seeing which columns in the tableau
125+
are standard basis vectors. Reset the stored basis in `T` to that result,
126+
or set the stored basis to all zeros if no basis can be inferred.
127+
"""
128+
function infer_basis!(T::Tableau)
129+
indicators = [_is_std_basis_vector(T.M[2:end, j + 1]) for j in 1:T.n_vars]
130+
newB = findall(indicators)
131+
if length(newB) T.n_cons
132+
T.B = zeros(Int, T.n_cons)
133+
return T.B
134+
end
135+
T.B = newB
136+
end

0 commit comments

Comments
 (0)