#C12.txt: The Shapley valueof an n-person cooperative game Help12:=proc(): print(` RandG(n,K), Ex1() , Coe(f,x,n,S), RandSG(n,K), TtoGF(T,x,n) , GFtoT(f,x,n) `):end: with(combinat): Ex1:=proc():table([({3})=18,({2})=12,({})=0,({1, 3})=60,({2, 3})=90,({1, 2})=30,({1})=6,({1, 2, 3})=120]):end: #RandG(n,K): A random n-person 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}. RandG:=proc(n,K) local ra,T,PS,S: ra:=rand(0..K): PS:=powerset(n): T[{}]:=0: for S in PS minus {{}} do T[S]:=ra(): od: op(T): end: #Coe(f,x,n,S): The coefficient of mul(x[i], in in S) in f Coe:=proc(f,x,n,S) local i,f1: f1:=f: for i in S do f1:=diff(f1,x[i]): od: f1:=subs({seq(x[i]=0,i=1..n)},f1): end: #RandSG(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}. RandSG:=proc(n,K) local U,f,x,i,ra,PS,S,T: U:={seq(i,i=1..n)}: ra:=rand(0..K): PS:=powerset(n): T[{}]:=0: f:=0: for S in PS minus {{}} do f:=f+ra()*mul(x[i], i in S)*mul(1+x[i], i in U minus S): od: f:=expand(f): for S in PS minus {{}} do T[S]:=Coe(f,x,n,S): od: op(T): end: #TtoGF(T,x,n): The generating function of the n-person game given by the table T defined on powerst(n) minus {{}} TtoGF:=proc(T,x,n) local SP,S,i: SP:=powerset(n): add(T[S]*mul(x[i],i in S),S in SP) : end: #GFtoT(f,x,n): inputs f in x[1],...,x[n] outputs the Coalition table GFtoT:=proc(f,x,n) local S,PS,T: PS:=powerset(n): for S in PS do T[S]:=Coe(f,x,n,S): od: op(T): end: