ChipMaster's bwBASIC This also includes history going back to v2.10. *WARN* some binary files might have been corrupted by CRLF.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

82 lines
3.3 KiB

  1. 1 REM SIMPLEX
  2. 2 CLEAR 1000
  3. 3 CLS
  4. 10 CLS:PRINT TAB(10);"LINEAR PROGRAMMING":PRINT
  5. 20 PRINT "LINEAR PROGRAMMING IS A MATHEMATICAL TOOL DESIGNED TO HELP
  6. 25 PRINT "MANAGEMENT TO MAKE OPTIMUM USE OF COMPETING RESOURCES.
  7. 30 PRINT "IT IS A VERY POPULAR TECHNIQUE AND INVOLVES LINEAR INEQUALITIES
  8. 35 PRINT "CALLED CONSTRAINTS AND A LINEAR OBJECTIVE FUNCTION WHICH
  9. 40 PRINT "WE TRY TO MAXIMIZE OR MINIMIZE. THE INTERESTED USER MAY
  10. 45 PRINT "CONSULT ANY INTRODUCTORY TEXT IN FINITE MATHEMATICS FOR
  11. 50 PRINT "ADDITIONAL INFORMATION.
  12. 55 PRINT :PRINT "THE NUMBERS OF VARIABLES AND CONSTRAINTS ARE ONLY
  13. 60 PRINT "LIMITED BY AVAILABLE MEMORY BUT MANY VARIABLE PROBLEMS
  14. 65 PRINT "MAY TAKE A LONG TIME TO RUN."
  15. 90 PRINT :INPUT "PRESS ENTER TO BEGIN";Z9$
  16. 100 CLS
  17. 1000 DEFDBL A,X
  18. 1002 DEFINT I,J,N,T,S,M
  19. 1005 INPUT "NUMBER OF VARIABLES ";M
  20. 1010 INPUT "NUMBER OF CONSTRAINTS ";N
  21. 1011 DIM A(N+2,N+M+2),X(M+N+2),D$(M+1)
  22. 1012 FOR JJ=1 TO M
  23. 1013 PRINT "NAME OF VARIABLE ";JJ;" IS ";:INPUT D$(JJ)
  24. 1014 NEXT
  25. 1015 REM SETTING UP MATRIX TABLEAU
  26. 1020 FOR I=2 TO N+1
  27. 1021 PRINT
  28. 1022 PRINT "CONSTRAINT ";I-1:PRINT
  29. 1023 FOR J=1 TO M:PRINT "COEFFICIENT FOR VARIABLE";J;" ";D$(J);" IS ";:INPUT A(I,J): NEXT J
  30. 1025 INPUT "ENTER 1 IF <= CONSTRAINT, -1 IF >= CONSTRAINT ";A(I,M+1)
  31. 1027 INPUT "ENTER AMOUNT FOR CONSTRAINT ";A(I,M+2)
  32. 1030 A(I,N+M+1)=A(I,M+2):A(I,M+2)=0
  33. 1035 IF I>2 THEN A(I,M+I-1)=A(I,M+1):A(I,M+1)=0
  34. 1037 PRINT :PRINT
  35. 1040 NEXT I
  36. 1042 PRINT :PRINT
  37. 1043 INPUT "PRESS Y IF A MINIMIZATION PROBLEM, OTHERWISE N";Z$:PRINT
  38. 1044 IF Z$<>"Y" AND Z$<>"N" THEN PRINT "INPUT ERROR":GOTO 1043
  39. 1045 PRINT "ENTER COEFFICIENTS FOR OBJECTIVE FUNCTION":PRINT
  40. 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
  41. 1050 IF Z$="N" THEN FOR J=1 TO M:A(1,J)=-A(1,J):NEXT
  42. 1065 FOR I=2 TO N+1
  43. 1070 IF A(I,M+I-1)<>-1 THEN GOTO 1085 : ELSE X(M+I-1)=1
  44. 1075 FOR J=1 TO N+M:A(N+2,J)=A(N+2,J)-A(I,J):NEXT J
  45. 1080 R=N+2
  46. 1085 NEXT I
  47. 1090 S=1:T=1
  48. 1095 FOR I=2 TO N+M:IF A(R,I)>= A(R,S) THEN S=I
  49. 1100 IF A(R,I)<A(R,T) THEN T=I
  50. 1110 NEXT I
  51. 1120 IF A(R,T) < 0 THEN GOTO 1140 : ELSE IF R=1 THEN GOTO 1300
  52. 1130 IF A(R,S) > 1E-4 THEN GOTO 1280 : ELSE R=1: GOTO 1090
  53. 1140 S=1
  54. 1150 FOR I=2 TO N+1:IF A(I,T)<=0 THEN GOTO 1190
  55. 1160 Y= A(I,N+M+1)/A(I,T): IF S=1 THEN GOTO 1180
  56. 1170 IF Y>= A(S,N+M+1)/A(S,T) THEN GOTO 1190
  57. 1180 S=I
  58. 1190 NEXT I
  59. 1200 IF S=1 THEN GOTO 1290
  60. 1210 FOR I=1 TO N+M: IF A(S,I)=1 THEN GOTO 1230
  61. 1220 NEXT I
  62. 1230 X(I)=1: X(T)=0: Y = A(S,T)
  63. 1240 FOR I = 1 TO N+M+1: A(S,I)=A(S,I)/Y:NEXT
  64. 1250 FOR I= 1 TO N+2: IF I=S THEN GOTO 1270 : ELSE Y=A(I,T)
  65. 1260 FOR J=1 TO N+M+1: A(I,J)=A(I,J)-Y*A(S,J):NEXT
  66. 1270 NEXT I: GOTO 1090
  67. 1280 PRINT " NO SOLUTION ":STOP
  68. 1290 PRINT "UNBOUNDED SOLUTION ":STOP
  69. 1300 FOR J=1 TO M
  70. 1310 IF X(J) <> 0 THEN X(J)=0: GOTO 1340
  71. 1320 FOR I=2 TO N+1: IF A(I,J)=1 THEN 1330 : NEXT I
  72. 1330 X(J)=A(I,N+M+1)
  73. 1340 NEXT J
  74. 1350 Y = A(1,N+M+1):IF Z$="Y" THEN Y=-Y
  75. 1360 REM PRINT OUT SOLUTION
  76. 1365 CLS:PRINT "VALUE OF OBJECTIVE FUNCTION = ";Y
  77. 1368 PRINT
  78. 1370 FOR I=1 TO M
  79. 1375 PRINT "AMOUNT OF ";D$(I);" I.E. X(";I;") = ";TAB(50); X(I)
  80. 1380 NEXT I