📄 statistics.java
字号:
} done++; IndexPair idx = new IndexPair(i, j); double[] linkStatusChanges = MobileNode.pairStatistics( node[i], node[j], 0.0, duration, radius, calculateMobility); if (calculateMobility) mobility += linkStatusChanges[0]; for (int l = 1; l < linkStatusChanges.length; l++) sched.add(idx, linkStatusChanges[l]); if ((linkStatusChanges.length & 1) == 0) // explicitely add "disconnect" at the end sched.add(idx, duration); } } System.out.println(); return mobility; } /** Helper function for overall(), merge two partitions. */ protected static void pmerge(int[] idx, int[] size, int i, int j) { int old = idx[j]; for (int k = 0; k < idx.length; k++) if (idx[k] == old) idx[k] = idx[i]; size[idx[i]] += size[old]; size[old] = 0; } /** Calculate statistics averaged over the whole simulation time. */ public static void overall(Scenario s, double[] radius, String basename) throws FileNotFoundException { MobileNode[] node = s.getNode(); double duration = s.getDuration(); double[][] ls = null; PrintWriter stats = new PrintWriter(new FileOutputStream(basename + ".stats")); int tEdges = (node.length * (node.length - 1)) / 2; double normFact = (double) tEdges * duration; Heap heap = null; int[] pIdx = null; // partition index int[] pSize = null; // partition sizes boolean[] isolation = null; ls = new double[node.length - 1][]; for (int i = 0; i < ls.length; i++) ls[i] = new double[node.length - i - 1]; heap = new Heap(); pIdx = new int[node.length]; // partition index pSize = new int[node.length]; // partition sizes isolation = new boolean[node.length]; for (int k = 0; k < radius.length; k++) { System.out.println("transmission range=" + radius[k]); int partitions = node.length; int partitionsOld = node.length; double pSince = 0.0; double avgPart = 0.0; double partDeg = 1.0; double partDegOld = 1.0; double pdSince = 0.0; double avgPartDeg = 0.0; int linkbreaks = 0; double timeToLinkBreak = 0.0; int links = 0; double linkDuration = 0.0; double mobility = 0.0; int connections = 0; Vector linkDurations = new Vector();// System.out.println("scheduling..."); for (int i = 0; i < node.length; i++) { pIdx[i] = i; pSize[i] = 1; isolation[i] = true; for (int j = i + 1; j < node.length; j++) ls[i][j - i - 1] = -1.0; } mobility = schedule(s, heap, radius[k], (k == 0)); if (k == 0) { stats.println("# mobility=" + (mobility / normFact)); stats.println( "# \"tx range\" \"avg. degree\" \"partitions\" \"partitioning degree\" \"avg time to link break\" \"std deviation of time to link break\" \"link breaks\" \"avg link duration\" \"total links\""); }// System.out.println("calculating..."); double tOld = 0.0; int progress = -1; int done = 0; while (heap.size() > 0) { int nProg = (int)(100.0 * (double)done / (double)(heap.size() + done) + 0.5); if (nProg > progress) { progress = nProg; System.out.print("calculating... " + progress + "% done.\r"); } done++; double tNew = heap.minLevel();// System.out.println("tNew=" + tNew + " tOld=" + tOld); IndexPair idx = (IndexPair) heap.deleteMin(); // uncomment the following code piece to print messages about nodes becoming isolated (meaning they have no links at all) and leaving their isolation again: /* if (tNew > tOld) for (int i = 0; i < pSize.length; i++) { if ((pSize[i] == 1) && ((! isolation[i]) || (tOld == 0.0))) { isolation[i] = true; System.out.println("isolation " + i + " at " + tOld); // check if this is working correctly for (int j = 0; j < node.length; j++) if (i < j) { if (ls[i][j - i - 1] >= 0.0) System.out.println("! " + j); } else if (i > j) { if (ls[j][i - j - 1] >= 0.0) System.out.println("! " + j); } } else if (isolation[i] && (pSize[i] != 1)) { isolation[i] = false; if (tOld > 0.0) System.out.println("de-isolation " + i + " at " + tOld); } } */ if (((tNew > tOld) && (partitions != partitionsOld)) || (heap.size() == 0)) { if (heap.size() != 0) { avgPart += (double)partitionsOld * (tOld - pSince);// System.out.println("#1: avgPart += " + partitionsOld + " * (" + tOld + " - " + pSince + ")"); } else { avgPart += (double)partitions * (tNew - pSince);// System.out.println("#2: avgPart += " + partitions + " * (" + tNew + " - " + pSince + ")"); } partitionsOld = partitions; pSince = tOld; } if (((tNew > tOld) && (partDeg != partDegOld)) || (heap.size() == 0)) { if (heap.size() != 0) { avgPartDeg += partDegOld * (tOld - pdSince);// System.out.println("#1: avgPartDeg += " + partDegOld + " * (" + tOld + " - " + pdSince + ")"); } else { avgPartDeg += partDeg * (tNew - pdSince);// System.out.println("#2: avgPartDeg += " + partDeg + " * (" + tNew + " - " + pdSince + ")"); } partDegOld = partDeg; pdSince = tOld; } if (ls[idx.i][idx.j - idx.i - 1] < 0.0) { // connect connections++; ls[idx.i][idx.j - idx.i - 1] = tNew; if (pIdx[idx.i] != pIdx[idx.j]) { partitions--; pmerge(pIdx, pSize, idx.i, idx.j); } } else { // disconnect connections--; double tUp = ls[idx.i][idx.j - idx.i - 1]; double tConn = tNew - tUp; ls[idx.i][idx.j - idx.i - 1] = -1.0; linkDuration += tConn; links++; if ((tNew < duration) && (tUp > 0.0)) { linkDurations.addElement(new Double(tConn)); timeToLinkBreak += tConn; linkbreaks++; // rebuild pIdx if (partitions == 1) { partitions = node.length; for (int i = 0; i < node.length; i++) { pIdx[i] = i; pSize[i] = 1; } } else { int split = pIdx[idx.i]; for (int i = 0; i < node.length; i++) if (pIdx[i] == split) { partitions++; pIdx[i] = i; pSize[i] = 1; } partitions--; } for (int i = 0; i < ls.length; i++) for (int j = i + 1; j < node.length; j++) if ((pIdx[i] != pIdx[j]) && (ls[i][j - i - 1] >= 0.0)) { partitions--; pmerge(pIdx, pSize, i, j); } } } partDeg = 0.0; for (int i = 0; i < pSize.length; i++) if (pSize[i] > 0) partDeg += (double)(pSize[i] * (node.length - pSize[i])); tOld = tNew; } System.out.println(); double expDuration = timeToLinkBreak / (double) linkbreaks; double varDuration = 0.0; for (int i = 0; i < linkbreaks; i++) { double tmp = ((Double) linkDurations.elementAt(i)).doubleValue() - expDuration; varDuration += tmp * tmp; } varDuration = Math.sqrt(varDuration / (double) (linkbreaks - 1)); stats.println( radius[k] + " " + (linkDuration * (double)node.length / normFact) + " " + (avgPart / duration) + " " + (avgPartDeg / (duration * (double)((node.length - 1) * node.length))) + " " + expDuration + " " + varDuration + " " + linkbreaks + " " + (linkDuration / (double) links) + " " + links); } stats.close(); } protected boolean parseArg(char key, String val) { switch (key) { case 'f' : name = val; return true; case 'r' : // radius radius = App.parseDoubleArray(val); return true; case 't' : printTime = true; return true; case 'G' : flags = flags ^ STATS_PARTDEG; if (val.length()!=0) secG = Double.parseDouble(val); return true; case 'M' : // MinCut flags = flags ^ STATS_MINCUT; if (val.length()!=0) secM = Double.parseDouble(val); return true; case 'N' : flags = flags ^ STATS_NODEDEG; if (val.length()!=0) secN = Double.parseDouble(val); return true; case 'P' : // Partitions flags = flags ^ STATS_PARTITIONS; if (val.length()!=0) secP = Double.parseDouble(val); return true; case 'S' : // Stability flags = flags ^ STATS_STABILITY; if (val.length()!=0) secS = Double.parseDouble(val); return true; case 'U' : // Unidirectional flags = flags ^ STATS_UNIDIRECTIONAL; if (val.length()!=0) secU = Double.parseDouble(val); return true; default : return super.parseArg(key, val); } } public static void printHelp() { App.printHelp(); System.out.println("Statistics:"); System.out.println("\t-f <scenario name>"); System.out.println("\t-r <list of transmission ranges>"); System.out.println("\t-t [ print time (in progressive mode) ]"); System.out.println("\t-G <sec> Partitioning Degree"); System.out.println("\t-M <sec> MinCut"); System.out.println("\t-N <sec> Node Degree"); System.out.println("\t-P <sec> Partitions"); System.out.println("\t-S <sec> Stability"); System.out.println("\t-U <sec> Unidirectional"); } public static void main(String[] args) throws FileNotFoundException, IOException { new Statistics(args); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -