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.

ShapleyDelta_Computation.m
% Shapley computation is really time consuming
% if already computed for a particular chain let 
% use it
if exist(strcat(handles.File,'.mat'))~=2
% prepare the dataset for shapley computation
A=coalition(length(ActiveSuppliers));
[righe,colonne]=size(A);
v=[];
for i=1:1:righe
    NumElem=length(ActiveSuppliers(find(A(i,:))));
    ActiveElementIndex=ActiveSuppliers(find(A(i,:)));
    MaskShapley=zeros(1,length(ActiveSuppliers));
    for j=1:1:NumElem
        if (SuppliersNew(1).Demand>SuppliersNew(ActiveElementIndex(j)).ProdCap)
           MaskShapley=[MaskShapley;SuppliersNew(ActiveElementIndex(j)).MaskShapley*SuppliersNew(ActiveElementIndex(j)).ProdCap];
        else
           MaskShapley=[MaskShapley;SuppliersNew(ActiveElementIndex(j)).MaskShapley*SuppliersNew(1).Demand];
        end    
    end
    if not(isfield(handles, 'funzione'))
        disp ('error: values function is not loaded in mat format')
        return
    end
    MaskShapleyaux=MaskShapley;
    MaskShapley=sum(MaskShapley);
    if (eval(handles.funzione))
        produzione=eval(handles.funzione);
        valore=SuppliersNew(1).UnitProdCost*produzione;
        v=[v,valore]; 
    else  
        v=[v,0];
    end
end    
v=[v,SuppliersNew(1).UnitProdCost*SuppliersNew(1).Demand];
% compute the shapley
ShapleyValues=shap1(length(ActiveSuppliers),v);
save(strcat(handles.File,'.mat'),'ShapleyValues');
else
    load(strcat(handles.File,'.mat'));
end
for i=1:1:length(SuppliersNew)
    ShapleyDelta(i)=SuppliersNew(i).Demand*SuppliersNew(i).UnitProdCost;   
end    
%Shapley Delta
disp('Shapley Delta computation');
ShapleyValuesOrig=ShapleyValues;
ShapleyDeltaOrig=(ShapleyValues-ShapleyDelta);
ShapleyDeltaOrig(ShapleyDeltaOrig<0)=0;
ShapleyDelta=(ShapleyValues-ShapleyDelta)./ShapleyValues;
ShapleyDelta(ShapleyDelta<0)=0;

Contact us at files@mathworks.com