Skip to content

Commit

Permalink
A fix for #196
Browse files Browse the repository at this point in the history
  • Loading branch information
josemduarte committed Oct 7, 2017
1 parent 0fad8d6 commit 331439c
Showing 1 changed file with 55 additions and 48 deletions.
103 changes: 55 additions & 48 deletions eppic-cli/src/main/java/eppic/assembly/GraphContractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,64 +119,71 @@ private UndirectedGraph<V, E> contractInterfaceCluster(
logger.debug("Graph has {} vertices and {} edges, before add edges loop", contGraph.vertexSet().size(), contGraph.edgeSet().size());
}

// we need to add to vToKeep all edges that were connecting vToRemove to any other vertex
for (E eToAdd : contGraph.edgesOf(vToRemove)) {
// In some cases (e.g. 1kbu, 5xnl), the vToRemove doesn't exist in contGraph. That's because we are getting
// vToRemove from the inputGraph whilst contGraph might already have no such vertex at this point in the removal process.
// This check avoids the IllegalArgumentException that would happen otherwise, see issue #196
if (!contGraph.containsVertex(vToRemove)) {
logger.info("The vertex to be removed {} does not exist in contracted graph", vToRemove.toString());
} else {
// we need to add to vToKeep all edges that were connecting vToRemove to any other vertex
for (E eToAdd : contGraph.edgesOf(vToRemove)) {

if (eToAdd == e) {
//Don't add the joining edges as a self-edge
continue;
}

if (eToAdd == e) {
//Don't add the joining edges as a self-edge
continue;
}
// extract similar info from eToAdd with the convention ( vToRemove -> vToLink )
V vToLink;
Point3i xtalTransLink;

// extract similar info from eToAdd with the convention ( vToRemove -> vToLink )
V vToLink;
Point3i xtalTransLink;

{ // local variable scope
V s = contGraph.getEdgeSource(eToAdd);
V t = contGraph.getEdgeTarget(eToAdd);

xtalTransLink = eToAdd.getXtalTrans();

if (vToRemove.equals(s)) {
vToLink = t;
} else {
assert vToRemove.equals(t); // should be one or the other
vToLink = s;
// preserve direction convention
xtalTransLink.negate();
}
{ // local variable scope
V s = contGraph.getEdgeSource(eToAdd);
V t = contGraph.getEdgeTarget(eToAdd);

if(vToLink == vToKeep) {
//Don't add the joining edges as a self-edge
continue;
xtalTransLink = eToAdd.getXtalTrans();

if (vToRemove.equals(s)) {
vToLink = t;
} else {
assert vToRemove.equals(t); // should be one or the other
vToLink = s;
// preserve direction convention
xtalTransLink.negate();
}

if(vToLink == vToKeep) {
//Don't add the joining edges as a self-edge
continue;
}
// Now we have all the info to make a new edge ( vToKeep -> vToLink )
logger.debug("Adding edge {} between {} -> {}. Before it was {}->{}",
eToAdd.toString(), vToKeep.toString(), vToLink.toString(), s.toString(), t.toString());
}
// Now we have all the info to make a new edge ( vToKeep -> vToLink )
logger.debug("Adding edge {} between {} -> {}. Before it was {}->{}",
eToAdd.toString(), vToKeep.toString(), vToLink.toString(), s.toString(), t.toString());
}

// we create a new edge so that we can keep the original edges from the original graph intact
InterfaceEdge newEdge = new InterfaceEdge();
// we create a new edge so that we can keep the original edges from the original graph intact
InterfaceEdge newEdge = new InterfaceEdge();

newEdge.setInterfaceId(eToAdd.getInterfaceId());
newEdge.setClusterId(eToAdd.getClusterId());
//TODO It can be that two non-infinite edges together are infinite. Does that matter here? -SB
newEdge.setIsInfinite(eToAdd.isInfinite() || e.isInfinite());
newEdge.setIsIsologous(eToAdd.isIsologous() || e.isIsologous());
newEdge.setInterfaceId(eToAdd.getInterfaceId());
newEdge.setClusterId(eToAdd.getClusterId());
//TODO It can be that two non-infinite edges together are infinite. Does that matter here? -SB
newEdge.setIsInfinite(eToAdd.isInfinite() || e.isInfinite());
newEdge.setIsIsologous(eToAdd.isIsologous() || e.isIsologous());

// xtalTrans should have already been negated if necessary
Point3i newTrans = new Point3i(xtalTrans);
newTrans.add(xtalTransLink);
newEdge.setXtalTrans(newTrans);
// xtalTrans should have already been negated if necessary
Point3i newTrans = new Point3i(xtalTrans);
newTrans.add(xtalTransLink);
newEdge.setXtalTrans(newTrans);

// the casting should be safe
contGraph.addEdge(vToKeep, vToLink, (E) newEdge);
// the casting should be safe
contGraph.addEdge(vToKeep, vToLink, (E) newEdge);

logger.debug("Graph has {} vertices and {} edges", contGraph.vertexSet().size(), contGraph.edgeSet().size());
}
logger.debug("Graph has {} vertices and {} edges", contGraph.vertexSet().size(), contGraph.edgeSet().size());
}

// Remove the vertex!
contGraph.removeVertex(vToRemove);
// Remove the vertex!
contGraph.removeVertex(vToRemove);
}
contractedVertices.put(vToRemove,vToKeep);
}

Expand Down

0 comments on commit 331439c

Please sign in to comment.