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.

Simplex_SCRS(SuppliersNew,TimeToMarket,VenditaMercato)
function [x,exitflag,fval] = Simplex_SCRS(SuppliersNew,TimeToMarket,VenditaMercato)
% matrice di connessioni per il simplesso per il tempo

A=[];
cont_Larghezza=0;
for i=1:1:length(SuppliersNew)
    if length(SuppliersNew(i).Suppliers)>2
        cont_Larghezza=cont_Larghezza+(length(SuppliersNew(i).Suppliers)/2);
    end    
end    

LargezzaMatrici=length(SuppliersNew)+cont_Larghezza;
Aeq=zeros(2,LargezzaMatrici);
tempi=zeros(1,LargezzaMatrici);
f=zeros(1,LargezzaMatrici);
bpar=zeros(length(SuppliersNew),1);
cont=length(SuppliersNew)+1;
for i=1:1:length(SuppliersNew)
    tempi(i)=(SuppliersNew(i).LeadTime*30)/SuppliersNew(i).ProdCap;
    bpar(i,1)=SuppliersNew(i).ProdCap;
    f(i)=SuppliersNew(i).UnitProdCost;
    for j=1:1:length(SuppliersNew(i).Piece)
        if not(isempty(SuppliersNew(i).Piece(j).nome))
           Aeq=[Aeq;zeros(1,LargezzaMatrici)];
        else
            continue;
        end   
        for k=1:1:length(SuppliersNew(i).Piece(j).supp)
            A=[A;zeros(1,LargezzaMatrici)];
            A(end,i)=1;
            A(end,SuppliersNew(i).Piece(j).supp(k))=1;
            Aeq(end,i)=-1;
            if (length(SuppliersNew(SuppliersNew(i).Piece(j).supp(k)).Suppliers)>2)
                % ho fornitori differenti
                % quindi devo attaccare in coda
                Aeq(end,cont)=1;
                Aeq(1,cont)=i;
                Aeq(2,cont)=SuppliersNew(i).Piece(j).supp(k);
                cont=cont+1;
            else
                % posso mettere al posto giusto
                Aeq(end,SuppliersNew(i).Piece(j).supp(k))=1;
            end    
        end
        
    end
end
% sistemo Aeq mettendo anche i vincoli rimanenti
for i=1:1:length(Aeq)
    if (Aeq(2,i)==0)
        continue;
    else
        trovati=int32(((Aeq(2,:))==(Aeq(2,i))));
        trovati(1,Aeq(2,i))=(-1);
        Aeq(end+1,:)=trovati;
        Aeq(2,find(trovati))=0;
    end    
end    
% devo sistemare le dimensioni di A
[r,c]=size(A);
[req,ceq]=size(Aeq);
b=ones(r,1);
b=b*TimeToMarket;
b=[b;bpar];
Beq=zeros(req,1);
for i=1:1:r
    A(i,:)=A(i,:).*tempi;
end    
A=[A;eye(length(SuppliersNew)),zeros(length(SuppliersNew),LargezzaMatrici-length(SuppliersNew))];
%options = optimset('LargeScale', 'off', 'Simplex', 'on','Display','iter');
options = optimset('LargeScale', 'off', 'Simplex', 'on','Display','off');
lb = zeros(LargezzaMatrici,1);
% Ho messo il guadagno di avio come costo che fa pagare al pezzo, di
% conseguenza tolti i costi sotto avro il ricavo totale
f(1) =-f(1);
[x,fval,exitflag,output,lambda]=linprog(f,A,b,Aeq(3:end,:),Beq(3:end,:),lb,[],[],options);

Contact us at files@mathworks.com