I am trying to implement a shortest path algorithm into my code, but I am at a loss on how to do it. Suppose you had a matrix that contained the (x,y) coordinates of several line segments. Suppose that each line segment had a score associated with it, and the score indicates how "valuable" that line segment is to a design.
If this information was put into a matrix the rows could be formatted as follows:
Start X, Start Y, End X, End Y, Score
Now, suppose that there is no connectivity information provided in the above matrix, i.e. you do not know the relation of 1 line to another based on the matrix. Based on the matrix above, I want to find the element path the produces the highest score (in my program it is the lowest score, but this is semantics). The catch, however, is that each path must be continuous with no jumps between connecting line segments. Does anyone know how to code this? I have a segment of my code below where the score of each element is calculated and stored (in the matrix ElementMap), but I don't know how to form the optimal path once I have ElementMap.
Thanks
for i = 1:Count2
for j = 1:length(ElementMap)
xStart = ElementMap(j,1);
yStart = ElementMap(j,2);
xEnd = ElementMap(j,3);
yEnd = ElementMap(j,4);
Score = 0;
if NodeMap(2*(i-1)+1) == ElementMap(j,1) && ElementMap(j,5) ~= 1
for m = 1:length(ThetaIncident)
[Point] = RayScore(xStart,yStart,xEnd,yEnd,ThetaIncident(m),OvenGlassXrange);
Score = Score - Point;
end
ElementMap(j,5) = 1; % 1 will indicate Element has been analyzed
end
ElementMap(j,6) = ElementMap(j,6) + Score;
end
end
(x,y). Each unique coordinate is a vertex. Each row of your data is an edge. Does that make sense?