#Maple Code for Lecture 13 of Dr. Z.'s Experimental Mathematics (Game Theory) class Help13:=proc(): print(`RSG(n,K), SV(f,n), SVp(f,n), SVpF(f,n) `): end: with(combinat): #RSG(n,K): A random SUPER-ADDITIVE n-person cooperative game RSG:=proc(n,K) :FM(RG(n,K),n):end: ##SV(f,n): Inputs a Coalition function a function defined on powerset(n) and outputs the list #of length n, call it L, such that L[i] is the Shapley value SV:=proc(f,n) local V,i,g,PN,S,val: #LET V[i]: The current Shapley value of Player i for i from 1 to n do V[i]:=0: od: g:=BM(f,n): #g[S]: means: corresponds to the game where the members of S are symmetric to each other and all the #other players are NULL players, and they get together g[S] PN:=powerset(n): for S in PN do val:=g[S]: for i in S do V[i]:=V[i]+val/nops(S): od: od: [seq(V[i],i=1..n)]: end: #SVp(f,n): Shapley value with the permutation approach SVp:=proc(f,n) local S,V,i,pi: for i from 1 to n do V[i]:=0: od: S:=permute(n): for pi in S do for i from 1 to n do V[pi[i]]:=V[pi[i]]+ f[{op(1..i,pi)}]-f[{op(1..i-1,pi)}]: od: od: [seq(V[i]/n!,i=1..n)]: end: #Added after class #SVi(f,n,i): The Shapley value of Player i in the n-person game given by f #This uses Eq. (13) (and (12), note the typo: n should be n!, i.e. gamma_n(s)=(s-1)!*(n-s)!/n!, where s=|S|) SVi:=proc(f,n,i) local PS,S: PS:=powerset(n) minus {{}}: add((nops(S)-1)!*(n-nops(S))!*(f[S]-f[S minus {i}]),S in PS)/n!: end: #SVpF(f,n): Yet another version of SV(f,n), using the above SVi SVpF:=proc(f,n) local i: [seq(SVi(f,n,i),i=1..n)]:end: #Stuff from Lecture 12: #C12.txt Help12:=proc(): print(`Ex1(), RG(n,K), FM(f,n), BM(f,n) `): end: Ex1:=proc():table([({3})=18,({2})=12,({})=0,({1, 3})=60,({2, 3})=90,({1, 2})=30,({1})=6,({1, 2, 3})=120]):end: with(combinat): #RG(n,K): inputs an and K outputs a random "n-person game" with entries in [0,K] RG:=proc(n,K) local ra,PS,S,f: ra:=rand(0..K): f[{}]:=0: PS:=powerset(n): for S in PS minus {{}} do f[S]:=ra(): od: op(f): end: #FM(f,n): inputs a function from 2^{1,...n} to pos. real numbres #we want g(T)= Sum of g(S) over all subsets S of T FM:=proc(f,n) local S,PS,PN,g,S1: PN:=powerset(n): for S in PN do PS:=powerset(S): g[S]:=add(f[S1], S1 in PS): od: op(g): end: #BM(f,n): inputs a function from 2^{1,...n} to pos. real numbres #we want g(T)= Sum of (-1)^(|T|-|S|)*g(S) over all subsets S of T BM:=proc(f,n) local S,PS,PN,g,S1: PN:=powerset(n): for S in PN do PS:=powerset(S): g[S]:=add( (-1)^(nops(S)-nops(S1))*f[S1], S1 in PS): od: op(g): end: