필터 지우기
필터 지우기

solve optimization with constraints

조회 수: 2 (최근 30일)
ali
ali 2021년 2월 28일
댓글: ali 2021년 3월 1일
I want to maximize an equation with 12 variables (The comment in code described the problem). I solved this by excel solver, but in matlab I dont know how to write the constraints. Below is my try:
% Maximize B = 3.9 X1 + 4.2 X2 + 4.2 X3 + 4.5 X4 + 4.1 X5 + 3.6 X6 + 3.1 X7
% + 2.7 X8 + 2.5 X9 + 2.6 X10 + 2.9 X11 +3.6 X12
%Subject to:
% S0 = 5;
% S(t-1) + I(t) - X(t) = S(t) (t =1,...,12) --> how to wirte this constraint?
% 1<= X(t) <= 7 (t = 1,...,12 )
% S(t) <= 10 (t = 1,...,12 )
f = [-3.9 -4.2 -4.2 -4.5 -4.1 -3.6 -3.1 -2.7 -2.5 -2.6 -2.9 -3.6];
lb=[1;1;1;1;1;1;1;1;1;1;1;1];
ub=[7;7;7;7;7;7;7;7;7;7;7;7];
I = [4 3 2 2 1 2 3 3 2 2 2 3];

채택된 답변

Alan Weiss
Alan Weiss 2021년 2월 28일
This problem is similar to Create Multiperiod Inventory Model in Problem-Based Framework. I think that you will find the problem-based approach easy to use.
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 3
Alan Weiss
Alan Weiss 2021년 3월 1일
Well, it is more awkward, but fairly straightforward. You simply have to keep careful track of variable indices.
Let S(1) through S(12) represent the S variables, and X(1) through X(12) the X variables. You have to put all of the variables into one, typically called x (lower case). Say the mapping is x = [X,S], where all variables are row vectors. Then you can write your constraints all in terms of x in matrices A and Aeq to represent the dynamics. For example, the first equation
S(t-1) + I(t) - X(t) = S(t)
becomes, for t = 1,
S0 + I(1) = S(1) + X(1) = x(1) + x(13)
You can represent this as row 1 in matrix Aeq with beq(1) = S0 + I(1) = 5 + 4. The Aeq row is
[1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0] % Aeq(1,1) = Aeq(1,13) = 1
Similarly, for t = 2 the equation is
I(2) = S(2) + X(2) - S(1)
In terms of Aeq and beq you get
Aeq(2,2) = Aeq(2,14) = 1
Aeq(2,13) = -1
beq(2) = I(2) = 3
The matrix Aeq has a simple banded structure. You have to be careful about the bounds on S and X; for example, does S have a lower bound?
You have to represent the f coefficients in terms of x, which means adjoin 12 zeros to the end of your current f vector. OK?
Alan Weiss
MATLAB mathematical toolbox documentation
ali
ali 2021년 3월 1일
YEESSS, Thank you so much.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by