logical expression in objective function
이전 댓글 표시
can i use logical expression inside the objective function of an optimization problem?
...
prob.Objective = (x(1)+x(2)+x(3)>= 0.0001)+(x(6)+x(7)+x(8)>= 0.0001);
....
채택된 답변
추가 답변 (2개)
Stephan
2019년 6월 22일
1 개 추천
Hi,
use the inequality constraints A and b as input arguments for the solver.
댓글 수: 4
Walter Roberson
2019년 6월 22일
Note that unless you have asked for maximization, then the minima would occur when both parts of the logical expression are false.
Your objective should almost always involve all of your inputs .
mohammad alquraan
2019년 6월 22일
Walter Roberson
2019년 6월 23일
The code you posted is already an example of using logical expressions inside objective functions.
The difficulty is that only intlinprog and ga and gamultiobj are certain to handle discontinuities. patternsearch() might handle discontinuities; I would have to review how simannealbnd works to confirm whether it handles discontinuities or not.
fmincon and fminsearch and lsqnonlin do not handle discontinuities.
This does not mean that you definitely cannot use logical expressions for those functions, but you would have to be careful to retain continuity of the function, and continuity of the first derivative; you can violate continuity of the second and further derivatives.
You should probably be recoding
(x(1)+x(2)+x(3)>= 0.0001)+(x(6)+x(7)+x(8)>= 0.0001)
as a pair of linear constraints,
x(1)+x(2)+x(3) <= 0.0001*(1-eps)
x(6)+x(7)+x(8) <= 0.0001*(1-eps)
The 1-eps has to do with converting the >= to < form: if 0.0001 could be exactly represented in binary floating point, then a value of 0.0001 exactly would generate a logical value of true, which is numeric 1, which would greater than the logical value of false, which is numeric 0, so and for optimization you want minima, so you want x(1)+x(2)+x(3) == 0.0001 to be outside the constraint. And 0.0001 as a literal is the value 0.000100000000000000004792173602385929598312941379845142364501953125 in binary, so permitting equality would get you values that were larger than 0.0001 which you do not want. Permitting equality to 0.0001*(1-eps) is fine as that is 0.000099999999999999977687119290248318748126621358096599578857421875
mohammad alquraan
2019년 6월 23일
편집: mohammad alquraan
2019년 6월 23일
mohammad alquraan
2019년 6월 23일
댓글 수: 11
Walter Roberson
2019년 6월 23일
bintprog has not existed since R2013-something.
mohammad alquraan
2019년 6월 23일
Walter Roberson
2019년 6월 23일
optimvar is new as of R2017b. It is not possible that you were able to code with optimvar in R2013a.
Walter Roberson
2019년 6월 23일
Does any x participate in more than one combination ? If not, then the number of users is the sum of the x, divided by 3.
mohammad alquraan
2019년 6월 23일
There is nothing to be gained but pain by downgrading your solution tool to bintprog. Now, you have to take every one of your integer non-binary variables, x and express them as sums of binary variables.
x1=b11+b12+b13+...
x2=b21+b22+b23+...
Because this greatly increases the number of variables, the likelihood of a computationally efficient solution is also harder to guarantee.
But if you wish to go this route, then the same constraints and objective formulation as I outlined for the problem-based solver would be applicable with bintprog as well.
mohammad alquraan
2019년 6월 23일
Matt J
2019년 6월 24일
The easiest would be to compose the problem first using the problem-based method and then convert it to solver form using,
problem = prob2struct(prob)
mohammad alquraan
2019년 6월 25일
Matt J
2019년 6월 25일
x = optimvar('x',N*(M+2),1,'Type','integer','LowerBound',0,'UpperBound',1);
mohammad alquraan
2019년 6월 25일
카테고리
도움말 센터 및 File Exchange에서 Quadratic Programming and Cone Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
