'=========================================================================== ' Subject: OPTIMISER Date: 10-17-99 (22:41) ' Author: Nathiel T. Tinsley Code: QB, QBasic, PDS ' Origin: ntins2000@email.msn.com Packet: ALGOR.ABC '=========================================================================== REM *** OPTIMISER *** REM *** QBasic Version *** REM *** DRIVER *** REM *** INITIALISE *** TARGET1: CLS PRINT TAB(34); "OPTIMISER." PRINT PRINT PRINT INPUT "Enter Total Number of Rows "; a$ tr = INT(VAL(a$)) PRINT PRINT INPUT "Enter Total Number of Columns "; a$ tc = INT(VAL(a$)) DIM g(tr, tc), r$(tr), c$(tc), u(tc + 1), y(tr), h(tc), v(tr), w(tr + 1) CLS FOR j = 1 TO tr PRINT PRINT "Enter the Name of row"; j; INPUT r$(j) NEXT j CLS FOR j = 1 TO tc PRINT PRINT "Enter the Name of Column"; j; INPUT c$(j) NEXT j FOR j = 1 TO tr v(j) = j NEXT j FOR j = 1 TO tc h(j) = -j NEXT j FOR j = 1 TO tr CLS FOR j1 = 1 TO tc PRINT PRINT "Enter the Value of "; r$(j); "-"; c$(j1); INPUT a$ g(j, j1) = INT(VAL(a$)) NEXT j1, j GOSUB TARGET9 PRINT "Enter the Name of the "; INPUT "'x' Column "; x$ GOSUB TARGET9 PRINT "Enter the Name of the "; INPUT "'y' Column "; y$ GOSUB TARGET9 PRINT "Enter the Name of the "; INPUT "'z' Column "; z$ GOSUB TARGET9 PRINT "Enter the Name of the "; INPUT "'u' Row "; u$ GOSUB TARGET9 PRINT "Enter the Name of the "; INPUT "'w' Row "; w$ GOSUB TARGET9 PRINT "Enter the Name of the "; INPUT "'f' Box "; f$ CLS FOR j = 1 TO tr PRINT PRINT "For the r$(j);"; Row, Enter; ";" PRINT "the "; y$; " Value "; INPUT a$ y(j) = VAL(a$) NEXT j CLS FOR j = 1 TO tc PRINT PRINT "For the "; c$(j); " Column, Enter "; PRINT "the "; u$; " Value "; INPUT a$ u(j) = VAL(a$) NEXT j GOSUB TARGET2 GOSUB TARGET3 END REM *** MAIN LOOP *** TARGET2: FOR k = 1 TO 1000 CLS PRINT PRINT ">> Working"; k; "<<" REM *** GET PIVOT COLUMN *** pc = 0 be = 0 FOR j1 = 1 TO tc IF u(j1) > be THEN pc = j1 be = u(j1) END IF NEXT j1 IF be <= 0 THEN RETURN END IF REM *** GET PIVOT ROW *** se = 20000 pr = 0 FOR j = 1 TO tr q = g(j, pc) w(j) = q IF q <= .0001 GOTO TARGET4 IF y(j) / q <= se THEN se = y(j) / q pr = j END IF TARGET4: NEXT j w(tr + 1) = u(pc) IF pr = 0 THEN CLS PRINT "No Possible Solution." END END IF pe = g(pr, pc) GOSUB TARGET5 NEXT k PRINT "No Solution Found." END REM *** PIVOT ROW/PIVOT ELEMENT *** TARGET5: FOR j = 1 TO tc g(pr, j) = g(pr, j) / pe NEXT j y(pr) = y(pr) / pe REM *** ADJUST ROWS TO NEW PIVOT ROW *** FOR j = 1 TO tr IF j = pr GOTO TARGET6 x = g(j, pc) FOR j1 = 1 TO tc g(j, j1) = g(j, j1) - x * g(pr, j1) NEXT j1 y(j) = y(j) - x * y(pr) TARGET6: NEXT j x = u(pc) FOR j1 = 1 TO tc u(j1) = u(j1) - x * g(pr, j1) NEXT j1 u(tc + 1) = u(tc + 1) - x * y(pr) REM *** ADJUST PIVOT COLUMN *** FOR j = 1 TO tr g(j, pc) = -w(j) / pe NEXT j u(pc) = -w(tr + 1) / pe g(pr, pc) = 1 / pe x = h(pc) h(pc) = v(pr) v(pr) = x TARGET3: REM *** DISPLAY RESULTS *** CLS PRINT TAB(34); "RESULTS." GOSUB TARGET7 z = u(tc + 1) PRINT f$; GOSUB TARGET8 FOR j = 1 TO tc IF h(j) > 0 THEN PRINT x$; " "; r$(h(j)); z = -u(j) GOSUB TARGET8 END IF NEXT j FOR j = 1 TO tc IF h(j) <= 0 THEN PRINT w$; " "; c$(-h(j)); z = -u(j) GOSUB TARGET8 END IF NEXT j FOR j = 1 TO tr IF v(j) >= 0 THEN PRINT z$; " "; r$(v(j)); z = y(j) GOSUB TARGET8 END IF NEXT j RETURN REM *** ROUND THE RESULT *** TARGET8: z = INT((z + .5) * 100) / 100 PRINT " ="; z TARGET7: PRINT "-------------------------------------------------------------------------------" RETURN REM *** DIAGRAM *** TARGET9: CLS PRINT TAB(20); "x Columns y z" PRINT PRINT PRINT TAB(20); " r" PRINT PRINT TAB(20); " o" PRINT PRINT TAB(20); " w" PRINT PRINT TAB(20); " s" PRINT PRINT TAB(20); "u Row"; TAN(64); "f Box" PRINT PRINT TAB(20); "w Row" PRINT PRINT RETURN