program Schedule; {$apptype CONSOLE} {$R+} const {n:word=48; g:word=4; t:word=10; ngroups:word=12;} crlf=#13#10; {Schedule n=120 people in groups of g=6, repeated t=4 times without anyone seeing the same person again} type list=array[0..200] of byte; soln=array[0..50] of list; byteset=set of byte; deja=array[0..200] of byteset; var s,bests,saves :soln; vu :deja; {not used in current version} exchangelist :list; exchangecount :byte; already :array[0..200,0..200] of boolean; fout :text; quiet :boolean; mink :byte; n :byte; g,t,ngroups :word; (* procedure Reecord(r :byte); var i,j,k :byte; begin for i:=0 to pred(ngroups) do for j:=0 to pred(g) do for k:=0 to pred(g) do vu[s[r,g*i+j]]:=vu[s[r,g*i+j]]+[s[r,g*i+k]]; end; function ConflictCount(r :byte):byte; var i,j,k :byte; begin result:=0; for i:=0 to pred(ngroups) do for j:=0 to pred(g) do for k:=succ(j) to pred(g) do if (s[r,g*i+k] in vu[s[r,g*i+j]]) then inc(result); writeln('Round ',r,': total conflicts=',result); end; *) procedure Reecord(r :byte); var i,j,k :byte; begin for i:=0 to pred(ngroups) do for j:=0 to pred(g) do for k:=0 to pred(g) do begin already[s[r,g*i+j],s[r,g*i+k]]:=true; already[s[r,g*i+k],s[r,g*i+j]]:=true; end; end; procedure MakeExchangeList(r :byte); var i,j,k :byte; didone :boolean; begin exchangecount:=0; for i:=0 to pred(ngroups) do begin didone:=false; for j:=0 to pred(g) do begin if (didone) then continue; k:=j; repeat inc(k) until (k=g) or (already[s[r,g*i+j],s[r,g*i+k]]); if (k1) then for i:=0 to pred(exchangecount div 2) do begin swap:=s[r,exchangelist[2*i]]; s[r,exchangelist[2*i]]:=s[r,exchangelist[2*i+1]]; s[r,exchangelist[2*i+1]]:=swap; end; end; procedure TryExchangingToResolveConflicts(r :byte); var i,k :word; begin k:=100; while (k>0) and (i<3000) do begin inc(i); if (not quiet) then write(i:3,': '); MakeExchangeList(r); ShuffleExchangeList(r); PerformExchanges(r); k:=ConflictCount(r); if (k0) and (i<3000) do begin inc(i); if (not quiet) then write(i:3,': '); MakeExchangeList(r); ShuffleExchangeList(r); PerformExchanges(r); k:=ConflictCount(r); if (k0) then rewrite(fout); writeln(fout,crlf,crlf,'----------------------------------------------------------------------'); randomize; InitializeConflictList; for i:=0 to pred(n) do s[0,i]:=i; Reecord(0); Print(0); for i:=1 to t-1 do CreateListForRound(i); write('Done...'); readln; close(fout); end. saves:=s; InitializeConflictList; for i:=0 to pred(t) do begin s[i]:=saves[pred(t)-i]; Reecord(i); mink:=ConflictCount(i); TryExchangingToResolveConflicts(i); Print(i); end; write('Done...'); readln; close(fout); end.