BEGIN { SUBSEP=":" srand() mpess1 = .1 mpunish1 = 2 hurwicz1 = .8 mpess2 = .1 mpunish2 = 2 hurwicz2 = .8 while (1) { mpess1 = round10(rand()/5.0) mpunish1 = round(10*rand()) hurwicz1 = min(round10(.2+.8*rand()),1.0) mpess2 = round10(rand()/5.0) mpunish2 = round(10*rand()) hurwicz2 = min(round10(.2+.8*rand()),1.0) true = true makeutilitycliff = true cliffmult = 2 cliffmult = max(round(4*rand() - 1),0) init() printmatrix() exit while (!finished) negotiate() finalreport() } } func init( i,j,k,d) { imax = 2+int(10*rand()) jmax = 2+int(10*rand()) iter = 0 maxiter = 100 finished = 0; brokedown = 0 # generate the payoff matrix delete payoff delete offered delete dominated delete track for (i=1; i<=imax; i++) for (j=1; j<=jmax; j++) { payoff[1,i,j] = payoff[2,i,j] = 0 } bestpayoff1 = bestpayoff2 = 0 for (i=1; i<=imax; i++) for (j=1; j<=jmax; j++) { if (makeutilitycliff && i+j > (imax+jmax)/2) for (d=1; d<=cliffmult; d++) for (k=1; k<=i+j; k++) payoff[1,i,j] += 10*rand() else for (k=1; k<=i+j; k++) payoff[1,i,j] += 10*rand() if (makeutilitycliff && i+j < (imax+jmax)/2) for (d=1; d<=cliffmult; d++) for (k=1; k<=imax+jmax-i-j; k++) payoff[2,i,j] += 10*rand() else for (k=1; k<=imax+jmax-i-j; k++) payoff[2,i,j] += 10*rand() if (payoff[1,i,j] > bestpayoff1) { bestpayoff1 = payoff[1,i,j] best1 = i SUBSEP j } if (payoff[2,i,j] > bestpayoff2) { bestpayoff2 = payoff[2,i,j] best2 = i SUBSEP j } } for (i=1; i<=imax; i++) for (j=1; j<=jmax; j++) { if (payoff[1,i,j] > 200) payoff[1,i,j] = 200 if (payoff[2,i,j] > 200) payoff[2,i,j] = 200 } # init agent characteristics pess1 = pess2 = 0 punish1 = punish2 = 0 # lowoff1 = payoff[1,imax,jmax] might not be the best lowoff1 = bestpayoff1 anow1 = payoff[1,best2] sec1 = payoff[1,1,jmax] # lowoff2 = payoff[2,1,1] lowoff2 = bestpayoff2 anow2 = payoff[2,best1] sec2 = payoff[2,1,jmax] } func printmatrix( i,j) { # print out the payoff matrix print "\t\tplayer 1's payoffs" printf " (2) " for (j=1; j<=jmax; j++) { printf "%5s ",j } print "" for (i=1; i<=imax; i++) { printf "(1)" printf "%2s: ",i for (j=1; j<=jmax; j++) { if (offered[1,i,j]) printf " $" # else if (dominated[1,i,j]) printf " c" else if (offered[2,i,j]) printf " ." else printf " " printf "%3.0f ",payoff[1,i,j] } print "" } printf "lowoffer=%3.0f ",lowoff1 printf "\tagreenow=%3.0f ",anow1 printf "\tsecurity=%3.0f ",sec1 printf "\tegap=%3.0f ",min(e1-bd1, e1-anow1) printf "\togap=%3.0f ",min(lowoff1-anow1, lowoff1-sec1) print "" printf "breakdown=%3.0f ",bd1 printf "\tpessimism=%2.2f ",pess1 printf "\tpunish=%3.0f ",punish1 printf "\texpected=%3.0f ",e1 print "" print "\t\tplayer 2's payoffs" printf " (2) " for (j=1; j<=jmax; j++) { printf "%5s ",j } print "" for (i=1; i<=imax; i++) { printf "(1)" printf "%2s: ",i for (j=1; j<=jmax; j++) { if (offered[2,i,j]) printf " $" # else if (dominated[2,i,j]) printf " c" else if (offered[1,i,j]) printf " ." else printf " " printf "%3.0f ",payoff[2,i,j] } print "" } printf "lowoffer=%3.0f ",lowoff2 printf "\tagreenow=%3.0f ",anow2 printf "\tsecurity=%3.0f ",sec2 printf "\tegap=%3.0f ",min(e2-bd2,e2-anow2) printf "\togap=%3.0f ",min(lowoff2-anow2, lowoff2-sec2) print "" printf "breakdown=%3.0f ",bd2 printf "\tpessimism=%2.2f ",pess2 printf "\tpunish=%3.0f ",punish2 printf "\texpected=%3.0f ",e2 print "" } func negotiate() { print "t="++iter # better to pipe to less # getline track[1,iter] = best2 track[2,iter] = best1 bd1 = sec1+punish1 e1 = pess1*bd1 + (1-pess1)*(hurwicz1*lowoff1+(1.0-hurwicz1)*max(anow1,sec1)) bd2 = sec2+punish2 e2 = pess2*bd2 + (1-pess2)*(hurwicz2*lowoff2+(1.0-hurwicz2)*max(anow2,sec2)) printmatrix() # accept offers if (e1<=anow1) { finished = 1 printf "1 accepts offer of " printf "%3.0f",anow1 printf " at "best1 printf "; 2 gets " printf "%3.0f",payoff[2,best1] print "" punish1 = punish2 = 0 final = best1 return } if (e2<=anow2) { finished = 1 printf "2 accepts offer of " printf "%3.0f",anow2 printf " at "best2 printf "; 1 gets " printf "%3.0f",payoff[1,best2] print "" punish1 = punish2 = 0 final = best2 return } # make offers progress1 = progress2 = 0 for (i=1; i<=imax; i++) for (j=1; j<=jmax; j++) { if (!offered[i,j] && e1<=payoff[1,i,j] && payoff[1,i,j]>=bd1) { progress1 = 1; makeoffer(1,i,j) } if (!offered[i,j] && e2<=payoff[2,i,j] && payoff[2,i,j]>=bd2) { progress2 = 1; makeoffer(2,i,j) } } if (progress1 || progress2) { pess1 = pess2 = 0 timesinceprogress = 0 print "" } else { timesinceprogress++ pess1 += mpess1 pess2 += mpess2 print "no new offers" } if (progress1) { timesincelastprogress1 = 0 punish2 = 0 } else { timesincelastprogress1++ punish2 += mpunish2 } if (progress2) { timesincelastprogress2 = 0 punish1 = 0 } else { timesincelastprogress2++ punish1 += mpunish1 } # print "...time since 1's progress="timesincelastprogress1 # print "...time since 2's progress="timesincelastprogress2 if (progress1 || progress2) return # breakdown if (iter>maxiter || e1<=bd1) { finished = 1 brokedown = 1 print "1 breaks down for "bd1 final = 1 SUBSEP jmax return } if (e2<=bd2) { finished = 1 brokedown = 1 print "2 breaks down for "bd2 final = 1 SUBSEP jmax return } } func makeoffer(who,i,j, i1,j1) { if (who == 1) { lowoff1 = min(lowoff1, payoff[1,i,j]) if (payoff[2,i,j] > anow2) { anow2 = payoff[2,i,j] best2 = i SUBSEP j } } if (who == 2) { lowoff2 = min(lowoff2, payoff[2,i,j]) if (payoff[1,i,j] > anow1) { anow1 = payoff[1,i,j] best1 = i SUBSEP j } } printf "..."who" offers "i":"j offered[who,i,j] = 1 offered[i,j] = 1 # mark dominated proposals if (who == 2) { for (i1=i; i1>=1; i1--) for (j1=j; j1>=1; j1--) dominated[2,i1,j1] = 1 } else if (who == 1) { for (i1=i; i1<=imax; i1++) for (j1=j; j1<=jmax; j1++) dominated[1,i1,j1] = 1 } } func max(a,b) { if (a > b) return a else return b } func min(a,b) { if (a < b) return a else return b } func round10(x) { return int(.5+10.0*x)/10.0 } func round(x) { return int(.5+x) } func finalreport( i,j,rate,gets1,gets2,r) { delete pmatrix gets1 = payoff[1,final]+punish1 gets2 = payoff[2,final]+punish2 rate = 10.0 if (max(bestpayoff1,bestpayoff2) > 100.0) rate = 10.0 else rate = 5.0 for (i=1; i<=iter; i++) { x = round(payoff[1,track[1,i]]/rate) y = round(payoff[2,track[1,i]]/rate) if (!pmatrix[x,y]) pmatrix[x,y] = i x = round(payoff[1,track[2,i]]/rate) y = round(payoff[2,track[2,i]]/rate) if (!pmatrix[x,y]) pmatrix[x,y] = i } for (i=1; i<=imax; i++) for (j=1; j<=jmax; j++) { x = round(payoff[1,i,j]/rate) y = round(payoff[2,i,j]/rate) if (!pmatrix[x,y]) pmatrix[x,y] = "#" if (i==1 && j==jmax) pmatrix[x,y] = "0" } if (brokedown) { x = round(gets1/rate) y = round(gets2/rate) pmatrix[x,y] = pmatrix[x,y]"*" } printf " " for (j=0; j<=20; j++) printf "%3s",j*rate print "" for (i=0; i<=20; i++) { printf "%3s",i*rate for (j=0; j<=20; j++) { if (pmatrix[i,j]) printf "%2s ",pmatrix[i,j] else printf " . " } print "" } if (brokedown) r = "breakdown" else r = "agreed" print "cliff="cliffmult " mpun="mpunish1 " mpess=" mpess1 " hurw=" hurwicz1 " gets=" round(gets1) " " round(payoff[1,final]) " best="round(bestpayoff1) " sec="round(sec1) " iter="iter " "r print "cliff="cliffmult " mpun="mpunish2 " mpess=" mpess2 " hurw=" hurwicz2 " gets=" round(gets2) " " round(payoff[2,final]) " best="round(bestpayoff2) " sec="round(sec2) " iter="iter " "r print "cliff="cliffmult " mpun="mpunish1 " mpess=" mpess1 " hurw=" hurwicz1 " gets=" round(gets1) " " round(payoff[1,final]) " best="round(bestpayoff1) " sec="round(sec1) " iter="iter " "r >> "log" print "cliff="cliffmult " mpun="mpunish2 " mpess=" mpess2 " hurw=" hurwicz2 " gets=" round(gets2) " " round(payoff[2,final]) " best="round(bestpayoff2) " sec="round(sec2) " iter="iter " "r >> "log" close("log") }