I found a solution myself.
My problem has the additional constraint that I only want to check whether there is more than one path only for two nodes that are directly connected with and edge. This means that by simply computing the shortest path you will always get this single edge as path.
So, my question can be reformulated as:
Is there another path connecting the two nodes of an edge, aside from the edge itself?
The solution is to use a weighted shortest path. If we assign a very high weight to our edge of interest, and weight 1
to all the others, then if the minimal distance is lower than our high weight, the answer is YES, otherwise NO.
Here is the code:
public static boolean areThereMultiplePaths(final Edge edge, DirectedGraph<Entity, Edge> graph) {
Transformer<Edge, Integer> transformer = new Transformer<Edge, Integer>() {
public Integer transform(Edge otherEdge) {
if (otherEdge.equals(edge))
return Integer.MAX_VALUE;
else
return 1;
}
};
DijkstraShortestPath<Entity, Edge> algorithm = new DijkstraShortestPath<Entity, Edge>(graph, transformer);
Double distance = (Double) algorithm.getDistance(edge.getStartNode(), edge.getEndNode());
return distance < Integer.MAX_VALUE;
}