Skip to content

Commit e441b2d

Browse files
committed
work
1 parent 53ad614 commit e441b2d

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

development/cycling-tries.jl

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# source: https://web.ist.utl.pt/~mcasquilho/CD_Casquilho/LP2004Comp&OR_GassVinjamuri.pdf
2+
3+
using SimplexTableaux, SimpleGraphs, DrawSimpleGraphs, Plots
4+
5+
6+
7+
"""
8+
find_all_matrix_pivots(T::Tableau)
9+
10+
Return a list of tuples `(i,j)` at which `T` has a good matrix pivot
11+
at the `i,j`-entry.
12+
"""
13+
function find_all_matrix_pivots(T::Tableau)
14+
top_row = T.M[1, 2:(end - 1)]
15+
m, n = size(T.A)
16+
col_list = [j for j in 1:n if top_row[j] > 0]
17+
18+
result = Vector{Tuple{Int,Int}}()
19+
for j in col_list
20+
a = T.M[2:end, j + 1]
21+
b = T.M[2:end, end]
22+
rats = b .// a
23+
24+
for i in 1:m
25+
if a[i] < 0 || rats[i] < 0
26+
rats[i] = 1//0
27+
end
28+
end
29+
30+
min_rat = minimum(rats)
31+
32+
if min_rat == 1//0
33+
continue
34+
end
35+
36+
ilist = [i for i in 1:m if rats[i]==min_rat]
37+
38+
for i in ilist
39+
p = (i, j)
40+
push!(result, p)
41+
end
42+
end
43+
return result
44+
end
45+
46+
"""
47+
simplex_graph(T::Tableau)::DirectedGraph{Vector{Int}}
48+
49+
Create a `DirectedGraph` for every possible pivot of `T`.
50+
"""
51+
function simplex_graph(T::Tableau)::DirectedGraph{Vector{Int}}
52+
G = DirectedGraph{Vector{Int}}()
53+
54+
blist = find_all_bases(T)
55+
for B in blist
56+
add!(G, B)
57+
end
58+
59+
for B in blist
60+
set_basis!(T, B)
61+
plist = find_all_matrix_pivots(T)
62+
for ij in plist
63+
i, j = ij
64+
matrix_pivot!(T, i, j)
65+
BB = get_basis(T)
66+
add!(G, B, BB)
67+
println("$B --> $BB")
68+
set_basis!(T, B)
69+
end
70+
end
71+
72+
return G
73+
end
74+
75+
function _one_pass_trim(G::DirectedGraph)::Int
76+
kills = 0
77+
VV = vlist(G)
78+
for v in VV
79+
if in_deg(G, v)==0 || out_deg(G, v)==0
80+
delete!(G, v)
81+
kills+=1
82+
end
83+
end
84+
return kills
85+
end
86+
87+
import SimpleGraphs.trim
88+
function trim(G::DirectedGraph)
89+
while _one_pass_trim(G) > 0
90+
end
91+
end

development/examples.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,30 @@ function deg_picture()
150150
finish()
151151
end
152152

153+
# from the Gass and Vinjamuri paper
153154

155+
function example_kuhn()
156+
A = [
157+
1 0 0 -2 -9 1 9;
158+
0 1 0 1//3 1 -1//3 -2;
159+
0 0 1 2 3 -1 -12
160+
]
161+
b = [0; 0; 2]
162+
c = [0; 0; 0; -2; -3; 1; 12]
163+
164+
return Tableau(A, b, c, false)
165+
end
166+
167+
function example_chvatal()
168+
c = [10; -57; -9; -24]
169+
A = [
170+
1//2 -11//2 -5//2 9
171+
1//2 -3//2 -1//2 1
172+
1 0 0 0
173+
]
174+
b = [0; 0; 1]
175+
T = Tableau(A, b, -c)
176+
return T
177+
end
154178

155179
nothing

0 commit comments

Comments
 (0)