I am new to MATLAB and making a project on Path Planning on a 3D environment with PSO. I managed to write my main function as :
clc;
close all;
MaxIt = 100;
noOfPointsInSolution = 1 ;
n=(noOfPointsInSolution + 1) / 2 ;
options = optimoptions('particleswarm', 'MaxIter', MaxIt, 'Plotfcn', @pswplotbestf);
rng default;
[solution, cost] = particleswarm(@PathCostPSO, nVar, zeros(n*4,1),ones(n*4,1), options);
above is a part of my main program. My PathCostPSO function is:
function cost = PathCostPSO(X)
global threat_center threat_radius source goal splineSmoothing cost_arr
lam = 0.5;
path = [source; [X(1:2:end-2)'*500 X(2:2:end-1)'*500 X(3:2:end)'*500]; goal];
cost = lam * getPathLength(path) + (1-lam) * getPenalty(path,threat_center,threat_radius) ;
cost_arr = cat(1,cost_arr,cost/1e+29) ;
Please help if there is some error in implementing the my cost function in the main program for which when the program is run there is no output of Best Function value, rather it is an "inf" value.