/** * @param job Calculates each partition weight based on the undirected graph for comparison. If * static partitioning is applied then skipping will be applied here. */ public static void initializePartitionsWeight() { ArrayList<String> neighbours; long pw = 0, me, other; for (int i = 0; i < partitionsNames.size(); i++) { String currentPartition = partitionsNames.get(i); me = partitionsSizes.get(currentPartition); neighbours = new ArrayList<String>(); pw = me * me; for (int j = 0; j < partitionsNames.size(); j++) { other = partitionsSizes.get(partitionsNames.get(j)); if (currentPartition.startsWith("G")) { String otherPartition = partitionsNames.get(j); int myRow = Reader.getRow(currentPartition); int myCol = Reader.getCol(currentPartition); int otherRow = Reader.getRow(otherPartition); int otherCol = Reader.getCol(otherPartition); if ((((myRow != myCol) && (myCol >= otherRow)) || ((otherRow != otherCol) && (otherCol >= myRow))) // new || otherPartition.equals(currentPartition)) continue; // verified } neighbours.add(partitionsNames.get(j)); pw += me * other; } partitionsWeights.put(currentPartition, pw); undirectedGraph.put(currentPartition, neighbours); } }
public static void printCircularPartitionsWeight(String stage) { long pw = 0, me, other, nPart = partitionsNames.size(); long combin = (nPart * (nPart - 1) / 2); System.out.println(stage + " partition weights:"); for (int i = 0; i < nPart; i++) { String currentPartition = partitionsNames.get(i); System.out.print(currentPartition + ": "); int myRow = Reader.getRow(currentPartition); int myCol = Reader.getCol(currentPartition); int mapId = i; me = partitionsSizes.get(currentPartition); pw = me * me; for (int j = mapId + 1; j <= mapId + (combin / nPart); j++) { String otherPartition = partitionsNames.get((int) (j % nPart)); int otherRow = Reader.getRow(otherPartition); int otherCol = Reader.getCol(otherPartition); if ((((myRow != myCol) && (myCol >= otherRow)) || ((otherRow != otherCol) && (otherCol >= myRow))) || otherPartition.equals(currentPartition)) continue; other = partitionsSizes.get(partitionsNames.get((int) (j % nPart))); pw += (me * other); } if (mapId < (combin % nPart)) { String otherPartition = partitionsNames.get((int) ((mapId + (combin / nPart) + 1) % nPart)); int otherRow = Reader.getRow(otherPartition); int otherCol = Reader.getCol(otherPartition); if (!((((myRow != myCol) && (myCol >= otherRow)) || ((otherRow != otherCol) && (otherCol >= myRow))) || otherPartition.equals(currentPartition))) { other = partitionsSizes.get( partitionsNames.get((int) ((mapId + (combin / nPart) + 1) % nPart))); // buggy? pw += (me * other); } } System.out.println(pw); partitionsCircularWeights.put(currentPartition, pw); } }