Set<InputNode> nodesA = new HashSet<InputNode>(a.getNodes());
Set<InputNode> nodesB = new HashSet<InputNode>(b.getNodes());
Map<InputNode, InputNode> inputNodeMap = new HashMap<InputNode, InputNode>();
for (Pair p : pairs) {
InputNode n = p.getN1();
assert nodesA.contains(n);
InputNode nB = p.getN2();
assert nodesB.contains(nB);
nodesA.remove(n);
nodesB.remove(nB);
InputNode n2 = new InputNode(n);
inputNodeMap.put(n, n2);
inputNodeMap.put(nB, n2);
graph.addNode(n2);
markAsChanged(n2, n, nB);
}
for (InputNode n : nodesA) {
InputNode n2 = new InputNode(n);
graph.addNode(n2);
markAsNew(n2);
inputNodeMap.put(n, n2);
}
for (InputNode n : nodesB) {
InputNode n2 = new InputNode(n);
n2.setId(-n2.getId());
graph.addNode(n2);
markAsDeleted(n2);
inputNodeMap.put(n, n2);
}
Collection<InputEdge> edgesA = a.getEdges();
Collection<InputEdge> edgesB = b.getEdges();
Set<InputEdge> newEdges = new HashSet<InputEdge>();
for (InputEdge e : edgesA) {
int from = e.getFrom();
int to = e.getTo();
InputNode nodeFrom = inputNodeMap.get(a.getNode(from));
InputNode nodeTo = inputNodeMap.get(a.getNode(to));
char index = e.getToIndex();
InputEdge newEdge = new InputEdge(index, nodeFrom.getId(), nodeTo.getId());
if (!newEdges.contains(newEdge)) {
markAsNew(newEdge);
newEdges.add(newEdge);
graph.addEdge(newEdge);
}
}
for (InputEdge e : edgesB) {
int from = e.getFrom();
int to = e.getTo();
InputNode nodeFrom = inputNodeMap.get(b.getNode(from));
InputNode nodeTo = inputNodeMap.get(b.getNode(to));
char index = e.getToIndex();
InputEdge newEdge = new InputEdge(index, nodeFrom.getId(), nodeTo.getId());
if (!newEdges.contains(newEdge)) {
markAsDeleted(newEdge);
newEdges.add(newEdge);
graph.addEdge(newEdge);
} else {