/* * find the new appeared neighbors by comparing the current neighbor with the history */ public static Vector findNewNeighbor(int pos) { Vector result = new Vector(); Vector cur = (Vector) neighborCurrent.get(pos); Vector his = (Vector) neighborHistory.get(pos); if (his == null || his.size() == 0) return cur; for (int i = 0; i < cur.size(); i++) { if (!his.contains(cur.get(i))) { result.add(cur.get(i)); } } return result; }
/* * deep copy from current neighbors to history neighbors */ public static void currentToHistory() { // neighborHistory = neighborCurrent; for (int i = 0; i < size; i++) { Vector currN = (Vector) neighborCurrent.get(i); Vector histN = new Vector(); for (int j = 0; j < currN.size(); j++) { int temp = (Integer) currN.get(j); histN.add(temp); } neighborHistory.set(i, histN); } }
/* * update neighborCurrent, based on the knowledge of the nodes */ public static void updateCurrentNeighbor() { for (int i = 0; i < size; i++) { // add the neighbors for the ith node Vector nb = new Vector(); for (int j = 0; j < size; j++) { if (i == j) continue; Location li = ((RouteGPSR) nodes.get(i)).getCurrentLocation(); Location lj = ((RouteGPSR) nodes.get(j)).getCurrentLocation(); if (distance(li, lj) < JistExperiment.market_radius) { nb.add(j); } } neighborCurrent.set(i, nb); } }