Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.
function [f] = Inventory_ma2rafiq(C_Cost)
Demand = [1,3,2,4];
%C_Cost = [
% 20 16 31/2 15 27/2
% 16 15 14 12 21/2
% 12 10 7 13/2 6
% 0 4 5 6 7];
Setup_cost = 3;
variable_cost = 1;
holding_cost = 0.5;
Prod_Cap = 5;
WareHouse_Cap = 4;
Period_Begining = 1;
Period_End = 4;
Inv_Min = 0;
Inv_Max = 4;
%Prod_Q_Min = 0;
%Prod_Q_Max = 5;
n=size(C_Cost,1);
Min_Cost=zeros(1,n); %added matrix to keep argmin(Min_Cost)
Opt_Prod_Quantity=zeros(1,n); %added matrix to keep argmin(Min_Cost)
for Period = Period_End:-1:Period_Begining; % Period Loop for 4 - 1
for Inv_Level = Inv_Min:Inv_Max; % Inventory Level Loop from 4 - 0
for Prod_Quantity = max(0,Demand(Period)-Inv_Level):min(Prod_Cap,WareHouse_Cap-Inv_Level+Demand(Period)); % Loop only with Current Month Demand met constraint and Ending Inventory cannot exceed Capacity Constraint
if Period == 4 % Cost for Period 4
if Prod_Quantity == 0
cost = 0; % No Production = 0 Cost
else
cost = Setup_cost + Prod_Quantity*variable_cost + holding_cost*(Inv_Level + Prod_Quantity - Demand(Period)); % Holding Cost + ProdCost
end
end
if Period ~= 4 % Cost for Periods other than 4
if Prod_Quantity == 0
cost = C_Cost(Inv_Level+1,Inv_Level+Prod_Quantity-Demand(Period)); % Calculate only cost from Cost Matrix
else
cost = Setup_cost + Prod_Quantity*variable_cost + holding_cost*(Inv_Level + Prod_Quantity - Demand(Period)) + C_Cost(Inv_Level+1,Inv_Level+Prod_Quantity-Demand(Period)); % Complete Cost Formula
end
end
%Inv_Level + Prod_Quantity - demand(Period) <=4; % Current Month Demand Constraint
%Inv_Level + Prod_Quantity - demand(Period) >=0; % Ending Inventory cannot exceed Capacity Constraint
if C_Cost(Period,Inv_Level+1) == cost;% Check to see if this is the minimum cost
X = (cost+0.5*(Inv_Level + Prod_Quantity - Demand(Period))); % Store the Minimum cost
Min_Cost(1,Inv_Level+1) = (X); % If we are at the minimum cost then store min_cost
Opt_Prod_Quantity(1,Inv_Level+1) = (Prod_Quantity); % If we are at the minimum cost then store min_cost associated Prod_Quantity
end
end
end
end
Min_Cost % Output Min_Cost matrix
Opt_Prod_Quantity % Output Production Quantity matrix
end
function [f] = Inventory_ma2rafiq(C_Cost)
Demand = [1,3,2,4];
%C_Cost = [
% 20 16 31/2 15 27/2
% 16 15 14 12 21/2
% 12 10 7 13/2 6
% 7 6 5 4 0];
Setup_cost = 3;
variable_cost = 1;
holding_cost = 0.5;
Prod_Cap = 5;
WareHouse_Cap = 4;
Period_Begining = 1;
Period_End = 4;
Inv_Min = 0;
Inv_Max = 4;
%Prod_Q_Min = 0;
%Prod_Q_Max = 5;
n=size(C_Cost,1);
Min_Cost=zeros(1,n); %added matrix to keep argmin(Min_Cost)
Opt_Prod_Quantity=zeros(1,n); %added matrix to keep argmin(Min_Cost)
for Period = Period_End:-1:Period_Begining; % Period Loop for 4 - 1
for Inv_Level = Inv_Min:Inv_Max; % Inventory Level Loop from 0 - 4
for Prod_Quantity = max(0,Demand(Period)-Inv_Level):min(Prod_Cap,WareHouse_Cap-Inv_Level+Demand(Period)); % Loop only with Current Month Demand met constraint and Ending Inventory cannot exceed Capacity Constraint
if Period == 4 % Cost for Period 4
if Prod_Quantity == 0
cost = 0; % No Production = 0 Cost
else
cost = Setup_cost + Prod_Quantity*variable_cost + holding_cost*(Inv_Level + Prod_Quantity - Demand(Period)); % Holding Cost + ProdCost
end
end
if Period ~= 4 % Cost for Periods other than 4
if Prod_Quantity == 0
cost = Setup_cost + Prod_Quantity*variable_cost; % Calculate only cost from Cost Matrix
else
cost = Setup_cost + Prod_Quantity*variable_cost + holding_cost*(Inv_Level + Prod_Quantity - Demand(Period)) + Setup_cost + Prod_Quantity*variable_cost; % Complete Cost Formula
end
end
%Inv_Level + Prod_Quantity - demand(Period) <=4; % Current Month Demand Constraint
%Inv_Level + Prod_Quantity - demand(Period) >=0; % Ending Inventory cannot exceed Capacity Constraint
if C_Cost(Period,Inv_Level+1) == cost;% Check to see if this is the minimum cost
X = (cost+0.5*(Inv_Level + Prod_Quantity - Demand(Period))); % Store the Minimum cost
Min_Cost(1,Inv_Level+1) = (X); % If we are at the minimum cost then store min_cost
Opt_Prod_Quantity(1,Inv_Level+1) = (Prod_Quantity); % If we are at the minimum cost then store min_cost associated Prod_Quantity
end
end
end
end
Min_Cost % Output Min_Cost matrix
Opt_Prod_Quantity % Output Production Quantity matrix
end
function [f] = Inventory_ma2rafiq(C_Cost)
Demand = [1,3,2,4];
%C_Cost = [
% 20 16 31/2 15 27/2
% 16 15 14 12 21/2
% 12 10 7 13/2 6
% 0 4 5 6 7];
Setup_cost = 3;
variable_cost = 1;
holding_cost = 0.5;
Prod_Cap = 5;
WareHouse_Cap = 4;
Period_Begining = 1;
Period_End = 4;
Inv_Min = 0;
Inv_Max = 4;
%Prod_Q_Min = 0;
%Prod_Q_Max = 5;
n=size(C_Cost,1);
%Min_Cost=zeros(1,n); %added matrix to keep argmin(Min_Cost)
Min_Cost = 0;
Opt_Prod_Quantity=zeros(1,n); %added matrix to keep argmin(Min_Cost)
for Period = Period_End:-1:Period_Begining; % Period Loop for 4 - 1
for Inv_Level = Inv_Min:Inv_Max; % Inventory Level Loop from 4 - 0
for Prod_Quantity = max(0,Demand(Period)-Inv_Level):min(Prod_Cap,WareHouse_Cap-Inv_Level+Demand(Period)); % Loop only with Current Month Demand met constraint and Ending Inventory cannot exceed Capacity Constraint
if Period == 4 % Cost for Period 4
if Prod_Quantity == 0
cost = 0; % No Production = 0 Cost
else
cost = Setup_cost + Prod_Quantity*variable_cost + holding_cost*(Inv_Level + Prod_Quantity - Demand(Period)); % Holding Cost + ProdCost
end
end
if Period ~= 4 % Cost for Periods other than 4
if Prod_Quantity == 0
cost = Setup_cost + Prod_Quantity*variable_cost; % Calculate only cost from Cost Matrix
else
cost = Setup_cost + Prod_Quantity*variable_cost + holding_cost*(Inv_Level + Prod_Quantity - Demand(Period)) + Setup_cost + Prod_Quantity*variable_cost; % Complete Cost Formula
end
end
%Inv_Level + Prod_Quantity - demand(Period) <=4; % Current Month Demand Constraint
%Inv_Level + Prod_Quantity - demand(Period) >=0; % Ending Inventory cannot exceed Capacity Constraint
if C_Cost(Period,Inv_Level+1) == cost;% Check to see if this is the minimum cost
X = (cost+0.5*(Inv_Level + Prod_Quantity - Demand(Period))); % Store the Minimum cost
Min_Cost = C_Cost(1,1); % If we are at the minimum cost then store min_cost
Opt_Prod_Quantity(1,Period) = (Prod_Quantity); % If we are at the minimum cost then store min_cost associated Prod_Quantity
end
end
end
end
Min_Cost % Output Min_Cost matrix
Opt_Prod_Quantity % Output Production Quantity matrix
end
function [f] = Inventory_ma2rafiq(C_Cost)
Demand = [1,3,2,4];
Setup_cost = 3;
variable_cost = 1;
holding_cost = 0.5;
Prod_Cap = 5;
WareHouse_Cap = 4;
Period_Begining = 1;
Period_End = 4;
Inv_Min = 0;
Inv_Max = 4;
n=size(C_Cost,1);
Min_Cost = 0;
Opt_Prod_Quantity=zeros(1,n); %added matrix to keep argmin(Min_Cost)
for Period = Period_End:-1:Period_Begining; % Period Loop for 4 - 1
for Inv_Level = Inv_Min:Inv_Max; % Inventory Level Loop from 4 - 0
for Prod_Quantity = max(0,Demand(Period)-Inv_Level):min(Prod_Cap,WareHouse_Cap-Inv_Level+Demand(Period)); % Loop only with Current Month Demand met constraint and Ending Inventory cannot exceed Capacity Constraint
if Period == 4 % Cost for Period 4
if Prod_Quantity == 0
cost = 0; % No Production = 0 Cost
else
cost = Setup_cost + Prod_Quantity*variable_cost + holding_cost*(Inv_Level + Prod_Quantity - Demand(Period)); % Holding Cost + ProdCost
end
end
if Period ~= 4 % Cost for Periods other than 4
if Prod_Quantity == 0
cost = Setup_cost + Prod_Quantity*variable_cost; % Calculate only cost from Cost Matrix
else
cost = Setup_cost + Prod_Quantity*variable_cost + holding_cost*(Inv_Level + Prod_Quantity - Demand(Period)) + Setup_cost + Prod_Quantity*variable_cost; % Complete Cost Formula
end
end
%Inv_Level + Prod_Quantity - demand(Period) <=4; % Current Month Demand Constraint
%Inv_Level + Prod_Quantity - demand(Period) >=0; % Ending Inventory cannot exceed Capacity Constraint
if min(C_Cost(Period,Inv_Level+1)) == cost;% Check to see if this is the minimum cost
X = cost; % Store the Minimum cost
Min_Cost = C_Cost(1,1); % If we are at the minimum cost then store min_cost
Opt_Prod_Quantity(1,Period) = (Prod_Quantity); % If we are at the minimum cost then store min_cost associated Prod_Quantity
end
end
end
end
Min_Cost % Output Min_Cost matrix
Opt_Prod_Quantity % Output Production Quantity matrix
end
function [f] = Inventory_ma2rafiq(C_Cost)
Demand = [1,3,2,4];
Setup_cost = 3;
variable_cost = 1;
holding_cost = 0.5;
Prod_Cap = 5;
WareHouse_Cap = 4;
Period_Begining = 1;
Period_End = 4;
Inv_Min = 0;
Inv_Max = 4;
n=size(C_Cost,1);
Min_Cost = 0;
Opt_Prod_Quantity=zeros(1,n); %added matrix to keep argmin(Min_Cost)
for Period = Period_End:-1:Period_Begining; % Period Loop for 4 - 1
for Inv_Level = Inv_Min:Inv_Max; % Inventory Level Loop from 4 - 0
for Prod_Quantity = max(0,Demand(Period)-Inv_Level):min(Prod_Cap,WareHouse_Cap-Inv_Level+Demand(Period)); % Loop only with Current Month Demand met constraint and Ending Inventory cannot exceed Capacity Constraint
if Period == 4 % Cost for Period 4
if Prod_Quantity == 0
cost = 0; % No Production = 0 Cost
else
cost = Setup_cost + Prod_Quantity*variable_cost + holding_cost*(Inv_Level + Prod_Quantity - Demand(Period)); % Holding Cost + ProdCost
end
end
if Period ~= 4 % Cost for Periods other than 4
if Prod_Quantity == 0
cost = Setup_cost + Prod_Quantity*variable_cost; % Calculate only cost from Cost Matrix
else
cost = Setup_cost + Prod_Quantity*variable_cost + holding_cost*(Inv_Level + Prod_Quantity - Demand(Period)) + Setup_cost + Prod_Quantity*variable_cost; % Complete Cost Formula
end
end
%Inv_Level + Prod_Quantity - demand(Period) <=4; % Current Month Demand Constraint
%Inv_Level + Prod_Quantity - demand(Period) >=0; % Ending Inventory cannot exceed Capacity Constraint
for i = 1:5;
min_value = min(C_Cost(Period,i));
end
if min_value == cost;% Check to see if this is the minimum cost
%X = cost; % Store the Minimum cost
Min_Cost = C_Cost(1,1); % If we are at the minimum cost then store min_cost
Opt_Prod_Quantity(1,Period) = (Prod_Quantity); % If we are at the minimum cost then store min_cost associated Prod_Quantity
end
end
end
end
Min_Cost % Output Min_Cost matrix
Opt_Prod_Quantity % Output Production Quantity matrix
end
function [f] = Inventory_ma2rafiq(C_Cost)
Demand = [1,3,2,4];
Setup_cost = 3;
variable_cost = 1;
holding_cost = 0.5;
Prod_Cap = 5;
WareHouse_Cap = 4;
Period_Begining = 1;
Period_End = 4;
Inv_Min = 0;
Inv_Max = 4;
n=size(C_Cost,1);
Min_Cost = 0;
Opt_Prod_Quantity=zeros(1,n); %added matrix to keep argmin(Min_Cost)
for Period = Period_End:-1:Period_Begining; % Period Loop for 4 - 1
for Inv_Level = Inv_Min:Inv_Max; % Inventory Level Loop from 4 - 0
for Prod_Quantity = max(0,Demand(Period)-Inv_Level):min(Prod_Cap,WareHouse_Cap-Inv_Level+Demand(Period)); % Loop only with Current Month Demand met constraint and Ending Inventory cannot exceed Capacity Constraint
if Period == 4 % Cost for Period 4
if Prod_Quantity == 0
cost = 0; % No Production = 0 Cost
else
cost = Setup_cost + Prod_Quantity*variable_cost + holding_cost*(Inv_Level + Prod_Quantity - Demand(Period)); % Holding Cost + ProdCost
end
end
if Period ~= 4 % Cost for Periods other than 4
if Prod_Quantity == 0
cost = Setup_cost + Prod_Quantity*variable_cost; % Calculate only cost from Cost Matrix
else
cost = Setup_cost + Prod_Quantity*variable_cost + holding_cost*(Inv_Level + Prod_Quantity - Demand(Period)) + Setup_cost + Prod_Quantity*variable_cost; % Complete Cost Formula
end
end
%Inv_Level + Prod_Quantity - demand(Period) <=4; % Current Month Demand Constraint
%Inv_Level + Prod_Quantity - demand(Period) >=0; % Ending Inventory cannot exceed Capacity Constraint
%for i = 1:5;
%min_value = min(C_Cost(Period,i));
%end
if min(C_Cost,[],2)==cost;% Check to see if this is the minimum cost
%X = cost; % Store the Minimum cost
Min_Cost = C_Cost(1,1); % If we are at the minimum cost then store min_cost
Opt_Prod_Quantity(1,Period) = (Prod_Quantity); % If we are at the minimum cost then store min_cost associated Prod_Quantity
break
end
end
end
end
Min_Cost % Output Min_Cost matrix
Opt_Prod_Quantity % Output Production Quantity matrix
end
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Best Graph | 2 | 55 | |
countX | 22 | 109 | |
splitOdd10 challenge | 5 | 105 | |
Calculating Standard Deviation inside Excel. | 5 | 94 |
Join the community of 500,000 technology professionals and ask your questions.