How to implement theses constraints in the cost function ?
Show older comments
I am working on a constrained PSO program (S decision variable) where the constraints are arrays that there elements should be lower or egual to 0.4 :
1) dx = [S(1) - 0.3, diff(S)];
2) ds = [0.3 - S(1),S(1:end-1)-S(2:end)];
abs(dx)<=0.4
abs(ds)<=0.4
in a simpler way,dx and ds should be arrays with elements that are less or egual to 0.4
i tried this : le(abs(dx),0.4)
le(abs(ds),0.4)
but when runing the main pso i dont see constrained results
2 Comments
Matt J
on 16 Nov 2022
i tried this
Where? How? pso() doesn't have an input for such constraints. Maybe use ga() or patternsearch(). Also, the constraints are linear, so you should put them in the form A*S<=b.
Matt J
on 16 Nov 2022
Also, from your expressions we can see that dx=-ds. Therefore, the constraints, abs(dx)<=0.4 and abs(ds)<=0.4 are the same thing.
Answers (1)
pso() doesn't have an input for such constraints. Maybe use ga() or patternsearch().
Here's how it would look when solved with ga():
lb=-inf(nvars,1);
ub=-lb;
e=0.4*ones(nvars-1,1);
D=diff(eye(nvars));
%constraint matrices
lb(1)=-0.1;
ub(1)=0.7;
A=[D;-D];
b=[e;e];
%run optimization
S = ga(fun,nvars,A,b,[],[],lb,ub)
12 Comments
Anwar
on 16 Nov 2022
Matt J
on 16 Nov 2022
I'm not familiar with Yarpiz. Maybe if you provide a link to the syntax documentation...
Anwar
on 16 Nov 2022
For sure ,Here's the Pso's Script
That doesn't help us, I'm afraid. You made it sound like it's a 3rd party package. Don't they provide user documentation with it? Where is the section of the documentation which talks about how to set up a problem and constraints?
Anwar
on 16 Nov 2022
If you have no other constraints than what we've discussed, and a small enough number of unknowns S(i), you can find the vertices V of your constraint set using this FEX download,
For example, with nvars=10 and if I assume all -100<=S(i)<=100,
nvars=10;
lb=-100*ones(nvars,1);
ub=-lb;
e=0.4*ones(nvars-1,1);
D=diff(eye(nvars));
%constraint matrices
lb(1)=-0.1;
ub(1)=0.7;
A=[D;-D];
b=[e;e];
[A,b]=addBounds(A,b,[],[],lb,ub);
V=lcon2vert(A,b)
>> whos V
Name Size Bytes Class Attributes
V 1024x10 81920 double
This means that all feasible vectors S have the form S=V'*x where all x(j) are bounded according to 0<=x(j)<=1. Thus you can rewrite your objective function f(S) as a function x with the change of variables f(V.'*x). But since all x(j) have only simple bounds, they can be optimized using PSO in this transformed space.
A problem may be that you now have 1024 variables x(j) whereas before, you had only 10 variables S(i). I'm not sure whether that's a big number for PSO.
Matt J
on 17 Nov 2022
How the changing to f(V.'x) is done exactly.
If you have f(S), then you can do
f=@(x) f(V.'*x)
does lb (1) =-0.1 And ub(1)=0.7 affect by giving negative values to the S ?.
The constraint on S(1) that you posted is |S(1)-0.3|<=0.4, which is the same as -0.1<=S(1)<=0.7.
Anwar
on 17 Nov 2022
Edited: Bruno Luong
on 17 Nov 2022
Matt J
on 17 Nov 2022
The objective function came out of your brain. If it's returning the wrong value, I have no way of knowing what it should be returning instead.
Anwar
on 17 Nov 2022
Categories
Find more on Particle Swarm 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!