I have a findAllPaths() function to find all possible paths in a graph (stored in matrix):
public void findAllPaths(final Matrix matrix, final Index s, final Index d, HashMap <Index , Boolean> isVisited, Collection localPathList)
{
// Mark the current node
isVisited.put(s, true);
if (s.equals(d)) {
this.pathsList.add(new ArrayList<>(localPathList));
// if match found no need to traverse more till depth
isVisited.put(s, false);
return;
}
// Recur for all the vertices neighbors to current index
for (Index i : matrix.getNeighbors(s)) {
if (!isVisited.get(i)) {
// store current node in path[]
localPathList.add(i);
findAllPaths(matrix, i, d, isVisited, localPathList);
// remove current node in path[]
localPathList.remove(i);
}
}
// Mark the current node
isVisited.put(s, false);
}
I'm trying to make it run in parallel as much as possible.
Does anybody have an idea of how I can accomplish that?