constrain variables to a set of values

조회 수: 1 (최근 30일)
Omar Morsy
Omar Morsy 2021년 12월 6일
댓글: Matt J 2021년 12월 7일
I have two questions.
My objective finction is L*A (dot product).
I want to optimze my variables which are in matrix (A). But the elemnts of the output of optimizing A should be one value from a set of specific values.
For example: I want to set the output values of A (after the optimization) to be one of the following values { 1:37}.
1) how can I set that the elemnts of the output matrix (A) to be one of the values from the givien set?
And one more thing. I have a ready function (pfile) which I want to use in the optimization problem. That function works as follow:
[w, a, x] = ASU(A)
I get 3 outputs from that function and I would like to minimize my objective function subjected to the output (a) and (x) =0.
2) how can I use the output of the given ASU function as contraints to the optimization problem?
The problem is linear and I am using solver-based.
L is 345x1
A is 1x345
w,a and x are 1x1
ASU accepts only a 1x345 matrix.
If I multiple L*A by a constant (density) it will give me w which is the objective function that I want to minimize
Thanks
  댓글 수: 5
Omar Morsy
Omar Morsy 2021년 12월 7일
편집: Omar Morsy 2021년 12월 7일
It is a dot product of L and A.
I forgot to clarify that.
Omar Morsy
Omar Morsy 2021년 12월 7일
I edited my question to clarify all the missing data

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2021년 12월 6일
편집: Matt J 2021년 12월 6일
The first thing I recommend is that you use ASU to compute L and the equality constraints in matrix form. You can do that by downloading func2mat,
M=func2mat(@fun,zeros(345,1))
L=M(1,:);
Aeq=M(2:3,:);
function out=fun(A)
[w,a,x]=ASU(A);
out=[w;a;x];
end
Now you make the change of variables A=Z*[1.6; 2.1; 2.2; 17.2] where Z is a 345x4 unknown binary matrix satisfying sum(Z,2)=1. You then solve for Z with intlinprog,
v=[1.6; 2.1; 2.2; 17.2];
f=kron(v',L);
Aeq=kron(v', Aeq); %a=0 and x=0
beq=[0;0];
Aeq=[Aeq; kron([1,1,1,1], speye(345))]; %sum(Z,2)=1
beq(3:347)=1;
lb=zeros(345,4);
Z=intlinprog(f,1:numel(lb),[],[],Aeq,beq,lb,lb+1);
A=Z*v;
  댓글 수: 15
Omar Morsy
Omar Morsy 2021년 12월 7일
Yes it is linear
Matt J
Matt J 2021년 12월 7일
If it truly is linear, then this should fix it.
A1=ones(1,345);
wax1=fun(A1);
M=func2mat( @(A)fun(A+1) - wax1 , A1);
L=M(1,:);
Aeq=M(2:3,:);
function out=fun(A)
[w,a,x]=ASU(A);
out=[w;a;x];
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by