function c=machines(k,lambda,c_f,mu,c_r) %Simulate availability of m machines %lambda breakdown rate of all machines %mu repair rate of each machine %k repair capacity (number of repairmen %c_f cost per hour of an unavailable machine %c_r cost per hour of a repairman T=800; %Total simulation time m=5; %Number of machines t=0; %Simulation clock tb=exprnd(1/(m*lambda)); %The time of next breakdown tr=inf; %The time of next repair completion n_r=[]; %Machines under repair n_q=0; %Number queueing for repair c=0; %Total cost %The main simulation loop while min(tb,tr)0 n_r=sort([n_r tr+exprnd(1/mu)]); n_q = n_q-1; end %Update simulation clock t = tr; %Next service completion if not(isempty(n_r)) tr = n_r(1); else tr=inf; end %Next breakdown (breakdown intensity increasis as repair is %completed) tb=t+exprnd(1/(lambda*(m-length(n_r)-n_q))); end end %Update statistics for remaining time period c = c+(T-t)*(c_f*(length(n_r)+n_q)+c_r*k); %Average hourly cost c=c/T;