我正在尝试使用matlab实现优化问题
其中N = 100,M =(N-1 / k)和L = 50。
N=100;
L = 50;
for K= 101:1:1000
M = (N-1)/K;
R=@(x) -((1./x(2)).*(N- (x(1).*M)-((min ( N./(L.*x(2)), K)-x(1))*(max(0,N-(L.*x(2).*x(1)))))/(x(1)+(min ( N./(L.*x(2)), K)-x(2)))) - (max(0,N-(L.*K*x(2)))));
LB = [1 1];
b=1:min((ceil(N/L)), K) ;
UB = [min((ceil(N./L)), K) ((N./(L*b))) ];
options = optimoptions('fmincon','Algorithm','interior-point'); % run interior-point algorithm
[xopt, vopt] = fmincon(R,1,[],[],[],[],LB,UB,[],options);
v(K) = -vopt;
end
plot(101:1000,v,'v-','LineWidth',2);
xlabel('Number of Users (K)');
ylabel('Delivery Rate (R)');
出现以下错误:
Warning: Length of lower bounds is > length(x); ignoring extra bounds. > In checkbounds (line 27) In fmincon (line 318) In R1 (line 19) Warning: Length of upper bounds is > length(x); ignoring extra bounds. > In checkbounds (line 41) In fmincon (line 318) In R1 (line 19) Index exceeds array bounds. Error in R1>@(x)-((1./x(2)).*(N-(x(1).*M)-((min(N./(L.*x(2)),K)-x(1))*(max(0,N-(L.*x(2).*x(1)))))/(x(1)+(min(N./(L.*x(2)),K)-x(2))))-(max(0,N-(L.*K*x(2))))) Error in fmincon (line 546) initVals.f = feval(funfcn{3},X,varargin{:}); Error in R1 (line 19) [xopt, vopt] = fmincon(R,1,[],[],[],[],LB,UB,[],options); Caused by: Failure in initial objective function evaluation. FMINCON cannot continue.
输出图应为此处显示的图:
(下界曲线)
答案 0 :(得分:0)
1
替换为[1, 1]
v
,这会加快您的运行速度
计算l
的上限,如您所见
取决于s
并且在分母中,将其视为非线性
然后设置UB = []
约束,您需要将 nonlcon
fmincon
N=100;
L = 50;
t = 101:1:1000;
le = length(t);
v = zeros(1, le);
for K= 100:1:1000
M = (N-1)/K;
R = @(x) -(1./(x(1))).*(N-x(1).*((N-1)./K)-((min(ceil(N./(L.*x(2))), K)).*...
max(N -L.*x(1).*x(2), 0))./((x(1) +(min(ceil(N./(L.*x(2))), K))))...
-(max(N - K.*L.*x(2), 0)));
LB = [1 1];
options = optimoptions('fmincon','Algorithm','interior-point');
[xopt, vopt] = fmincon(R,[1, 1],[],[],[],[],LB,[],...
@(x)nonlincon(x(1), x(2),N, L, K ),options);
v(K-101+1) = -vopt;
end
plot(101:1000,v,'v-','LineWidth',2);
xlabel('Number of Users (K)');
ylabel('Delivery Rate (R)');
function [c, ceq] = nonlincon(s, l,N, L, K )
c(1) = l -N./(L.*s);
c(2) = s - min((ceil(N./L)), K) ;
ceq = [];
end