Skip to content

Commit

Permalink
Solving problem in contraction happening in some edge cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
josemduarte committed Oct 11, 2017
1 parent 331439c commit 42e3286
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions eppic-cli/src/main/java/eppic/assembly/GraphContractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,13 @@ private UndirectedGraph<V, E> contractInterfaceCluster(
newTrans.add(xtalTransLink);
newEdge.setXtalTrans(newTrans);

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

if (!contGraph.containsVertex(vToKeep) || !contGraph.containsVertex(vToLink)) {
logger.warn("Either vertex to link to {} or vertex to keep {} don't exist in contracted graph."
+ " Edge {} won't be added! Something is wrong!", vToLink, vToKeep, newEdge);
} else {
// the casting should be safe
contGraph.addEdge(vToKeep, vToLink, (E) newEdge);
}
logger.debug("Graph has {} vertices and {} edges", contGraph.vertexSet().size(), contGraph.edgeSet().size());
}

Expand Down Expand Up @@ -451,4 +455,34 @@ private static <V extends ChainVertexInterface, E extends InterfaceEdgeInterface
}
return counts;
}

public static <V extends ChainVertexInterface, E extends InterfaceEdgeInterface> boolean checkInterfClusterIsAutomorphicForEntities(
UndirectedGraph<V, E> g, int interfClusterId) {
int sourceEntityId = -1;
int targetEntityId = -1;
for (E e : g.edgeSet()) {
if (e.getClusterId() == interfClusterId) {
V s = g.getEdgeSource(e);
V t = g.getEdgeTarget(e);
sourceEntityId = s.getEntityId();
targetEntityId = t.getEntityId();
break;
}
}
if (sourceEntityId!=-1) {
if (!GraphUtils.isAutomorphicForEntityAndEdgeType(g, sourceEntityId, interfClusterId)) {
logger.warn("Graph is not automorphic with respect to entity id {} and interface cluster id {}", sourceEntityId, interfClusterId);
return false;
}
}
if (targetEntityId!=-1) {
if (!GraphUtils.isAutomorphicForEntityAndEdgeType(g, targetEntityId, interfClusterId)) {
logger.warn("Graph is not automorphic with respect to entity id {} and interface cluster id {}", targetEntityId, interfClusterId);
return false;
}
}

return true;

}
}

0 comments on commit 42e3286

Please sign in to comment.