Using optimization algorithms to find minimum path with obstacles
Show older comments
Hello
I'm trying to optimize the path in the figure trying to avoid that the resulting path passes through obstacles. The approach I'm using is to use an optimization algorithm (fminunc) that improves the cost function (this computes the total path length with the Euclidean distances between each point) while keeping the start and end points fixed. The algorithm varies the coordinates of the green points and I insert as the starting point x0 the matrix containing the green points.

Not knowing how to model each obstacle (all cubes of which I have the 8 extremes) as a constraint to avoid, I added to the cost function a function that adds a cost as a penalty if there are points inside the obstacles. However I always get the same result:

Does anyone know if there is a better method to get the desired result? Or even if it knows how to model obstacles as constraints? Then using the function fmincon.
This is the path I hope to obtain:

Accepted Answer
More Answers (1)
It's doubtful you can do it with fmincon, but you might be able to do it by creating a graph object to model steps between allowable locations. You could then use shortestpath to solve the problem. The code below would just need a simple modification to delete the nodes from the graph were obstacles are located.
N=20; %Represent the field as NxN grid of points
[X,Y]=ndgrid(1:N); XY=[X(:),Y(:)]; M=numel(X);
I=repmat(1:M,9,1);
[D,J]=pdist2(XY,XY,'euclidean','Smallest',9);
idx=(D>=sqrt(2)+10*eps);
D(idx)=0;
A=sparse(I,J,D,M,M);
G=graph(A,'omitself'); %Non-directed graph of the grid lattice
plot(G,'XData',X(:),'YData',Y(:))
1 Comment
Andrea Di Mauro
on 4 Dec 2022
Categories
Find more on Solver Outputs and Iterative Display 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!