I am given a $N$ x $M$ sized grid and $K$ start points $S = (s_1, s_2, .. s_k)$ where each $s_k = (x_k,y_k)$ representing the position on the grid. I am also given a single endpoint $(x_{end}, y_{end})$. Some cells of the grid contain obstacles which are undesirable to pass through.
Given that we have a routine getPaths(x_k, y_k)
to compute all paths from each $(x_k,y_k)$ to $(x_{end}, y_{end})$, I need to choose a path for each $(x_k, y_k)$ to $(x_{end}, y_{end})$ such that the total number of obstacles encountered along the union of paths is minimised.
I was thinking if the following greedy algorithm would give an optimal answer. The psuedo steps are as follows:
U = {}
allPaths = flatten([getPaths(x_i, y_i) for all i = 1, ... k])
obstacleSet = set()
while U does not contain all k paths
// best path that when merged with obstacle Set returns the least number of obstacles
[bestPath, obstacleSet] = findBestPath(allPaths, obstacleSet)
// filter from allPaths paths which contain the source of `bestPath`
allPaths = filter(allPaths, bestPath.source)
// add best path to U
U.add(bestPath)
end
Would greedy algorithm be able to give an optimal solution in this scenario ?