Mathematical formulation of a operations research problem

12 ビュー (過去 30 日間)
David Franco
David Franco 2019 年 9 月 10 日
編集済み: David Franco 2021 年 12 月 2 日
How can I implement this objective function and its constraints in Matlab (p-median problem)?
Thank you very much!
  1 件のコメント
darova
darova 2019 年 9 月 10 日
I can give you a start
y = zeros(1,10);
y = facility == candidate;

サインインしてコメントする。

採用された回答

Hasan Cosgun
Hasan Cosgun 2021 年 12 月 2 日
編集済み: Hasan Cosgun 2021 年 12 月 2 日
nNodes = 52; % no of nodes (customers)
nP = 6; % No of Warehouses/Facilities
% dist: nNodes x nNodes distance matrix
% decision variables
x = optimvar('x',1,nNodes,'Type','integer','LowerBound',0,'UpperBound',1);
y = optimvar('y',nNodes,nNodes,'Type','integer','LowerBound',0,'UpperBound',1);
prob = optimproblem('ObjectiveSense','minimize');
prob.Objective = sum(sum(dist .* y));
onesum = sum(y,2) == 1;
vertxy = optimconstr(nNodes,nNodes);
for i=1:nNodes
for j=1:nNodes
vertxy(i,j) = y(i,j) <= x(j);
end
end
depsum = sum(x) == nP;
prob.Constraints.onesum = onesum;
prob.Constraints.vertxy = vertxy;
prob.Constraints.depsum = depsum;
nSolution = solve(prob);
Just a full start...
  1 件のコメント
David Franco
David Franco 2021 年 12 月 2 日
編集済み: David Franco 2021 年 12 月 2 日
Thank you very much @Hasan Cosgun!!! I updated your code with an example:
% P-Median Problem (PMP)
rng default
nNodes = 32; % No of Customers
nP = 6; % No of Facilities
xx = randi(20,nNodes,2);
dist = pdist2(xx,xx,'euclidean');
% decision variables
y = optimvar('y',1,nNodes,'Type','integer','LowerBound',0,'UpperBound',1);
x = optimvar('x',nNodes,nNodes,'Type','continuous','LowerBound',0);
prob = optimproblem('ObjectiveSense','minimize');
prob.Objective = sum(sum(dist .* x));
onesum = sum(x,2) == 1; % Restriction 1
depsum = sum(y) <= nP; % Restriction 2
vertxy = optimconstr(nNodes,nNodes);
for i = 1:nNodes
for j = 1:nNodes
vertxy(i,j) = x(i,j) <= y(j); % Restriction 3
end
end
prob.Constraints.onesum = onesum;
prob.Constraints.depsum = depsum;
prob.Constraints.vertxy = vertxy;
[sol,fval,exitflag,output] = solve(prob);
Solving problem using intlinprog. LP: Optimal objective value is 82.069171. Optimal solution found. Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 0 (the default value). The intcon variables are integer within tolerance, options.IntegerTolerance = 1e-05 (the default value).
z = 1:nNodes;
idx = sum(sol.x .* z(ones(nNodes,1),:),2);
h1 = gscatter(xx(:,1),xx(:,2),idx);
hold on
h2 = plot(xx(sol.y == 1,1),xx(sol.y == 1,2),'ko');
legend('Location','eastoutside')
h2.Annotation.LegendInformation.IconDisplayStyle = 'off';

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2020 年 3 月 11 日
Should be very easy with the Problem-Based Optimization Workflow.
  1 件のコメント
David Franco
David Franco 2020 年 3 月 11 日
Thank you Matt, I will try this.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by