📄 statistics.java
字号:
/******************************************************************************* ** BonnMotion - a mobility scenario generation and analysis tool ** ** Copyright (C) 2002, 2003 University of Bonn ** ** ** ** This program is free software; you can redistribute it and/or modify ** ** it under the terms of the GNU General Public License as published by ** ** the Free Software Foundation; either version 2 of the License, or ** ** (at your option) any later version. ** ** ** ** This program is distributed in the hope that it will be useful, ** ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** ** GNU General Public License for more details. ** ** ** ** You should have received a copy of the GNU General Public License ** ** along with this program; if not, write to the Free Software ** ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** *******************************************************************************/package edu.bonn.cs.iv.bonnmotion.apps;import edu.bonn.cs.iv.bonnmotion.*;import edu.bonn.cs.iv.graph.*;import edu.bonn.cs.iv.util.*;import java.io.*;import java.util.Vector;/** Application that calculates various statistics for movement scenarios. */public class Statistics extends App { public static final int STATS_NODEDEG = 0x00000001; public static final int STATS_PARTITIONS = 0x00000002; public static final int STATS_MINCUT = 0x00000004; public static final int STATS_STABILITY = 0x00000008; public static final int STATS_UNIDIRECTIONAL = 0x00000010; public static final int STATS_PARTDEG = 0x00000020; // to what degree is the network partitioned? protected static double secP = 0; protected static double secM = 0; protected static double secN = 0; protected static double secS = 0; protected static double secU = 0; protected static double secG = 0; protected static boolean printTime = false; protected String name = null; protected double[] radius = null; protected int flags = 0; /* protected double duration = 0; protected MobileNode node[] = null; */ public Statistics(String[] args) throws FileNotFoundException, IOException { go(args); } public void go(String[] _args) throws FileNotFoundException, IOException { parse(_args); if ((name == null) || (radius == null)) { printHelp(); System.exit(0); } Scenario s = new Scenario(name); // get my args /* node = s.getNode(); duration = s.getDuration(); */ if (flags > 0) for (int i = 0; i < radius.length; i++) { Heap sched = new Heap(); System.out.println("radius=" + radius[i]); // System.out.println("scheduling..."); schedule(s, sched, radius[i], false); // System.out.println("calculating..."); String basename = name + ".stats_" + radius[i]; if (basename.endsWith(".0")) basename = basename.substring(0, basename.length() - 2); progressive(s.nodeCount(), s.getDuration(), sched, true, flags, basename); } else overall(s, radius, name); } /** Calculates statistics' devolution over time. */ public static void progressive( int nodes, double duration,// Scenario s, Heap sched, boolean bidirectional, int which, String basename) throws FileNotFoundException, IOException {// MobileNode[] node = s.getNode();// double duration = s.getDuration(); Graph topo = new Graph(); for (int i = 0; i < nodes; i++) topo.checkNode(i); double time = 0.0; int unicnt = -1; int unisrc = -1; int unidst = -1; int mincut = -1; int stability = -1; int edges = -1; int part = -1; double partdeg = -1; double tNextDeg = 0.0; double tNextMinCut = 0.0; double tNextPart = 0.0; double tNextStability = 0.0; double tNextPartDeg = 0.0; double tNextUni = 0.0; // target files for stats output PrintWriter fDeg = null; if ((which & STATS_NODEDEG) > 0) fDeg = new PrintWriter(new FileOutputStream(basename + ".nodedeg")); PrintWriter fUni = null; if ((which & STATS_UNIDIRECTIONAL) > 0) fUni = new PrintWriter(new FileOutputStream(basename + ".uni")); PrintWriter fPart = null; if ((which & STATS_PARTITIONS) > 0) fPart = new PrintWriter(new FileOutputStream(basename + ".part")); PrintWriter fMinCut = null; if ((which & STATS_MINCUT) > 0) fMinCut = new PrintWriter(new FileOutputStream(basename + ".mincut")); PrintWriter fStability = null; if ((which & STATS_STABILITY) > 0) fStability = new PrintWriter(new FileOutputStream(basename + ".stability")); PrintWriter fPartDeg = null; if ((which & STATS_PARTDEG) > 0) fPartDeg = new PrintWriter(new FileOutputStream(basename + ".partdeg"));// double n1 = (double) (nodes * (nodes - 1)); double n1 = (double)(nodes - 1); int[] uni = new int[4]; int progress = -1; int done = 0; while (sched.size() > 0) { double ntime = sched.minLevel(); int nProg = (int)(100.0 * (double)done / (double)(sched.size() + done) + 0.5); if (nProg > progress) { progress = nProg; System.out.print("calculating... " + progress + "% done.\r"); } done++; if (ntime > time) { if (printTime) System.out.println("t=" + time); Graph g; if (bidirectional) { g = topo; if (((which & STATS_NODEDEG) > 0) && (time >= tNextDeg)) { tNextDeg += secN; int ne = 0; for (int i = 0; i < g.nodeCount(); i++) { Node n = g.nodeAt(i); ne += n.outDeg(); } if (ne != edges) { edges = ne; fDeg.println(time + " " + ((double) edges / n1)); } } } else { g = (Graph) topo.clone(); // double[] hirbel = g.unidirRemove(uni); g.unidirRemove(uni); if (((which & STATS_UNIDIRECTIONAL) > 0) && (time >= tNextUni) ) { tNextUni += secU; if (uni[0] != unicnt) { unicnt = uni[0]; fUni.println("unicnt " + time + " " + unicnt); } if (uni[1] != unisrc) { unisrc = uni[1]; fUni.println("unisrc " + time + " " + unisrc); } if (uni[2] != unidst) { unidst = uni[2]; fUni.println("unidst " + time + " " + unidst); } } if (((which & STATS_NODEDEG) > 0) && (time >= tNextDeg) && (uni[3] != edges)) { tNextDeg += secN; edges = uni[3]; fDeg.println(time + " " + ((double) edges / n1)); } } if (((which & STATS_PARTITIONS) > 0) && (time >= tNextPart)) { tNextPart += secP; int npart = g.partitions(0); if (part != npart) { part = npart; fPart.println(time + " " + part); } } if (((which & STATS_PARTDEG) > 0) && (time >= tNextPartDeg)) { tNextPartDeg += secG; double npartdeg = g.partdeg(0); if (partdeg != npartdeg) { partdeg = npartdeg; fPartDeg.println(time + " " + partdeg); } } if (((which & STATS_MINCUT) > 0) && (time >= tNextMinCut)) { tNextMinCut += secM; Graph h = Graph.buildSeperatorTree(g); Edge minedge = h.findMinEdge(); int nmincut = 0; if (minedge != null) nmincut = minedge.weight; if (mincut != nmincut) { mincut = nmincut; fMinCut.println(time + " " + mincut); } } if (((which & STATS_STABILITY) > 0) && (time >= tNextStability )) { tNextStability += secS; int nstability = g.stability(); if (stability != nstability) { stability = nstability; fStability.println(time + " " + stability); } } } time = ntime; IndexPair idx = (IndexPair) sched.deleteMin(); if (idx.i >= 0) { // hack: stopper Node src = topo.getNode(idx.i); if (src.getSucc(idx.j) == null) { // System.out.println("" + time + " +(" + idx.i + ", " + idx.j + ")"); Node dst = topo.getNode(idx.j); src.addSucc(dst, 1); //.setLabel("time", new Double(time)); if (bidirectional) dst.addSucc(src, 1); //.setLabel("time", new Double(time)); } else { // System.out.println("" + time + " -(" + idx.i + ", " + idx.j + ")"); src.delSucc(idx.j); if (bidirectional) topo.getNode(idx.j).delSucc(idx.i); } } } System.out.println(); if (fDeg != null) fDeg.close(); if (fUni != null) fUni.close(); if (fPart != null) fPart.close(); if (fMinCut != null) fMinCut.close(); if (fStability != null) fStability.close(); if (fPartDeg != null) fPartDeg.close(); } /** Put LinkStatusChange-events into a heap. */ public static double schedule( Scenario s, Heap sched, double radius, boolean calculateMobility) { MobileNode[] node = s.getNode(); double duration = s.getDuration(); double mobility = 0.0; int total = (node.length - 1) * node.length / 2; int done = 0; int progress = -1; for (int i = 0; i < node.length; i++) { for (int j = i + 1; j < node.length; j++) { int nProg = (int)(100.0 * (double)done / (double)total + 0.5); if (nProg > progress) { progress = nProg; System.out.print("scheduling... " + progress + "% done.\r");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -