Discretized/Vector Nonlinear Optimization using fmincon (Optimal Scheduling)
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I have a discretized nonlinear optimization problem. I want to find the optimal schedule of a decision variable (X) over 3 sampling instants. I am attempting to use the fmincon function. The objective function (J) for minimization is nonlinear and the only constraints are the upper (ub) and lower bounds (lb) on the decision variable. The solution should be of the form X = [x(1) x(2) x(3)]. Variables T, V_max, & QGg_max are known.
%Known parameters
V_max = 3.15;
Qg_max = 200;
T = [2 4 6];
%Constraints
A = [];
b = [];
Aeq = [];
beq = [];
%Boundary limits
lb = transpose((T/(3.6*Qg_max)).*(ones(1,3)));
ub = V_max*ones(3,1);
%Initial guess
x0 = [1 2 3];
%Optimization
X = fmincon(@myFUN,x0,A,b,Aeq,beq,lb,ub);
The myFUN.m function contains the following code:
function J = myFUN(X)
%Nonlinear objective function
T = [2 4 6];
J = (X.*T.^2) + (X) + ((T.^2)./X) + (T) + (T.*X.^2);
end
But when attempting to run the script, I get the following error:
Error using fmincon (line 619)
Supplied objective function must return a scalar value.
Error in fminconHELP (line 20)
X = fmincon(@myFUN,x0,A,b,Aeq,beq,lb,ub);
I cannot find any help on addressing this issue or an example of using fmincon for discrete nonlinear optimization. So I'm not sure if fmincon can be used for this purpose? In that case, any suggestions on alternative techniques?
채택된 답변
As the error message says, the J returned by myFUN is not a scalar, so it is not clear to MATLAB what it means to minimize or maximize it.
In any case, it appears that in your problem each sampling time is independent of the others, so there is no need to approach this as a multi-variable optimization problem. You could just apply fmincon (or even just use fminbnd) to each sampling instant separately:
x0 = [1 2 3];
T=[2,4,6];
for i=1:3
X(i) = fmincon(@(X) (X.*T(i).^2) + (X) + ((T(i).^2)./X) + (T(i)) + (T(i).*X.^2),x0(i),...
[],[],[],[],lb(i),ub(i));
end
댓글 수: 18
Another problem I'm experiencing is how to apply this to a multi-variable optimization problem, i.e. both the vectors X and T are the decision vectors and subject to certain upper and lower bounds. The solution would thus be of the form X = [x(1) x(2) x(3)] and T = [t(1) t(2) t(3)]. How can fmincon be used for this multi-variable scheduling problem?
And what would be your objective function ?
I want to minimize objective function J(X,T) = (X*T^2) + (X) + ((T^2)/X) + (T) + (T*X^2)
But the result will be a vector, not a scalar value as it is necessary for optimization ...
J is a function of X and T where optimization of X and T will result in a scalar-valued J at each sampling instant.
And these scalars J_i at each sampling instat i are added to get the overall value J of the objective ?
If I understand correctly, the revised problem is still separable across the sampling instants. At sampling instant i, you know have a 2-variable optimization with objective
J(X,T) = (X*T^2) + (X) + ((T^2)/X) + (T) + (T*X^2)
Here X and T (and hence also J) are scalars.
Yes, that is correct. My attempt thus far is as follows in the code (which I believe to be correct).
%Known parameters
V_max = 3.15;
Qg_max = 200;
numVars = 2;
numSamples = 3;
%Constraints
A = [];
b = [];
Aeq = [];
beq = [];
%Boundary limits
lbV = transpose((T/(3.6*Qg_max)).*(ones(1,numSamples)));
lbT = 500*ones(numSamples,1);
lb = [lbV,lbT];
ubV = V_max*ones(numSamples,1);
ubT = 2000*ones(numSamples,1);
ub = [ubV,ubT];
% Initial guess
% Initial guess for belt speed
V0 = ones(numSamples,1);
% Initial guess for feed rate
T0 = 600*ones(numSamples,1);
% Matrix form of intial guess
x0 = [V0,T0];
% Form of the solution
% X = [x(1) x(2)];
% X = [V(1) T(1)
% V(2) T(2)
% V(3) T(3)]
% Initialise arrays
X = zeros(numSamples,numVars);
fval = zeros(numSamples,1);
% Optimization
for i=1:numSamples
[X(i,:),fval(i)] = fmincon(@(X) (X(1).*X(2).^2) + (X(1)) + ((X(2).^2)./X(1)) + (X(2)) + (X(2).*X(1).^2),x0(i,:),[],[],[],[],lb(i,:),ub(i,:));
end
% Display solution
V_optimal = transpose(X(:,1))
T_optimal = transpose(X(:,2))
fval = transpose(fval)
My next issue is to implement a constraint such that the summation of the elements of T (i.e. T(1) + T(2) + T(3)) exceeds a certain value Tsum. I am unable to implement the correct A and b vectors to satisfy AX < b for this multi-variable problem.
Again the question:
If
X = [V(1) T(1) V(2) T(2) V(3) T(3)]
is your decision vector, what is your objective ?
My next issue is to implement a constraint such that the summation of the elements of T (i.e. T(1) + T(2) + T(3)) exceeds a certain value Tsum.
In that case, the problem is no longer decomposable across sampling instants. As Torsten says, we need you to write down for us the 6-variable function that you intend to minimize.
I do not know how to adapt my objective function to account for this summation inequality constraint.
The objective function isn't something that "accounts" for the constraints. They are separate things.
You must know the thing you are trying to minimize (subject to the constraints). If you don't know, how can anyone else?
I want to minimize J = (X*T^2) + (X) + ((T^2)/X) + (T) + (T*X^2) at each sampling instant such that the summation of the elements of T exceed a particular value. I have no further information on the objective function. So I'm not sure how I would write down the required 6-variable objective function.
I will give you some examples to help guide your thinking. First, define
f(a,b)=(a*b^2) + (a) + ((b^2)/a) + (b) + (b*a^2)
where a and b are scalars. You have 6 unknowns X(i),T(i), i.=1,2,3.
You could minimize
J = f(X(1),T(1)) + f(X(2),T(2)) + f(X(3),T(3))
subject to sum(T)>=Tsum.
Alernatively, you could minimize
J = 10*f(X(1),T(1)) + f(X(2),T(2)) + f(X(3),T(3))
imposing the same constraints sum(T)>=Tsum.
Yet another alternative is to minimize
J = 3*f(X(1),T(1)) + pi*f(X(2),T(2)) + 75*f(X(3),T(3))
In all of these choices of J (and infinitely many more), the optimization algorithm has an incentive to make each f(X(i),T(i)) as small as possible, because reducing f(X(i),T(i)) also reduces J. However, they will all give different solutions when your constraint sum(T)>=Tsum is imposed.
So, your problem is not fully specified (and we cannot help you) until you are able to say more than "I want f(X(i),T(i)) as small as possible at all sampling instants i".
Apologies, I understand now what you mean. I wish to minimize:
J = f(X(1),T(1)) + f(X(2),T(2)) + f(X(3),T(3))
Where:
f(X,T) = (X*T^2) + (X) + ((T^2)/X) + (T) + (T*X^2)
Subject to sum(T) >= Tsum; and lower- and upper-bounds on X and T
Very good. That would be,
X0=[1,2,3];
T0=[2,4,6];
A=[0 0 0 -1 -1 -1];
b=-Tsum;
lb=[lb1,lb2,lb3,lb4,lb5,lb6];
ub=[ub1,ub2,ub3,ub4,ub5,ub6];
psol=fmincon(@myObjective, [X0,T0], A,b,[],[],lb,ub)
X=psol(1:3);
T=psol(4:6);
function J = myObjective(p)
X=p(1:3);
T=p(4:6);
f = @(a,b) (a*b^2) + (a) + ((b^2)/a) + (b) + (b*a^2);
J = f(X(1),T(1)) + f(X(2),T(2)) + f(X(3),T(3));
end
One last problem is incorporating 2 nonlinear constraints. At each sampling instant i, the following constraints should be met:
-T(i)/X(i) <= 0
and
T(i)/X(i) - 100 <= 0
My approach is to define a function myCON as follows:
function [c,ceq] = myCON(q)
%Nonlinear constraints
c(1) = -(q(2))/(q(1));
c(2) = ((q(2))/(q(1))) - 100;
ceq = [];
end
Then I try to pass the nonlinear constraint function handle as a parameter of the fmincon function, but erroneous results are produced (the script does not crash however).
psol=fmincon(@myObjective, [X0,T0], A,b,[],[],lb,ub,@myCON)
I suspect that q in the myCON is not properly linked to X and T in the code I have written. I do not understand how to properly apply nonlinear constraints in a multi-variable scheduling problem. Thank you for the assistance thus far.
What are the upper and lower bounds lb,ub on X(i)? Are the X(i) always positive? If so, your nonlinear constraints are the same as the following linear constraints and it would be better to pose it that way instead,
T(i)>=0
T(i)-100*X(i)<=0
A similar thing can be done if X(i) are constrainted to be negative.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
