Help13:=proc(): print(` RSG(n,K) , SV(f,n), SVp(f,n), SVi(f,n,i), SVpF(f,n) `):end: with(combinat): #RSG(n,K): A random n-person Super-Additive game given by a coalition function with random values from 0 to K. The output is a table such that T[S]=value of coalition S for all subsets of {1,..,n}. RSG:=proc(n,K): FM(RG(n,K),n): end: #SV(f,n): Inputs a coalition function on the subsets of {1,...,n} outputs the list of Shapley values. Using the Mobius transform approach. Try, e.g.: #SC(Ex1(),3); f:=RandSG(5,100); SV(f,5); SV:=proc(f,n) local g,PS,S,i,V,val: g:=BM(f,n): PS:=powerset(n): for i from 1 to n do V[i]:=0: od: for S in PS 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): Inputs a coalition function on the subsets of {1,...,n} outputs the list of Shapley values. Using the Permutation approach. Try, e.g.: #SC(Ex1(),3); f:=RandSG(5,100); SVp(f,5); SVp:=proc(f,n) local S,i,V,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: #SVi(f,n,i): The Shapley value of Player i in the n-person game given by f 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:=proc(f,n) local i: [seq(SVi(f,n,i),i=1..n)]:end: #From 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: #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: