Info

This question is closed. Reopen it to edit or answer.

where should i insert optimisation task

2 views (last 30 days)
Gauri
Gauri on 7 Feb 2024
Closed: Gauri on 14 Feb 2024
this is my code. my aim is to minimise the total cost, i want to do it using ga or pso option in optimisation task. the optimisation variable is the order quantity. please help.
%cost rates
P = 20
H = 0.1 *P
B = 10*P
E = P;
%demand vector
D = [21 37 1 16 8 5 10 18 20 27 21 35 11 44 2 34 21 28 8 10 41 49 16 35 44 45 5 2 9 44 5 22 48 27 35 16 35 42 1 38 50 38 15 40 6 23 46 15 15 7]
%shelf life
L = 4
% Initialize variables
T = length(D); % Number of days
I = zeros(1, T); % Inventory levels
order_qty = zeros(1, T); % Order quantities
Sexpired = zeros(1, T); % Expired quantities
A = zeros(1, T); % age of inventory
C = zeros(1,T); % backorder amount per day
in = zeros(1,T); % leftover inventory per day
max_inventory = 50;
% Initial conditions
I(1,1) = 10;
A(1,1) = 0;
% starting loop
for t = 1:T-1
% calculate leftover inventory
in(t) = max(0,(I(t)-D(t)));
if in(t) == 0
%order_qty(t) = max(0, max_inventory - I(t)); %order upto S
order_qty(t) = X; % wanting to assign value of optimised variable to order_qty for today
C(t) = abs(I(t)-D(t)); % counting backorders or shortage
A(t+1) = 1; % Reset age to 1 when new inventory arrives
I(t+1) = min(max_inventory, order_qty(t)); % inventory level for tomorow
else
% FIFO implementation
A(t+1) = A(t) + 1; % Increase age for existing items
A(t+1) = min(A(t+1), L); % Cap age to L
% Check for expired items
if A(t+1) >= L % if expired i.e age exceeds shelf life
Sexpired(t) = in(t); % count leftover inventory today as expired and discard
A(t+1) = 1; % Reset age to 1 for the newly ordered items tomorow
I(t+1) = min(max_inventory,order_qty(t)); % tomorow inventory will be only new arrival
end
end
end
% Calculate costs
holding_cost = sum(H .* I);
purchase_cost = sum(P .* order_qty);
expiry_cost = sum(E .* Sexpired);
shortage_cost = sum(B .* C);
% Calculate total cost outside the loop
total_cost = holding_cost + purchase_cost + expiry_cost + shortage_cost;
% Display costs
disp(['Holding Cost: ' num2str(holding_cost)]);
disp(['Purchase Cost: ' num2str(purchase_cost)]);
disp(['Expiry Cost: ' num2str(expiry_cost)]);
disp(['Shortage Cost: ' num2str(shortage_cost)]);
disp(['Total Cost: ' num2str(total_cost)]);
% Display quantity ordered each day
disp('Quantity Ordered Each Day:');
disp(order_qty);
disp(Sexpired);
This is the code of the optimisation task:
% Create optimization variables
X3 = optimvar("X","LowerBound",0,"UpperBound",50);
% Set initial starting point for the solver
initialPoint4.X = repmat(25,size(X3));
% Create problem
problem = optimproblem;
% Define problem objective
problem.Objective = sum(H * I + B * C + E * Sexpired + P * order_qty);
% Set nondefault solver options
options = optimoptions("ga","CreationFcn","gacreationlinearfeasible");
% Display problem information
show(problem);
% Clear variables
clearvars X3 initialPoint4 options
  3 Comments
Gauri
Gauri on 7 Feb 2024
thankyou for your comment
defining X as an array makes more sense, but i dont know how to do it....
i dont have the mathematical model of this problem. I managed to create this code out of a vague problem statement: "We are considering the inventory management of a single type of bread from the retailer point of view. All the available inventory will be displayed on the rack so that the customer has the full freedom to select the bread. In general, retailer’s priority will be to sell bread with minimum shelf life, hence it is assumed to follow the First in First Out (FIFO) policy usually followed in perishable products in full filling the demand. Order-up-to-S policy is considered. An objective function is constructed for the total cost, in which we consider the holding cost, back order cost, expiry cost and procurement cost."
I need to use meta-heuristic algorithms to optimise this. So i plan on making quantity of units placed for order [by retailer to suplier] as the optimisation variable.
I did make a flowchart of the code:
A simpler version:
Any guidance or suggestions would be of great help, as im feeling really lost right now
Sam Chak
Sam Chak on 9 Feb 2024
Hi @Gauri,
Could you please label the step numbers in your flowchart and provide comments (annotations) in the code? This will help both you and others to easily reference and understand the steps and logic involved.

Answers (0)

This question is closed.

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!