This function performs a MultiObjective Particle Swarm Optimization (MOPSO) for minimizing continuous functions. The implementation is bearable, computationally cheap, and compressed (the algorithm only requires one file: MPSO.m). An 'example.m' script is provided in order to help users to use the implementation. It is also noteworthy to mention that the code is highly commented for easing the understanding. This implementation is based on the paper of Coello et al. (2004), "Handling multiple objectives with particle swarm optimization".
IMPORTANT: the objetive function that you specify must be vectorized. This means that it will take the entire population (i.e., a matrix Np x nVar, which Np is the number of particles and nVar is the number of variables) and it expects to receive a fitness value for each particle (i.e., a vector Np x 1). If the function is not vectoriyed and receives only a single value, the code will obviously rise an error.
Víctor MartínezCagigal (2019). MultiObjective Particle Swarm Optimization (MOPSO) (https://www.mathworks.com/matlabcentral/fileexchange/62074multiobjectiveparticleswarmoptimizationmopso), MATLAB Central File Exchange. Retrieved .
1.3.2.0  Now the function raises a warning if the objective function is badly programmed, which is usually the issue that is reported in some comments. 

1.3.1.0  ParetoFront folder is now uploaded 

1.3.0.0  Function is modified in order to return the data form the repository 

1.3.0.0  Optimal Pareto Fronts are updated. 

1.2.0.0  More benchmark functions and optimal Pareto Fronts are implemented 

1.1.0.0  Mutation operator and crowding factor for repository removing are applied. 
Create scripts with code, output, and formatted text in a single executable document.
T Kalog (view profile)
Víctor MartínezCagigal (view profile)
@sim_892 MATLAB is now complaining because you cannot do bitwise operations (with the point .) if the size of the matrices are not the same... So I guess your objective function is not properly definet yet.
Anyway, you can write your objective function in a file if it suits better to you. For example, a file named myFunction, which declares a function out = myFunction(x) that takes the matrix "x" and returns a vector "out". Then the objective function could be called like this: @(x) myFunction(x);
sim_892 (view profile)
Thank you @Víctor MartínezCagigal, now I understand, but my problem remains, unfortunately. I specified all my variables of the objective function in the correct form: x(:,1), x(:,2), x(:,3) etc.. I also use everywhere the . opertator as you explained but now I get the following error:
Matrix dimensions must agree.
Error in example>@(x)1i.*w.*C2_25(x)+G3_25(x)
Error in example>@(x)(Y_qw_25(x).*Y_ser_25(x))./(Y_qw_25(x)+Y_ser_25(x))
Error in example>@(x)Y_1_25(x)+1i.*w.*C1_25(x)+G1_25(x)
Error in example>@(x)(Y_tb_rtd_25(x).*(1./(1i.*w.*x(:,11))))./(Y_tb_rtd_25(x)+(1./(1i.*w.*x(:,11))))
Error in example>@(x)Y_1p_25(x)+1i.*w.*x(:,12)
Error in example>@(x)((1./Y_tot_25(x))50)./((1./Y_tot_25(x))+50)
Error in example>@(x)sum((abs(real(S11(:,25))real(S_tot_25(x)))+abs(imag(S11(:,25))imag(S_tot_25(x)))).^2)
Error in example>@(x)[f1(x),f2(x)]
As you can see I need some functions of functions to specify my objective function since otherwise its too big to write in a single expression. But I think that the real problem is my final objective function is now a single value but rather an array (a function vs frequency points), and I guess that the vector of the frequency w as I use in my objective functions, somehow messes up with your definition of the variables x(:,1), x(:,2), x(:,3)
Víctor MartínezCagigal (view profile)
@sim_892 As stated in the comments, my objective function performs a vectorized approach to evaluate all the particles at once and return a fitness for each one. Therefore, as the input must be the population (matrix of n_particles x n_variables), x(:,1) just takes the first variable of all the particles at once.
Regarding your second issue, you are not using array operations (.^, .*, ./, etc) and thus MATLAB complains about it. This is a very basic concept of MATLAB, so I suggest you to take some courses or tutorials (https://www.mathworks.com/help/matlab/matlab_prog/arrayvsmatrixoperations.html).
sim_892 (view profile)
If I use your formatting (from examples) for the Objective function I get the following error:
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers,
use '.^'.
sim_892 (view profile)
Hi, I don't understand how to properly program the objective functions and I am pretty new with Matlab: In my previous implementations of PSO I would simply express the variables of my objective functions in the form of x(1), x(2), x(3), ..... but you express those variables sometimes in form x(:,1) some others just x. Can you give an example in which the Objective functions are expressed in function of single element variables (x(1), x(2),... etc) ?
Thank you
Saiara Samira Sajid (view profile)
Víctor MartínezCagigal (view profile)
So, for those that have the problem in nchoosek. The error says that you are taking <2 particles when updating the repository. This is usually because you have specified a badly programmed objective function.
The objetive function that you specify must be vectorized. This means that it will take the entire population (i.e., a matrix Np x nVar, which Np is the number of particles and nVar is the number of variables) and it expects to receive a fitness value for each particle (i.e., a vector Np x 1). If the function is not vectoriyed and receives only a single value, the code will obviously rise an error.
Saiara Samira Sajid (view profile)
Hello,
Thanks a lot for the code . However, I am facing the same problem as Srinivas Kolluru.
My objective Function contains for loop. So I am not sure how to solve it.
Error using nchoosek (line 65)
K must be an integer between 0 and N.
Error in MOPSO>checkDomination (line 179)
all_perm = nchoosek(1:Np,2); % Possible permutations
Error in MOPSO (line 23)
DOMINATED= checkDomination(POS_fit);%this is causing problem
Error in Flowshop (line 20)
REP = MOPSO(params,MultiObj);
Wagner Saldanha (view profile)
Thank you!
I can't use functions with if conditions, would it be possible to use if in function handle?
Sharifah Zarith Rahmah Bt Syed Ahmad (view profile)
Hey i am very new with matlab , how to start using the tool box ?
yujin (view profile)
tianqing liu (view profile)
xiaofu zhang (view profile)
Thank you for this very nice code.
But when i run the 'example.m' ,it has the error as follow.Could you give me some advice?
Error using load
Unable to read file 'ParetoFronts/Kursawe.mat'. There are no such files or directories.
Xiancai Wei (view profile)
Parmod Yadav (view profile)
Sir in single objective 'artificial bee colony optimization' we calculate fitness using the formula fit_i=1/1+f_i, where f_i is the cost function value. Could you please tell me how can we calculate fitness in multi objective artificial bee colony optimization.
Fodhil Fadhila (view profile)
Thank you for this very nice code
Víctor MartínezCagigal (view profile)
Hi Nima,
Just refer to the example of Kursake function. As can be noticed, the function has 3 variables (nVar parameter). The limits are defined in var_min and var_max as vectors which, in that case, are [5 5 5] and [5 5 5], respectively. You should define your limits in that way.
nima rezaee (view profile)
firs of all awesome code and algorithm. thank you.
but unfortunately i have the same problem as RAVI MANDAVA. i want to have different varmin and varmax for each variable in mopso.
i can change the code but im not sure it will work. i dont know maybe im missing something.
can someone please help me .
thanks in advance.
shdotcom shdotcom (view profile)
Great work，Thank you very much
Víctor MartínezCagigal (view profile)
Dear Srinivas Kolluru,
since your error is returned from a function called "MOPSO_new", I suppose that the problem lies in your own version of the algorithm. Send me an email and perhaps I can help you.
Regards.
Srinivas Kolluru (view profile)
Hello Martinez,
Thank you for the code. But when i run the code, i am facing a similar error reported earlier by Devin.
The number of particles = 200;
Error using nchoosek (line 65)
K must be an integer between 0 and N.
Error in MOPSO_new>checkDomination (line 226)
all_perm = nchoosek(1:Np,2); % Possible permutations
Error in MOPSO_new (line 67)
DOMINATED= checkDomination(POS_fit);
Can you help me with this please
Yuyang Wang (view profile)
Works and easy to understand and modify.
Xu Shuhui (view profile)
great work，Thank you very much
jogo (view profile)
as expected it outperforms the gamultiobj from Matlab
I can´t understand why they have a single PSO and not a MOPSO ....
Thanks for this nice code!
Víctor MartínezCagigal (view profile)
@zkl, Actually, the code plots the current generation positions in red, and the Pareto Front particles in black. Thus, the Pareto Front are only the black points.
Víctor MartínezCagigal (view profile)
@Ali Chamseddine, Indeed, constraints are not implemented here, since it is a "simple" example. In order to add them, you will need to create a feasibility function that check, in each generation, if the particles positions are feasible taking into account the given constraints. In case that some of they were not, you should modify their positions.
zkl (view profile)
hi, thank you for sharing. i want to ask a question. why not all the Particles are at the pareto front when i run your example? Is it correct when most of them are at the front while a little of them are not.
Ali Chamseddine (view profile)
Thank you for sharing it! However I would like to ask about setting up constraints, I haven't found any constraints implemented in any of the examples! Any tips on how to do that would be greatly appreciated, thanks again!
Ali
Andrés F. Abril (view profile)
Zenith Zhou (view profile)
Great！thx for sharing.I'm now studying MOPSO and do meet some trouble in coding...
milan joshi (view profile)
how do i test new function ...I am very new to MATLAB...any help would be highly appreciated. I dont know how to check MOPSO for new function...
haifeng lu (view profile)
hao Liu (view profile)
Víctor MartínezCagigal (view profile)
@bulin wen, Thank you for your feedback. The references are indicated in comments inside the MOPSO.m function. Mainly, I based my algorithm in:
[1] Coello, C. A. C., Pulido, G. T., & Lechuga, M. S. (2004). Handling multiple objectives with particle swarm optimization. IEEE Transactions on evolutionary computation, 8(3), 256279.
[2] Sierra, M. R., & Coello, C. A. C. (2005, March). Improving PSObased multiobjective optimization using crowding, mutation and edominance. In International Conference on Evolutionary MultiCriterion Optimization (pp. 505519). Springer Berlin Heidelberg.
@Mengying Zhang, Thank you for the feedback. There wasn't rationale for not including the ZDT4 problem, perhaps I didn't found the equations when I wrote the code. However, it is easy to implement, feel free to add it ;)
bulin wen (view profile)
thank you very much! It's very useful.And could you tell me what the references you have used?
Mengying Zhang (view profile)
Thank you for uploading this code. Yet I found that you excluded ZDT4 test problem in this code. Have you ever tested ZDT4 with it ?
Mehmet Gulec (view profile)
Great job.
Víctor MartínezCagigal (view profile)
Edit: The error says that "K must be an integer between 0 and N". Since K is 2, it indicates that Np is 1 or 0. In other words, the number of particles that you have specified is less than 2 and thus, MOPSO cannot run.
Víctor MartínezCagigal (view profile)
Hi Devin,
I have tested the algorithm again with the 5 functions that I provide in the "example.m" script and it does not throw any error. Probably, the MultiObj function that you are using is not correct. Can you provide me more information about your run?
Despite that, although I do not believe that this is the cause of the problem, what version of MATLAB are you using? In my case, I tested the algorithm with versions greater than 2015a.
Regards,
Víctor.
Devin (view profile)
Error using nchoosek (line 65)
K must be an integer between 0 and N.
Error in MOPSO>checkDomination (line 218)
all_perm = nchoosek(1:Np,2); % Possible permutations
Error in MOPSO (line 67)
DOMINATED= checkDomination(POS_fit);
Error in example (line 76)
MOPSO(params,MultiObj);