Skip to content

Commit 53ad614

Browse files
committed
Working?
1 parent a353409 commit 53ad614

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
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.0.7"
4+
version = "0.0.8"
55

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

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ See [the documentation](https://docs.juliahub.com/General/SimplexTableaux/stable
1616
## Caveats
1717

1818
As a demonstration project, this is not suitable for solving actual linear programming (LP) problems.
19-
At present it will fail if:
20-
* The LP is infeasible.
21-
* The LP is unbounded.
22-
* Other unidentified reasons. (In other words, still buggy.)
19+
20+
At present the user needs to specify a starting basis; see the documentation.
2321

2422
This module is set up for minimization problems only.
2523

development/examples.jl

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function unbounded_example()
4949
b = [5; 4; -3]
5050
c = [-1; -2]
5151
T = Tableau(A, b, c)
52+
set_basis!(T, [1, 2, 5])
5253
return T
5354
end
5455

@@ -118,21 +119,21 @@ end
118119

119120
function deg_picture()
120121
newdraw()
121-
122-
L1 = Line(3,4,8,5)
123-
L2 = Line(8,5,6,2)
124-
L3 = Line(6,2,1,1)
125-
L4 = Line(1,1,3,4)
126-
L5 = Line(3,4,4,5)
127-
128-
p1 = Point(1,1)
129-
p2 = Point(3,4)
130-
p3 = Point(8,5)
131-
p4 = Point(6,2)
132-
pp = [p1,p2,p3,p4]
133-
134-
draw_xaxis(-1,9)
135-
draw_yaxis(-1,6)
122+
123+
L1 = Line(3, 4, 8, 5)
124+
L2 = Line(8, 5, 6, 2)
125+
L3 = Line(6, 2, 1, 1)
126+
L4 = Line(1, 1, 3, 4)
127+
L5 = Line(3, 4, 4, 5)
128+
129+
p1 = Point(1, 1)
130+
p2 = Point(3, 4)
131+
p3 = Point(8, 5)
132+
p4 = Point(6, 2)
133+
pp = [p1, p2, p3, p4]
134+
135+
draw_xaxis(-1, 9)
136+
draw_yaxis(-1, 6)
136137

137138
draw_xtick(1:8)
138139
draw_ytick(1:5)
@@ -141,14 +142,14 @@ function deg_picture()
141142
draw(p)
142143
end
143144

144-
145-
LL = [L1,L2,L3,L4,L5]
145+
LL = [L1, L2, L3, L4, L5]
146146

147147
for L in LL
148148
draw(L)
149149
end
150150
finish()
151-
152151
end
153152

153+
154+
154155
nothing

src/SimplexTableaux.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export Tableau,
2323
find_a_basis,
2424
find_all_bases,
2525
find_pivot,
26+
find_pivot_column,
2627
get_Abc,
2728
get_basis,
2829
is_feasible,

src/Solver.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ function find_pivot(T::Tableau)
5757
end
5858

5959
function find_pivot_column(T::Tableau)
60-
for i in 1:T.n_vars
61-
if T.M[1, i + 1] > 0
62-
return i
63-
end
60+
reduced_costs = T.M[1, 2:(end - 1)] # top row between separators
61+
rc, j = findmax(reduced_costs)
62+
if rc <= 0
63+
return 0 # no pivot possible
6464
end
65-
return 0 # no valid column
65+
return j
6666
end
6767

6868
"""
@@ -80,18 +80,21 @@ function simplex_solve!(T::Tableau, verbose::Bool=true)
8080
println(T)
8181
end
8282

83-
pivot_count = 0
83+
pivot_count = 0
8484

8585
while !is_optimal(T)
8686
p = find_pivot(T)
8787
if 0 p
88-
@error "Cannot solve this LP. Is it infeasible? Unbounded?"
88+
@info "This linear program is unbounded"
89+
return nothing
8990
end
9091
basis_pivot!(T, p...)
9192
pivot_count += 1
9293
if verbose
9394
in, out = p
94-
println("Pivot $(pivot_count): column $out leaves basis and column $in enters\n")
95+
println(
96+
"Pivot $(pivot_count): column $out leaves basis and column $in enters\n"
97+
)
9598
println(T)
9699
end
97100
end

0 commit comments

Comments
 (0)