我的代码在下面给出并且它没有工作因为intlinprog没有正确实现请有人指导我或帮助我这一点,我将非常感激。我试图实现的是最小化ro mx(最大链接利用率和它的两个主要限制在这里附带的图像Constraint Formula
中给出我得到的错误是
使用intlinprog时出错(第121行)INTLINPROG要求以下输入为数据类型double:'f'。
主要错误(第111行)[x,fval,exitflag] = intlinprog(@objectiveFun,...
代码
% delta_edp : if link e on path p used for demand d
% x_dp : if path used for demand
% y_e : if link e used in any primary path
% l_dp : the fraction of traffic via path p
%link
global hd ce Ye delta_edp X_dp;
link(1,:)=[1 2];
link(2,:)=[1 3];
link(3,:)=[1 4];
link(4,:)=[2 6];
link(5,:)=[3 6];
link(6,:)=[3 7];
link(7,:)=[4 8];
link(8,:)=[4 9];
link(9,:)=[6 10];
link(10,:)=[7 10];
link(11,:)=[8 11];
link(12,:)=[8 12];
link(13,:)=[9 12];
link(14,:)=[9 13];
link(15,:)=[1 5];
link(16,:)=[5 13];
%primary path
Pd_pr(1,:)=[2, 6, 10];
Pd_pr(2,:)=[3,7,11];
Pd_pr(3,:)=[3,7,12];
Pd_pr(4,:)=[15, 16,0];
%sencondary path
Pd_s(1,:)=[1,4,9];
Pd_s(2,:)=[2,5,9];
Pd_s(3,:)=[3,8,13];
Pd_s(4,:)=[3,8,14];
path=[Pd_pr;Pd_s];
%link capacity
ce=[50 50 200 50 50 50 150 50 50 50 50 50 50 50 50 50];
%demand
demand=[1 10;1 11;1 12;1 13];
%associated flow values for demand
hd=[50 50 50 50];
%value of X_dp
X_dp=zeros(4,8);
for jj=1:4
for kk=1:8
demandStart=demand(jj,1);
demandEnd=demand(jj,2);
pathStart=path(kk,1);
linkStart=link(pathStart,1);
pathEnd=path(kk,3);
if pathEnd==0
pathEnd=path(kk,2);
end
linkEnd=link(pathEnd,2);
if pathEnd==0
pathEnd=path(kk,2);
end
if demandStart==linkStart && demandEnd==linkEnd
X_dp(jj,kk)=1;
end
end
end
X_dp1=reshape(X_dp,1,[]);
%value of delat_edp
delta_edp=zeros(16,4,8);
for ii=1 : 16
for jj=1: 4
for kk=1:8
for nn=1:3
if path(kk,nn)==ii && X_dp(jj,kk)==1
delta_edp(ii,jj,kk)=1;
end
end
end
end
end
%value of Ye
Ye=zeros(16,1);
for ii=1:16
for kk=1:4
for nn=1:3
if Pd_pr(kk,nn)==ii
Ye(ii)=1;
end
end
end
end
lb = zeros(1,32);
ub=1;
options = optimoptions('intlinprog','Display','iter');
intcon=@constraint;
[x,fval,exitflag]=intlinprog(@objectiveFun,...
32,[],[],lb,ub,intcon,options);
l_dp=reshape(x,4,8)
min_romax=fval
function [c,ceq] =constraint(X_dp1)
global hd ce Ye delta_edp;
%first constrain
X_dp=reshape(X_dp1,4,8);
X_dp=reshape(X_dp1,4,8);
for ii=1 : 16
ro(ii)=0;
for jj=1 : 4 %demand
for kk=1:8
if delta_edp(ii,jj,kk)==1
ro(ii)=ro(ii)+hd(jj)*X_dp(jj,kk);
end
end
end
ro(ii)=ro(ii)/ce(ii);
end
ro_max=max(ro);
for ii=1:16
A(ii)=0;
C(ii)=1;
for jj=1:4
for kk=1:8
A(ii)=A(ii)+hd(jj)*delta_edp(ii,jj,kk)*X_dp(jj,kk);
end
end
B(ii)=ce(ii);
C(ii)=C(ii)*(1-Ye(ii));
end
c=A-B;
c=round(c);
ceq=(A./B)-C-ro_max;
ceq=round(ceq);
%% objective function
function f=objectiveFun(l_dp1)
global hd ce delta_edp
l_dp=reshape(l_dp1,4,8);
for ii=1 : 16
ro(ii)=0;
for jj=1 : 4 %demand
for kk=1:8
if delta_edp(ii,jj,kk)==1
ro(ii)=ro(ii)+hd(jj)*l_dp(jj,kk);
end
end
end
ro(ii)=ro(ii)/ce(ii);
end
ro_max=max(ro);
f=ro_max