Mixed-integer Linear Programming with double sum constraints and 3D optimization variable

7 ビュー (過去 30 日間)
Hello,
I am trying to implement the below MILP problem. I did not add all of the constraints to not to complicate my question. P and W are integer decision variables (Mx1).
s.t.
Below is my code to implement. I tried to use MATLAB's optimization language but I couldn't use it correcly so I used an inefficient for loop. Commented alternative MATLAB script on top of each constraint.
data = someFun2ImportData('data.csv');
len = length(data);
% Pairwise distance matrix
dist_matrix = squareform(pdist([data(:,2:3)],@lldistmile));
P = optimvar('P',len,'Type','integer','LowerBound',0,'UpperBound',1);
W = optimvar('w', len,len,len, 'Type', 'integer', 'LowerBound',0,'UpperBound',1);
beta = 150;
t = 5;
% Constraints
for i=1:len
const1 = sum(W(:,:,i)) == 1;
ndesign.Constraints.const1 = const1;
% const2 = sum(W,2) <= P;
const2 = sum(W(:,i,:)) <= P(i);
ndesign.Constraints.const2 = const2;
%const3 = sum(W*dist_matrix/beta,[1 2])*60 <= t;
for k=1:len
const3 = sum(W(i,k,i).*dist_matrix(i,k))/beta*60 <= t;
sum(W(i,k,i).*dist_matrix(i,k))/beta*60
ndesign.Constraints.const3 = const3;
end
end
ndesign = optimproblem; % Create optimization problem
objfun = sum(P); % Objective Function
ndesign.Objective = objfun; % Assign objfun to the problem
opts = optimoptions('intlinprog','Display','off','PlotFcn',@optimplotmilp);
[sol,fval,exitflag,output] = solve(networkdesign,'options',opts);
I need your help to implement this problem.

採用された回答

Matt J
Matt J 2020 年 9 月 9 日
編集済み: Matt J 2020 年 9 月 9 日
data = someFun2ImportData('data.csv');
len = length(data);
% Pairwise distance matrix
dist_matrix = squareform(pdist([data(:,2:3)],@lldistmile));
P = optimvar('P',[len,1],'Type','integer','LowerBound',0,'UpperBound',1);
W = optimvar('w', [len,len,len,] , 'Type', 'integer', 'LowerBound',0,'UpperBound',1);
beta = 150;
t = 5;
ndesign = optimproblem('Objective',sum(P)); % Create optimization problem
e=ones(1,len);
ndesign.Constraints.const1 = ( sum(reshape(W,[],len),1)==1 );
ndesign.Constraints.const2 = ( squeeze(sum(W,2))<=P*e );
ndesign.Constraints.const3 = ( dist_matrix(:).'*reshape(W,[],len)<=beta*t );
opts = optimoptions('intlinprog','Display','off','PlotFcn',@optimplotmilp);
[sol,fval,exitflag,output] = solve(ndesign,'options',opts);
  3 件のコメント
Sanee
Sanee 2024 年 8 月 26 日
Hello Matt, What will the code look like if the data was inputed in the code?
Matt J
Matt J 2024 年 8 月 26 日
Isn't it already?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Programming and Mixed-Integer Linear Programming についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by