new; cls; trial = 1; output file = badg reset; output on; toplev: qbar = rndu(1,1); tbar = rndu(1,1); qbar = .1; groupon = 1; groupnum = 10; groupmin = 2; groupmax = 6; col0 = "\27[0;40m"; col1 = "\27[0;42m"; col2 = "\27[0;44m"; col3 = "\27[0;43m"; col4 = "\27[0;46m"; col5 = "\27[0;47m"; col6 = "\27[0;45m"; col7 = "\27[0;41m"; numrows = 10; numcols = 10; persons = numrows*numcols; if groupon; member = zeros(numrows,numcols); groups = zeros(groupnum,groupmax); i = 1; do until i > rows(groups); gr = ceil(rndu(1,1).*numrows); gs = groupmin + ceil(rndu(1,1).*(groupmax-groupmin)); gc = ceil(rndu(1,1).*(numcols-gs+1)); if sumc(member[gr,gc:gc+gs-1]'); continue; endif; member[gr,gc:gc+gs-1] = ones(1,gs); j = 1; do until j > gs; groups[i,j] = (gr-1).*numcols+(gc+j-1); j = j + 1; endo; i = i + 1; endo; endif; gone = zeros(persons,1); clapvol = zeros(persons,1); standing = zeros(numrows,numcols); newgone = gone; newclap = clapvol; newstand = standing; threshl = zeros(persons,1); threshc = zeros(persons,1); threshs = zeros(persons,1); delta = rndu(persons,1).*(.1); alphav = rndu(persons,1).*2; alphac = rndu(persons,1).*(.5); alphaq = rndu(persons,1).*2.5; alphan = rndu(persons,1).*2; alpsum = alphav + alphac + alphaq + alphan; alphav = alphav ./ alpsum; alphac = alphac ./ alpsum; alphaq = alphaq ./ alpsum; alphan = alphan ./ alpsum; epsilon = rndu(persons,1).*(.5)-.25; gam = rndu(persons,1); tt = rndu(persons,1); ticket = rndu(persons,1); vizwt = rndu(persons,1); grpwt = rndu(persons,1); i = 1; do until i > persons; rr = ceil(i/numcols); cc = ((i-1)%numcols)+1; vb = zeros(numrows,numcols); left = cc - 1; right = cc + 1; currow = rr; do until currow <= 0; j = left; do until j > right; if (j >= 1) and (j <= numcols); vb[currow,j] = 1; endif; j = j + 1; endo; currow = currow - 1; left = left - 1; right = right + 1; endo; vb[rr,cc] = 0; call varput(vb,"vb"$+ftos(i,"*.*lf",0,0)); vb = vb .* vizwt[i]; if groupon; if member[rr,cc]; gi = 1; do until gi > rows(groups); gj = 1; do until gj > cols(groups); if groups[gi,gj] == i; break; endif; gj = gj + 1; endo; if gj <= cols(groups); break; endif; gi = gi + 1; endo; gj = 1; do until gj > cols(groups); if (groups[gi,gj] /= i) and (groups[gi,gj]); vb[rr,cc+(groups[gi,gj]-i)] = minc(1|(vb[rr,cc+(groups[gi,gj]-i)]+grpwt[i])); endif; gj = gj + 1; endo; endif; endif; call varput(vb,"viz"$+ftos(i,"*.*lf",0,0)); /************************************/ threshl[i] = 0.08; threshc[i] = .1; threshs[i] = .45; i = i + 1; endo; maxclap = persons - sumc(threshc); proc lln(thenum); retp(ln(thenum+1)); endp; proc utility(ii,piter); local viz,vb; viz = varget("viz"$+ftos(ii,"*.*lf",0,0)); vb = varget("vb"$+ftos(ii,"*.*lf",0,0)); retp ( ( alphav[ii].*lln(sumc(sumc(viz.*standing))./sumc(sumc(vb)) ) + alphan[ii].*lln(sumc(clapvol)./maxclap) + alphac[ii].*lln(ticket[ii]) + alphaq[ii].*lln( maxc( 0 | (qbar+epsilon[ii]-gam[ii].*((tbar-tt[ii])^2) ) ) ) ) .*exp((-1).*(piter-10).*delta[ii]) ); endp; proc 0 = showmap; local ii,jj; /* locate 1,ceil((numcols.*3)/2)-5; "S T A G E"; locate 2,1; format /ldn 0,0; ii = 1; do until ii > rows(standing); jj = 1; do until jj > cols(standing); " ";; if standing[ii,jj]; "X";; elseif gone[(ii-1).*numcols+jj]; " ";; else; ".";; endif; " ";; jj = jj + 1; endo; ""; ii = ii + 1; endo; ""; format /ldn 6,2; "OBJ QUALITY : ";; 100.*qbar; "% STANDING : ";; 100.*sumc(sumc(standing))./persons; "APPLAUSE : ";; 100.*sumc(clapvol)./maxclap; */ format /ldn 16,4; 100.*sumc(sumc(standing))./persons;; 100.*sumc(clapvol)./maxclap; retp(); endp; call showmap; iter = 1; do until iter == 0; i = 1; do until i > persons; if gone[i]; i = i + 1; continue; endif; u = utility(i,iter); /* Debugging code */ if rndu(1,1) < -.02; cls; rr = ceil(i/numcols); cc = ((i-1)%numcols)+1; format 2,0; "ROW ";; rr;; " COL ";; cc; format 8,4; viz = varget("viz"$+ftos(i,"*.*lf",0,0)); vb = varget("vb"$+ftos(i,"*.*lf",0,0)); "VISION:"; "vizwt : ";; vizwt[i]; "alphav : ";; alphav[i]; "weighted % seen standing : ";; sumc(sumc(viz.*standing))./sumc(sumc(vb)); "ln ( \" ) : ";; lln(sumc(sumc(viz.*standing))./sumc(sumc(vb))); "NOISE:"; "alphan : ";; alphan[i]; "% clapping volume : ";; sumc(clapvol)./maxclap; "ln ( \" ) : ";; lln(sumc(clapvol)./maxclap); locate 10, 40; "TICKET COST:"; locate 11,40; "alphac : ";; alphac[i]; locate 12,40; "ticket : ";; ticket[i]; locate 13,40; "ln ( \" ) : ";; lln(ticket[i]); locate 14,40; "QUALITY:"; locate 15,40; "alphaq : ";; alphaq[i]; locate 16,40; "qbar : ";; qbar; locate 17, 40; "epsilon : ";; epsilon[i]; locate 18,40; locate 19,40; "gamma : ";; gam[i]; locate 20,40; "tbar : ";; tbar; locate 21,40; "individual's t : ";; tt[i]; locate 22,40; "total (unweighted) term : ";; lln( maxc( 0 | (qbar+epsilon[i]-gam[i].*((tbar-tt[i])^2) ) ) ); locate 17,1; "TOTAL [ ] TERM : ";; temp = ( alphav[i].*lln(sumc(sumc(viz.*standing))./sumc(sumc(vb)) ) + alphan[i].*lln(sumc(clapvol)./maxclap) + alphac[i].*lln(ticket[i]) + alphaq[i].*lln( maxc( 0 | (qbar+epsilon[i]-gam[i].*((tbar-tt[i])^2) ) ) ) ); temp; "DECAY:"; "iteration : ";; iter; "delta : ";; delta[i]; "TOTAL DECAY TERM : ";; temp2 = exp((-1).*(iter-10).*delta[i]); temp2; ""; "TOTAL UTILITY : ";; temp.*temp2; waitc; endif; /* End of debugging code */ newclap[i] = (u >= threshc[i]).*(u-threshc[i]); newstand[ceil(i/numcols),((i-1)%numcols)+1] = (u >= threshs[i]); newgone[i] = (u <= threshl[i]); i = i + 1; endo; clapvol = newclap; standing = newstand; gone = newgone; call showmap; if sumc(gone) >= persons; break; endif; iter = iter + 1; endo; "CONVERGENCE"; ""; trial = trial + 1; if trial <= 1; goto toplev; endif; output off;