#OK to post homework #Yuxuan Yang, Jan 29rd, Assignment 3 #4 AllGames:=proc(a,b) local perm,i,j: perm:=permute(a*b): [seq(seq( [seq([seq([perm[i][m*b+n],perm[j][m*b+n]],m=0..a-1)],n=1..b)] ,i=1..nops(perm)),j=1..nops(perm))]: end: #5 FullStat:=proc(a,b) local n0,n1,n2,nr,nc,ne,g,gam,res1,res2,na: gam:=AllGames(a,b): n0:=0:n1:=0:n2:=0:nr:=0:nc:=0:ne:=0: for g in gam do na:=nops(PureNashEqui(g)): if na=0 then n0:=n0+1: elif na=1 then n1:=n1+1: elif na=2 then n2:=n2+1: fi: res1:=DynRC(g)[2]: res2:=DynCR(g)[2]: if res2[1]>res1[1] then nr:=nr+1: fi: if res1[2]>res2[2] then nc:=nc+1: fi: if res1=res2 then ne:=ne+1: fi: od: [n0,n1,n2,nr,nc,ne]: end: #FullStat(2, 2) #[72, 432, 72, 72, 72, 420] #FullStat(3, 2) #[86400, 345600, 86400, 83952, 86760, 331560] #6 SampleStat:=proc(a,b,K) local n0,n1,n2,nr,nc,ne,g,i,na,res1,res2: n0:=0:n1:=0:n2:=0:nr:=0:nc:=0:ne:=0: for i from 1 to K do g:=RandDisGame(a,b): na:=nops(PureNashEqui(g)): if na=0 then n0:=n0+1: elif na=1 then n1:=n1+1: elif na=2 then n2:=n2+1: fi: res1:=DynRC(g)[2]: res2:=DynCR(g)[2]: if res2[1]>res1[1] then nr:=nr+1: fi: if res1[2]>res2[2] then nc:=nc+1: fi: if res1=res2 then ne:=ne+1: fi: od: evalf([n0,n1,n2,nr,nc,ne]/K): end: #SampleStat(10,10,10000) #[0.3290000000, 0.4050000000, 0.2038000000, 0.2963000000, 0.2930000000, 0.3429000000] #[0.3247000000, 0.4197000000, 0.2030000000, 0.2919000000, 0.2907000000, 0.3455000000] #[0.3363000000, 0.4047000000, 0.2024000000, 0.3027000000, 0.3020000000, 0.3304000000] #[0.3313000000, 0.4095000000, 0.1983000000, 0.2955000000, 0.2959000000, 0.3364000000] #[0.3362000000, 0.3992000000, 0.2037000000, 0.2974000000, 0.2989000000, 0.3285000000] ################### C3.txt ############################ #C3.txt: Maple Code for Lecture 2 of Math640 (Spring 2022) with(combinat): Help3:=proc(): print(`RandDisGame(a,b), BR1d(G,a2), BR2d(G,a1), BR1dv(G), BR2dv(G), DynRC(G), DynCR(G) `):end: #RandDisGame(a,b): A random game where Player Row has a strategies R1, R2, ..., Ra; and Player Col. has b strategies: C1, C2, ..., Cb and all pay-offs are DISCTINCT #and consist of the set {1,2,...,ab}. Try: #RandDisGame(4,6); RandDisGame:=proc(a,b) local pi1,pi2,i1,j1: pi1:=randperm(a*b): pi2:=randperm(a*b): [seq([seq([pi1[b*i1+j1],pi2[b*i1+j1]],j1=1..b)],i1=0..a-1)]: end: #G:=Rand2PlayerGame(10,20,100)[1] #BR1d(G,a2): Inputs a bi-matrix of a 2-player game G and a member a2 of A2 outputs the SUBSET of A1 that consists of the best response BR1d:=proc(G,a2) local a1: max[index]([seq(G[a1][a2][1],a1=1..nops(G))]): end: #BR2d(G,a1): Inputs a bimatrix of a game G and a member a1 of A1 outputs the SUBSET of A2 that consists of the best response BR2d:=proc(G,a1) local a2: max[index]([seq(G[a1][a2][2],a2=1..nops(G[a1]))]): end: #BR1dv(G): Inputs a bimatrix of a game G, outputs The list of size A2 with all the set of best responses # BR1dv:=proc(G) local a2: [seq(BR1d(G,a2),a2=1..nops(G[1]))]:end: #BR2dv(G): Inputs a bimatrix of a game G, outputs The list of size A1 with all the set of best responses BR2dv:=proc(G) local a1: [seq(BR2d(G,a1),a1=1..nops(G))]:end: #DynRC(G): The outcome of the Dynamical version of the game G if row goes first and Column goes next DynRC:=proc(G) local L,i,iBest, jBest: #L is the list of size A1 where L[i] is the best response of Player Column to Strategy i and Row gets G[i][L[i]][1] L:=BR2dv(G): iBest:=max[index]([seq(G[i][L[i]][1],i=1..nops(G))]): jBest:=L[iBest]: [iBest,jBest], G[iBest][jBest]: end: #DynCR(G): The outcome of the Dynamical version of the game G if Col goes first and Row goes next DynCR:=proc(G) local L,j,iBest, jBest: #L is the list of size A2 where L[j] is the best response of Player Row to Strategy j and Col gets G[L[j]][j]][2] L:=BR1dv(G): jBest:=max[index]([seq(G[L[j]][j][2],j=1..nops(L))]): iBest:=L[jBest]: [iBest,jBest], G[iBest][jBest]: end: #Yuxuan Yang, Jan 29rd, Assignment 2 #4 IsNash:=proc(G,a1,a2) : evalb(a1 in BR1v(G)[a2]) and evalb(a2 in BR2v(G)[a1]):end: #5 PureNashEqui:=proc(G) local i,j,S: S:={}: for i from 1 to nops(G) do for j from 1 to nops(G[1]) do if IsNash(G,i,j) then S:=S union {[i,j]}: fi: od: od: S: end: