private Path pathFind(SimpleVertex sv) {
// Shimon Even - Graph Algorithms - p 181
Path path = new Path(sg);
List lEdges;
List lEdges2;
SimpleEdge anEdge;
SimpleEdge tempEdge;
SimpleVertex aVertex;
// case 1
lEdges = sv.getEdgesRelative(sg);
ListIterator lie = lEdges.listIterator();
while (lie.hasNext()) {
anEdge = (SimpleEdge) lie.next();
if (!anEdge.getBooleanProperty(ISOLD_KEY)
&& anEdge.getBooleanProperty(ISBACKEDGE_KEY)
&& ((anEdge.getAnother(sv)).getIntProperty(DFSNUM_KEY) < sv
.getIntProperty(DFSNUM_KEY))) {
anEdge.setProperty(ISOLD_KEY, Boolean.TRUE);
path.addEdge(anEdge);
return path;
}
}
// case 2
lEdges = sv.getEdgesRelative(sg);
lie = lEdges.listIterator();
while (lie.hasNext()) {
anEdge = (SimpleEdge) lie.next();
if (!anEdge.getBooleanProperty(ISOLD_KEY)
&& !anEdge.getBooleanProperty(ISBACKEDGE_KEY)
&& (anEdge.getAnother(sv)
.getVertexProperty(PARENT_KEY) == sv)
&& (anEdge.getAnother(sv)
.getIntProperty(DFSNUM_KEY) > sv.getIntProperty(DFSNUM_KEY))) {
anEdge.setProperty(ISOLD_KEY, Boolean.TRUE);
path.addEdge(anEdge);
aVertex = anEdge.getAnother(sv);
boolean found;
while (!aVertex.getBooleanProperty(ISOLD_KEY)) {
lEdges2 = aVertex.getEdgesRelative(sg);
found = false;
ListIterator lie2 = lEdges2.listIterator();
while (lie2.hasNext()) {
tempEdge = (SimpleEdge) lie2.next();
if (!tempEdge.getBooleanProperty(ISOLD_KEY)
&& ((tempEdge.getAnother(aVertex)).getIntProperty(DFSNUM_KEY) == aVertex
.getIntProperty(LOWNUM_KEY))) {
aVertex.setProperty(ISOLD_KEY, Boolean.TRUE);
tempEdge.setProperty(ISOLD_KEY, Boolean.TRUE);
path.addEdge(tempEdge);
found = true;
break;
}
}
if (!found) {
lEdges2 = aVertex.getEdgesRelative(sg);
lie2 = lEdges2.listIterator();
while (lie2.hasNext()) {
tempEdge = (SimpleEdge) lie2.next();
if (!tempEdge.getBooleanProperty(ISOLD_KEY)
&& (tempEdge.getAnother(aVertex)
.getVertexProperty(PARENT_KEY) == aVertex)
&& (tempEdge.getAnother(aVertex)
.getIntProperty(LOWNUM_KEY) == aVertex
.getIntProperty(LOWNUM_KEY))) {
aVertex.setProperty(ISOLD_KEY, Boolean.TRUE);
tempEdge.setProperty(ISOLD_KEY, Boolean.TRUE);
path.addEdge(tempEdge);
aVertex = tempEdge.getAnother(aVertex);
break;
}
}
}
}
return path;
}
}
// case 3
lEdges = sv.getEdgesRelative(sg);
lie = lEdges.listIterator();
while (lie.hasNext()) {
anEdge = (SimpleEdge) lie.next();
if (!anEdge.getBooleanProperty(ISOLD_KEY)
&& anEdge.getBooleanProperty(ISBACKEDGE_KEY)
&& (anEdge.getAnother(sv)
.getIntProperty(DFSNUM_KEY) > sv.getIntProperty(DFSNUM_KEY))) {
anEdge.setProperty(ISOLD_KEY, Boolean.TRUE);
path.addEdge(anEdge);
aVertex = anEdge.getAnother(sv);
while (!aVertex.getBooleanProperty(ISOLD_KEY)) {
lEdges2 = aVertex.getEdgesRelative(sg);
ListIterator lie2 = lEdges2.listIterator();
while (lie2.hasNext()) {
tempEdge = (SimpleEdge) lie2.next();
if (!tempEdge.getBooleanProperty(ISOLD_KEY)
&& ((tempEdge.getAnother(aVertex)) == aVertex
.getVertexProperty(PARENT_KEY))) {
aVertex.setProperty(ISOLD_KEY, Boolean.TRUE);
tempEdge.setProperty(ISOLD_KEY, Boolean.TRUE);
path.addEdge(tempEdge);
aVertex = tempEdge.getAnother(aVertex);
break;
}
}
}