Facilities Location Problem With MATLAB
Chris Harding
Fivecast Member | Retired Chemical Engineer | Affiliate Member at MIT | Friend of Johns Hopkins University Energy Policy and Climate
Excellent! I solved the barebones outline for facility choice by maximizing profits.
Let us say you have three distribution businesses in three different cities: Denver, Seattle, and St. Louis. You ship the biochar from each distribution center to three other cities: LA, Topeka, and NYC. The company's demand is increasing, but the company cannot afford to build a producer and a distribution center. A new producer should be built at a currently available distribution center. Which one?
A similar question is posed by [1]. and can be answered by a Facilities Location Problem (FLP) algorithm. Here is the code, and Seattle is the winner, which matches [1].
MATLAB Code:
m = 3; % Number of locations, producers, and distribution centers.
n = 3; % Number of customers
Producer = {"Denver", "Seattle", "St Louis"}; % Each Producer Ships to: LA, Topeka, and NYC.
s = [400, 700, 600]; % Capacity, ensure this matches the number of rows of x
d = [300, 100, 500]; % Demand
c = [10, 5, 17; 11, 18, 28; 18, 3, 9]; % Variable cost like shipping.
x = optimvar('x', [m, n], 'LowerBound', 0);
maximum =[];
for i = 1:m
prob = optimproblem('ObjectiveSense', 'maximize');
prob.Objective = sum((100 - c(i, :)) .* x(i, :));
% Define constraints correctly
prob.Constraints.colsum = sum(x, 1) <= d(:').';
prob.Constraints.rowsum = sum(x, 2) <= s(:); % s(:') ensures s is treated as a column vector
% Convert problem and solve
problemStruct = prob2struct(prob);
[xSol, fval, exitflag, output] = intlinprog(problemStruct.f, ...
problemStruct.intcon, problemStruct.Aineq, problemStruct.bineq, ...
problemStruct.Aeq, problemStruct.beq, problemStruct.lb, problemStruct.ub);
maximum = [maximum, abs(fval)];
% Display results
fprintf('The Producer is: %s\n', Producer{i});
fprintf('The monetary value is: %.2f\n', abs(fval));
end
[maxValue, maxIndex] = max(maximum);
if maxIndex == 1
fprintf('The Producer is: %s\n', Producer{maxIndex});
fprintf('The monetary value is: %.2f\n', maxValue);
elseif maxIndex == 2
fprintf('The Maximum Producer is: %s\n', Producer{maxIndex});
fprintf('The Maximum monetary value is: %.2f\n', maxValue);
else
fprintf('The Producer is: %s\n', Producer{maxIndex});
fprintf('The monetary value is: %.2f\n', maxValue)
end
End MATLAB Code.
Output:
领英推荐
The Maximum Producer is: Seattle
The Maximum monetary value is: 56500.00
Discussion:
The shipping costs, production values, etc are fictional and inaccurate. I am practicing and validating my code with REF [1].
References:
1. Cantlebary, Liz. Li, Lawrence. (2020). Facility location problem. Cornell University. https://optimization.cbe.cornell.edu/index.php?title=Facility_location_problem