logical expression in objective function
5 views (last 30 days)
Show older comments
mohammad alquraan
on 22 Jun 2019
Commented: mohammad alquraan
on 25 Jun 2019
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);
....
0 Comments
Accepted Answer
Matt J
on 23 Jun 2019
Edited: Matt J
on 23 Jun 2019
The way you would do this is to introduce additional binary variables,
b1=optimvar('boolean1','Type','integer','LowerBound',0,'UpperBound',1);
b2=optimvar('boolean2','Type','integer','LowerBound',0,'UpperBound',1);
and linear constraints,
prob.Constraint.Boolean1_Upper = b1>=(x(1)+x(2)+x(3)-0.0001)/U1;
prob.Constraint.Boolean1_Lower = b1<=(x(1)+x(2)+x(3))/0.0001;
prob.Constraint.Boolean2_Upper = b2>=(x(6)+x(7)+x(8)-0.0001)/U2;
prob.Constraint.Boolean2_Lower = b2<=(x(6)+x(7)+x(8))/0.0001;
where U1 and U2 are constant bounds large enough that the right hand sides can never be greater than 1. For example, if you have positive upper bounds on the x(i), the U can be the sum of those bounds.
These contraints combined with the binariness of b1 ensure that b1=(x(1)+x(2)+x(3)>=0.0001), and analogously for b2.
And now your objective would just be,
prob.Objective=b1+b2;
7 Comments
More Answers (2)
Stephan
on 22 Jun 2019
Hi,
use the inequality constraints A and b as input arguments for the solver.
4 Comments
Walter Roberson
on 23 Jun 2019
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
on 23 Jun 2019
11 Comments
Matt J
on 25 Jun 2019
x = optimvar('x',N*(M+2),1,'Type','integer','LowerBound',0,'UpperBound',1);
See Also
Categories
Find more on Get Started with Problem-Based Optimization and Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!