Last active
February 21, 2017 09:32
-
-
Save VincentTam/8084cb659febce2f696f20ad6b3677e9 to your computer and use it in GitHub Desktop.
My Octave dual simplex tableau generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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