1 REM ASSIGN
5 CLEAR 100
10 CLS:PRINT TAB(20);"ASSIGNMENT COST":PRINT
20 PRINT"THE ASSIGNMENT PROBLEM EXAMINED IN THIS PROGRAM IS OF THE
25 PRINT"FOLLOWING TYPE: THERE ARE A FIXED NUMBER OF JOBS TO BE DONE
30 PRINT"(SAY N JOBS), AND THE SAME NUMBER(N) OF POSSIBLE ASSIGNEES,
35 PRINT"I.E. THOSE WHO CAN DO THE JOB. THE ASSIGNEES HAVE DIFFERENT
40 PRINT"EFFICIENCIES FOR THE DIFFERENT JOBS. IN FACT FOR EACH 
45 PRINT"JOB-ASSIGNEE COMBINATION WE CAN ASSIGN SOME COST. EACH
50 PRINT"ASSIGNEE IS ASSIGNED TO 1 AND ONLY 1 JOB. THE PROGRAM WILL
55 PRINT"FIND THE ASSIGNMENT WHICH MINIMIZES TOTAL COST.
60 PRINT:PRINT"THIS PROGRAM IS SET UP FOR A MAXIMUM OF 9 DIFFERENT JOBS
65 PRINT"AND 9 DIFFERENT POSSIBLE ASSIGNMENTS.
90 PRINT:INPUT"PRESS ENTER TO CONTINUE";Z9$
100 MAXX = 9
110 DIM C(MAXX+1,MAXX+1),MA(MAXX+1),JO(MAXX+1),SZ(MAXX+1),AU(MAXX+1),SA(MAXX+1)
120 CLS
130 PRINT"HOW MANY JOBS MUST BE ASSIGNED(<=";MAXX;:INPUT N
140 IF N<1 OR N>MAXX OR N<>INT(N) THEN GOSUB 10000:PRINT:GOTO 130
150 PRINT
160 FOR I=1 TO N
170 PRINT"FOR JOB";I
180 FOR J=1 TO N
190 PRINT"    COST FOR ASSIGNEE";J;:INPUT C(I,J)
200 NEXT J
210 PRINT
220 NEXT I
230 PRINT:GOSUB 10100
235 CLS
240 INPUT"IS LINEPRINTER OUTPUT OF INITIAL COST ASSIGNMENT DESIRED(Y/N)";Z2$
250 IF Z2$<>"Y" AND Z2$<>"N" THEN GOSUB 10000:PRINT:GOTO 240
260 IF Z2$="N" THEN GOTO 300
270 PRINT:INPUT"PRESS ENTER WHEN PRINTER READY";Z9$
273 FOR I=1 TO N
275 LPRINT"FOR JOB";I
278 FOR J=1 TO N
280 LPRINT"    COST FOR ASSIGNEE";J;"=";C(I,J)
285 NEXT J:NEXT I
300 CLS:PRINT:PRINT:PRINT:PRINT"COMPUTING"
305 FOR I=1 TO N:FOR J=1 TO N:C(I,J)=-C(I,J):NEXT:NEXT
320 ZL=0:FOR I=1 TO N:AU(I)=0:NEXT
326 FOR I=1 TO N:MA(I)=0:W=-1E9
332 FOR J=1 TO N
334 IF AU(J)=1 THEN GOTO 342
336 IF C(I,J)<=W THEN GOTO 342
338 W=C(I,J):J1=J
342 NEXT J
344 AU(J1)=1
346 ZL=ZL+W
348 SA(I)=J1
350 NEXT I
370 REM START SEARCH
375 I=1
380 J=1
390 FOR M=1 TO I
400 IF J=MA(M) THEN J=J+1:GOTO 390
410 NEXT M
420 MA(I)=J
430 GOSUB 1000
440 SZ(I)=ZU:IF ZU<=ZL THEN GOTO 600
460 I=I+1:IF I<=N THEN GOTO 380
480 FOR I=1 TO N:SA(I)=MA(I):NEXT I
510 I=N:ZL=ZU:REM NEW BOUND
540 IF SZ(I-1)<>ZL THEN GOTO 660
550 MA(I)=0:I=I-1:IF I=1 THEN GOTO 660
580 GOTO 540
600 J=MA(I)
610 J=J+1
620 IF J<=N THEN GOTO 680
630 MA(I)=0:I=I-1
660 IF I=0 THEN GOTO 740
670 GOTO 600
680 IM=I-1
690 IF IM=0 THEN IM=1
700 FOR L=1 TO IM:IF J=MA(L) THEN GOTO 610
720 NEXT L
730 GOTO 420
740 CLS
750 INPUT"IS LINE PRINTER OUTPUT DESIRED(Y/N)";Z2$
760 IF Z2$<>"Y" AND Z2$<>"N" THEN GOSUB 10000:GOTO 750
770 CLS:PRINT"OPTIMAL ASSIGNMENT"
780 FOR I=1 TO N
790 PRINT TAB(10);"JOB ";SA(I);"GETS ASSIGNEE";I;"    COST = ";-C(SA(I),I)
800 NEXT
802 ZL=-ZL
805 PRINT:PRINT TAB(30);"TOTAL COST = ";ZL
810 IF Z2$="N" THEN GOTO 900
815 LPRINT TAB(20);"OPTIMAL ASSIGNMENT":LPRINT" "
820 FOR I=1 TO N
830 LPRINT "JOB ";SA(I);"GETS ASSIGNEE";I;"    COST = ";-C(SA(I),I)
832 NEXT I
835 LPRINT TAB(20);"TOTAL COST = ";ZL
900 PRINT:INPUT"PRESS ENTER TO START AGAIN";Z9$
905 IF Z9$ = "0" THEN END
910 CLEAR 1000:GOTO 100
1000 FOR CI=1 TO N:AU(CI)=MA(CI):NEXT CI
1030 FOR CI=1 TO N
1040 IF AU(CI)=0 THEN GOTO 1070
1050 NEXT CI
1060 CI=N+1:CM=CI-1:GOTO 1210
1070 CM=CI-1
1080 FOR MN=CI TO N
1090 CW=-1E9
1100 FOR JB=1 TO N
1110 IF CI=1 THEN GOTO 1150
1120 FOR L=1 TO CM
1130 IF JB=AU(L) THEN GOTO 1170
1140 NEXT L
1150 IF C(MN,JB)<=CW THEN GOTO 1170
1160 CW=C(MN,JB)
1170 NEXT JB
1180 AU(MN)=CW
1190 NEXT MN
1200 IF CI=1 THEN GOTO 1240
1210 FOR CJ=1 TO CM:AU(CJ)=C(CJ,MA(CJ)):NEXT CJ
1240 ZU=0:FOR CJ=1 TO N:ZU=ZU+AU(CJ):NEXT CJ
1280 RETURN
10000 PRINT"INPUT ERROR!TRY AGAIN!":FOR JJ=1 TO 300:NEXT:RETURN
10100 INPUT"PRESS ENTER TO CONTINUE";Z9$:RETURN
