Change Value during optimization process

조회 수: 3 (최근 30일)
Tim
Tim 2018년 10월 10일
댓글: Tim 2018년 10월 12일
Hey,
is it possible to change a value during the optimization loop?
Example: I want to maximize x and y
lb = lowerbound ub = upperbound
a = lb(0) ub(100)
b = lb(0) ub(50)
x = a+b
y = a+b
To archieve the solution I need the solution to be x = 50 + 25 and y = 50 + 25 how would i express this in code? Thanks!
example code I thought of but doesnt work
xyprob = optimproblem;
a = optimvar('a','LowerBound',0,'UpperBound',500);
b = optimvar('b','LowerBound',0,'UpperBound',100);
y = optimvar('y');
x = optimvar('x');
xyprob.ObjectiveSense = 'maximize';
xyprob.Objective = x
xyprob.Objective = y
xyprob.Constraints.econs1 = x == a+b
xyprob.Constraints.econs2 = y == a+b
[xysol,fval] = solve(xyprob);
tbl = struct2table(xysol)
  댓글 수: 2
Matt J
Matt J 2018년 10월 10일
편집: Matt J 2018년 10월 10일
Example: I want to maximize x and y
Since x=y why don't we just say that we are maximizing x?
If x~=y, what does it mean to maximize two objectives at once in a linear program?
Why are x and y optimvars at all? Why wouldn't you just have
a = optimvar('a','LowerBound',0,'UpperBound',500);
b = optimvar('b','LowerBound',0,'UpperBound',100);
xyprob.Objective = a+b ;
Tim
Tim 2018년 10월 10일
Hey thank you for your quick answer.
Yes thats right I need to maximize 2 or more variables at once. I am new to optimization with matlab so I dont know which solver I should choose. Maybe I need to go for fgoalattain ?
Here is a litte explanation for the problem.
a = storage filled with 100 kwh b = storage filled with 50 kwh x = house y = house
Explanation: x and y are houses, who need energy. They draw energy from the storages a and b. So if x takes 30 from a and 20 from b there is still 70 in a and 30 in b, but it should be equal.
The solution I want it to be is x = 50 + 25 and y = 50 + 25

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

채택된 답변

Matt J
Matt J 2018년 10월 11일
How about this?
xyprob = optimproblem;
xa = optimvar('xa','LowerBound',0,'UpperBound',100);
xb = optimvar('xb','LowerBound',0,'UpperBound',50);
ya = optimvar('ya','LowerBound',0,'UpperBound',100);
yb = optimvar('yb','LowerBound',0,'UpperBound',50);
xyprob.ObjectiveSense = 'maximize';
xyprob.Objective = xa+xb;
xyprob.Constraints.econs1 = xa+ya <= 100;
xyprob.Constraints.econs2 = xb+yb <= 50;
xyprob.Constraints.econs3 = xa+xb == ya+yb;
xyprob.Constraints.econs4 = xa+xb + ya+yb == 150;
[xysol,fval] = solve(xyprob);
tbl = struct2table(xysol)
  댓글 수: 1
Tim
Tim 2018년 10월 12일
wow you are a genius! Thx so much

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Least Squares에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by