Integer highDegreeNodeId = tuple.getLeft();
Integer lowDegreeNodeId = tuple.getMiddle();
//first add all the tuple nodes with the higher degree node in the center, no redundancy
if(!traveledNodesId.contains(highDegreeNodeId)){
traveledNodesId.add(highDegreeNodeId);
DNVNode middlenode = graph.getNode(level, highDegreeNodeId);
//List<DNVNode> neighbors = middlenode.getNeighbors();
//get all the neighbors of the higher degree node which haven't been traveled
ArrayList<DNVNode> neighbors = new ArrayList<DNVNode>();
for(DNVEdge edge : middlenode.getFromEdges()){
if(!traveledNodesId.contains(edge.getToId())){
neighbors.add(graph.getNode(level, edge.getToId()));
}
}
for(DNVEdge edge : middlenode.getToEdges()){
if(!traveledNodesId.contains(edge.getFromId())){
neighbors.add(graph.getNode(level, edge.getFromId()));
}
}
for(int i = 0; i < neighbors.size(); i++){
for(int j = i + 1; j < neighbors.size(); j++){
Integer degree1 = neighbors.get(i).getConnectivity();
Integer degree2 = neighbors.get(j).getConnectivity();
Integer leftNodeId, rightNodeId;
Tuple<Integer, Integer, Integer> degreeTuple;
//for each node tuple, the left node degree should be no smaller than the right one
if(degree1 >= degree2){
leftNodeId = neighbors.get(i).getId();
rightNodeId = neighbors.get(j).getId();
degreeTuple = new Tuple<Integer, Integer, Integer>(degree1, highDegree,degree2);
}else{
leftNodeId = neighbors.get(j).getId();
rightNodeId = neighbors.get(i).getId();
degreeTuple = new Tuple<Integer, Integer, Integer>(degree2, highDegree,degree1);
}
if(!degreeEdgeTableDK3.containsKey(degreeTuple)){
degreeEdgeTableDK3.put(degreeTuple, new ArrayList<Pair<DNVEdge, DNVEdge>>());
degreeOccurTableDK3.put(degreeTuple, 0);
degreeUniqueEdgeTableDK3.put(degreeTuple, new HashSet<DNVEdge>());
degreeUniqueNodeTableDK3.put(degreeTuple, new HashSet<DNVNode>());
}
degreeEdgeTableDK3.get(degreeTuple).add(new Pair<DNVEdge,DNVEdge>(middlenode.getEdgeToNeighbor(leftNodeId),middlenode.getEdgeToNeighbor(rightNodeId)));
degreeOccurTableDK3.put(degreeTuple, degreeOccurTableDK3.get(degreeTuple) + 1);
degreeUniqueEdgeTableDK3.get(degreeTuple).add(middlenode.getEdgeToNeighbor(leftNodeId));
degreeUniqueEdgeTableDK3.get(degreeTuple).add(middlenode.getEdgeToNeighbor(rightNodeId));
degreeUniqueNodeTableDK3.get(degreeTuple).add(middlenode);
degreeUniqueNodeTableDK3.get(degreeTuple).add(neighbors.get(i));
degreeUniqueNodeTableDK3.get(degreeTuple).add(neighbors.get(j));
cnt++;
}
}
}
if(traveledNodesId.contains(lowDegreeNodeId)){
continue;
}
//next get all the tuple nodes with the lower degree node in the center and the higher degree node at one end
DNVNode middlenode = graph.getNode(level, lowDegreeNodeId);
//get all the neighbors of the lower degree node which haven't been traveled
ArrayList<DNVNode> neighbors = new ArrayList<DNVNode>();
for(DNVEdge edge : middlenode.getFromEdges()){
if(!traveledNodesId.contains(edge.getToId())){
neighbors.add(graph.getNode(level, edge.getToId()));
}
}
for(DNVEdge edge : middlenode.getToEdges()){
if(!traveledNodesId.contains(edge.getFromId())){
neighbors.add(graph.getNode(level, edge.getFromId()));
}
}
for(DNVNode neighbor : neighbors){
Integer neighborId = neighbor.getId();
Integer neighborDegree = neighbor.getConnectivity();
//if(neighborDegree <= highDegree){
Tuple<Integer, Integer, Integer> degreeTuple = new Tuple<Integer, Integer, Integer>(highDegree, lowDegree, neighborDegree);
if(!degreeEdgeTableDK3.containsKey(degreeTuple)){
degreeEdgeTableDK3.put(degreeTuple, new ArrayList<Pair<DNVEdge, DNVEdge>>());
degreeOccurTableDK3.put(degreeTuple, 0);
degreeUniqueEdgeTableDK3.put(degreeTuple, new HashSet<DNVEdge>());
degreeUniqueNodeTableDK3.put(degreeTuple, new HashSet<DNVNode>());
}
degreeEdgeTableDK3.get(degreeTuple).add(new Pair<DNVEdge,DNVEdge>(tuple.getRight(),middlenode.getEdgeToNeighbor(neighborId)));
degreeOccurTableDK3.put(degreeTuple, degreeOccurTableDK3.get(degreeTuple) + 1);
degreeUniqueEdgeTableDK3.get(degreeTuple).add(tuple.getRight());
degreeUniqueEdgeTableDK3.get(degreeTuple).add(middlenode.getEdgeToNeighbor(neighborId));
degreeUniqueNodeTableDK3.get(degreeTuple).add(middlenode);
degreeUniqueNodeTableDK3.get(degreeTuple).add(graph.getNode(level, highDegreeNodeId));
degreeUniqueNodeTableDK3.get(degreeTuple).add(neighbor);
cnt++;
}