Code covered by the BSD License  

Highlights from
Supply Chain Risk Simulator (SCRS)

from Supply Chain Risk Simulator (SCRS) by Marco Anisetti
Supply Chain simulator for risk assessment and incentive schemes.

S=shap1(n,v);
function S=shap1(n,v); 
% This program determines the shapley value .Shapley value is one of
% important solution concept for Transferable utility cooperative game cooperative game.
  m=2^n-1;
  % The 2^2-1 coalition contrains of the transferable utility game.
A=coalition(n);
ss=ones(1,n);
 A=[A' ss']';
            for k=1:n
         k1=zeros(1,m);
     k2=k1;
     A2=0*A;
        for i=1:m
            if A(i,k)>0
                k1(i)=v(i);
                A2(i,:)=A(i,:);
                 else
            end
        end
         A3=A2;
         A3(:,k)=0;
         for i=1:m
             for j=1:m
                 if A3(i,1:n)==A(j,1:n);
                     k2(i)=v(j);
                 else
               end
             end
         end
         k3=k1-k2;
         k4=sum(A2.');
         r=zeros(1,m);
         mm=factorial(n-1);
         for i=1:m
                  if k4(i)>0
             r(i)=mm./nchoosek(n-1,k4(i)-1);
             else
         end
         end
         S(k)=sum(k3.*r)/sum(r);
       end
    
         
                    

Contact us at files@mathworks.com