Skip to content

Instantly share code, notes, and snippets.

@VincentTam
Last active February 21, 2017 09:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VincentTam/8084cb659febce2f696f20ad6b3677e9 to your computer and use it in GitHub Desktop.
Save VincentTam/8084cb659febce2f696f20ad6b3677e9 to your computer and use it in GitHub Desktop.
My Octave dual simplex tableau generator
# Show dual simplex tableau
# Prereq: matrix A, vectors b,c, basis
printf("Current basis:"); printf(" %2i", basis); disp("");
B = A(:,basis); cB = c(basis);
Bm1A = B\A; xB = B\b; zrow = cB'*Bm1A-c'; zval = cB'*xB;
if length(xB(xB<0)) >= 1
ovp = find(xB==min(xB(xB<0)))(1);
r = zrow./Bm1A(ovp,:); # ratio for display
T = [0:size(A)(2) 0; basis' Bm1A xB; 0 zrow zval; 0 r 0]
# compute min ratio
pr = Bm1A(ovp,:); # pivot row
pep = find(pr<0); # pivot elt pos array
if length(pep) >= 1
rr = zrow(pep)./pr(pep); # -ve ratio array
nvr = max(rr); # new var ratio
nv = find(r==nvr)(1);
printf("Leaving variable: %i\nEntering variable: %i\n", basis(ovp), nv);
basis(ovp) = nv;
else
disp("Simplex ended");
endif
else
T = [0:size(A)(2) 0; basis' Bm1A xB; 0 zrow zval]
disp("Simplex ended");
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment