Use Particle Swarm Optimization with inequality linear constraints.

23 ビュー (過去 30 日間)
Maisa Melo
Maisa Melo 2019 年 3 月 20 日
回答済み: Abderrahmane DADA 2019 年 9 月 15 日
I would like to know how can I use Particle Swarm Optimization with inequality linear constraints.
I get to run my code just with bounds limits, but I need run my code with linear constraints also, I need the sintax of function PSO.

採用された回答

Stephan
Stephan 2019 年 3 月 20 日
Hi,
there is not such a syntax, since PSO does not support constraints. If you need constraints i suggest to use ga, which is able to handle this.
Best regards
Stephan

その他の回答 (4 件)

Maisa Melo
Maisa Melo 2019 年 3 月 20 日
Hi Stephan, thank you to answer me.
I am trying to use PSO just because I am facing a problem with my results when I have used genetic algorithm toolbox.
Maybe you can help me with this another problem, i.e., the problem that I am facing genetic algorithm, because if I get the genetic algorithm working very well I will not need to use PSO.
Follow my problem with genetic algorithm:
I am using the toolbox genetic algorithm of Matlab R2015a version and I am facing a problem with the responses that genetic algorithm is obtaining.
I don't know why all the entries of the optimal vector that ga found are equals, for example, if v is an individual in a local minimum obtained by ga so v=(v1,v2,...,vn) and v1=v2=...=vn. I think that some operator of the genetic algorithm toolbox that I am using has the property to create individuals with equals coordinates and I need to change this property, I would like to create individuals that not have all equal coordinates, I would like the algorithm to be free to create individuals without this property.
I am using the following command line and options:
gaoptions = gaoptimset('CreationFcn',@gacreationlinearfeasible,'TolCon', 1e-6, 'TolFun', 1e-6, 'MutationFcn',@mutationadaptfeasible,'PopulationSize', 50, 'Generations', 50,'InitialPopulation',U0');
U =ga(@(U0) funcaoObjetivo(QP,U0',n),nvars,A,a,[],[],[],[],[],gaoptions);
  1 件のコメント
Alan Weiss
Alan Weiss 2019 年 3 月 20 日
We cannot answer why ga finds those points until we see your A and a matrices, and maybe (if it is not too long) your objective function funcaoObjetivo and the associated data U0 and n.
Alan Weiss
MATLAB mathematical toolbox documentation

サインインしてコメントする。


Maisa Melo
Maisa Melo 2019 年 3 月 20 日
Hi Alan, thank you to answer me.
I will show to you my code of constraints (Restricoes) and the objective function (funcaoObjetivo):
function [A,a] = Restricoes(beta,n,Riq,m,gama)
u0max=0;
un1max=0;
%%Sbarra
S=[eye(n),zeros(n,1);-1*ones(1,n),1;zeros(1,n),1];
[lin,col]=size(S);
Sbarra=zeros(m*(n+2),m*(n+1));
Sbarra(1:lin,1:col)=S;
for i=1:m-1
Sbarra(i*lin+1:(i+1)*lin,i*col+1:(i+1)*col)=S;
end%%end Sbarra
%%Lower Bound
Umin=beta*Riq*ones(m*(n+2),1);
for i=n+1:n+2:m*(n+2)
Umin(i)=-Riq;
end%end lower bound
%%Upper bound
Umax=gama*Riq*ones(m*(n+2),1);
for i=n+1:n+2:m*(n+2)
Umax(i)=u0max-Riq;
Umax(i+1)=un1max;
end%end upper bound
A=[Sbarra;-Sbarra]; %AU<=a
a=[Umax;-Umin];
end
Below is the matrix form of the constraints, the constraints umin(k)<=Su(k)<=umax(k) were concatenated to became just one inequality.
constraints.PNG
The objective function is given below:
fo.PNG
It is interesting to know how is defined the variables u and U:
u.PNG
V is the wealth of one portfolio investment in stock exchange, and my code calculates the wealth to current period and to m next periods
V.PNG
u(k)=(u1(k),u2(k),...,un(k)) , where ui(k) is the amount of money invested in the ith asset at time k.
c[eta(k+i)] and R(k,i) are matrices.
The variables of the problem are U.
The problem that I am facing is that the genetic algorithm define the same amount of money to all assets, it is not correct to my portfolio problem.
I need the algorithm to be free to choose to each asset one different amount of money, for example, the algorithm should choose to invest more money at the profit assets and not allocate money in the assets at a loss.
Sorry if my English is not so good, I am from Brazil and I am learning to speak English.
I thank you a lot for your availability to help me.
  1 件のコメント
Alan Weiss
Alan Weiss 2019 年 3 月 20 日
編集済み: Alan Weiss 2019 年 3 月 20 日
Thank you for the detail. I do not understand why you are trying to solve this problem using Global Optimization Toolbox solvers. The objective function looks smooth (perhaps a ratio of quadratics), and the constraints are linear. Therefore, you should not attempt to solve the problem using particleswarm or ga, but instead should use fmincon or perhaps quadprog if I misunderstand the constraints.
It is possible that you are computing an expectation using a simulation, and I did not understand that part of your explanation. If so, then perhaps read Optimizing a Simulation or ODE to see how you might need to set finite differences appropriately.
I did not test your linear constraints to see what kind of region they allow. Perhaps you should look at your feasible region by using linprog with your A and a matrices, and give varying f arguments to see what kinds of solutions you can get (I mean choose differing signs of the components of f). Also, and this is important, you should set finite bounds on all variables, botth upper and lower bounds.
One reason that your ga optimization is working poorly is that your options seem suited for a problem with just a few variables and dimensions, perhaps three or four variables u(i). I suspect that you have a great number of variables in reality. Therefore, a population size of 50 means that ga has no chance of providing you with reasonable answers. But in any case, you should not use ga for this kind of problem.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

サインインしてコメントする。


Maisa Melo
Maisa Melo 2019 年 3 月 20 日
I had already run this code using fmincon and quadprog, and the results that I obtained were very good. I would like the genetic algorithm to reach a similar result, because I will modify the objective function and change the constraints, and after this probably the fmincon and quadprog will not be able to lead with it problem anymore, and I will need use ga. But before I change the objective function I would like to secure that ga performance to this simplest problem is good, and so I will know that ga will be able to get good performance at the more difficult problem also. About the size of the population, the same problem the equals coordinates also happens when I use 400 individuals.
To you understand better the problem look the figure. The mission of the algorithm is to track the compound interest curve. The quadprog and fmincon are successful at the mission. The genetic algorithm also gets to track, but poorly accurate. I think that what prevents the ga reach a good tracking is the problem coordinates be equals, I think it because I had already explore everything I can to found what can be wrong with ga and I just found this problem.
untitled.png

Abderrahmane DADA
Abderrahmane DADA 2019 年 9 月 15 日
Hello Meisa.
Check the following link: It's a partcile swarm toolbox that is able to handle constrained problem.

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by