1 REM SIMPLEX  
2 CLEAR  1000  
3 CLS  
10 CLS:PRINT  TAB(10);"LINEAR PROGRAMMING":PRINT   
20 PRINT "LINEAR PROGRAMMING IS A MATHEMATICAL TOOL DESIGNED TO HELP  
25 PRINT "MANAGEMENT TO MAKE OPTIMUM USE OF COMPETING RESOURCES.  
30 PRINT "IT IS A VERY POPULAR TECHNIQUE AND INVOLVES LINEAR INEQUALITIES  
35 PRINT "CALLED CONSTRAINTS AND A LINEAR OBJECTIVE FUNCTION WHICH  
40 PRINT "WE TRY TO MAXIMIZE OR MINIMIZE. THE INTERESTED USER MAY   
45 PRINT "CONSULT ANY INTRODUCTORY TEXT IN FINITE MATHEMATICS FOR  
50 PRINT "ADDITIONAL INFORMATION.   
55 PRINT :PRINT "THE NUMBERS OF VARIABLES AND CONSTRAINTS ARE ONLY   
60 PRINT "LIMITED BY AVAILABLE MEMORY BUT MANY VARIABLE PROBLEMS  
65 PRINT "MAY TAKE A LONG TIME TO RUN."  
90 PRINT :INPUT "PRESS ENTER TO BEGIN";Z9$  
100 CLS  
1000 DEFDBL  A,X  
1002 DEFINT  I,J,N,T,S,M  
1005 INPUT "NUMBER OF VARIABLES    ";M  
1010 INPUT "NUMBER OF CONSTRAINTS  ";N  
1011 DIM  A(N+2,N+M+2),X(M+N+2),D$(M+1)  
1012 FOR  JJ=1  TO  M  
1013 PRINT  "NAME OF VARIABLE ";JJ;" IS ";:INPUT  D$(JJ)  
1014 NEXT   
1015 REM SETTING UP MATRIX TABLEAU  
1020 FOR  I=2  TO  N+1  
1021 PRINT   
1022 PRINT  "CONSTRAINT ";I-1:PRINT   
1023 FOR  J=1  TO  M:PRINT "COEFFICIENT FOR VARIABLE";J;"  ";D$(J);" IS ";:INPUT  A(I,J): NEXT  J  
1025 INPUT "ENTER 1 IF <= CONSTRAINT, -1 IF >= CONSTRAINT ";A(I,M+1)  
1027 INPUT "ENTER AMOUNT FOR CONSTRAINT  ";A(I,M+2)  
1030 A(I,N+M+1)=A(I,M+2):A(I,M+2)=0  
1035 IF  I>2  THEN  A(I,M+I-1)=A(I,M+1):A(I,M+1)=0  
1037 PRINT :PRINT   
1040 NEXT  I  
1042 PRINT :PRINT   
1043 INPUT "PRESS Y IF A MINIMIZATION PROBLEM, OTHERWISE N";Z$:PRINT   
1044 IF  Z$<>"Y"  AND  Z$<>"N"  THEN  PRINT "INPUT ERROR":GOTO  1043  
1045 PRINT "ENTER COEFFICIENTS FOR OBJECTIVE FUNCTION":PRINT   
1047 FOR  J=1  TO  M:PRINT "COEFFICIENT FOR VARIABLE";J;"  ";D$(J);" IS ";:INPUT  A(1,J): X(J)=1:NEXT  J:R=1  
1050 IF  Z$="N"  THEN  FOR  J=1  TO  M:A(1,J)=-A(1,J):NEXT   
1065 FOR  I=2  TO  N+1  
1070 IF  A(I,M+I-1)<>-1  THEN  GOTO  1085 :  ELSE   X(M+I-1)=1  
1075 FOR  J=1  TO  N+M:A(N+2,J)=A(N+2,J)-A(I,J):NEXT  J  
1080 R=N+2  
1085 NEXT  I  
1090 S=1:T=1  
1095 FOR  I=2  TO  N+M:IF  A(R,I)>= A(R,S)  THEN  S=I  
1100 IF  A(R,I)<A(R,T)  THEN  T=I  
1110 NEXT  I  
1120 IF  A(R,T) < 0  THEN  GOTO  1140 :  ELSE   IF  R=1  THEN  GOTO  1300  
1130 IF  A(R,S) > 1E-4  THEN  GOTO  1280 :  ELSE   R=1: GOTO  1090  
1140 S=1  
1150 FOR  I=2  TO  N+1:IF  A(I,T)<=0  THEN  GOTO  1190  
1160 Y= A(I,N+M+1)/A(I,T): IF  S=1  THEN  GOTO  1180  
1170 IF  Y>= A(S,N+M+1)/A(S,T)  THEN  GOTO  1190  
1180 S=I  
1190 NEXT  I  
1200 IF  S=1  THEN  GOTO  1290  
1210 FOR  I=1  TO  N+M: IF  A(S,I)=1  THEN  GOTO  1230  
1220 NEXT  I  
1230 X(I)=1: X(T)=0: Y = A(S,T)  
1240 FOR  I = 1  TO  N+M+1: A(S,I)=A(S,I)/Y:NEXT   
1250 FOR  I= 1  TO  N+2: IF  I=S  THEN  GOTO  1270 :  ELSE   Y=A(I,T)  
1260 FOR  J=1  TO  N+M+1: A(I,J)=A(I,J)-Y*A(S,J):NEXT   
1270 NEXT  I: GOTO  1090  
1280 PRINT " NO SOLUTION ":STOP  
1290 PRINT "UNBOUNDED SOLUTION ":STOP  
1300 FOR  J=1  TO  M  
1310 IF  X(J) <> 0  THEN  X(J)=0: GOTO  1340  
1320 FOR  I=2  TO  N+1: IF  A(I,J)=1  THEN 1330 : NEXT  I  
1330 X(J)=A(I,N+M+1)  
1340 NEXT  J  
1350 Y = A(1,N+M+1):IF  Z$="Y"  THEN  Y=-Y  
1360 REM PRINT OUT SOLUTION  
1365 CLS:PRINT  "VALUE OF OBJECTIVE FUNCTION = ";Y  
1368 PRINT   
1370 FOR  I=1  TO  M  
1375 PRINT "AMOUNT OF ";D$(I);" I.E. X(";I;") = ";TAB(50); X(I)  
1380 NEXT  I  

