/** * Given a filename, parses the seeds of the various independent streams from the file. An example * seedfile looks like: * * <p> * * <pre> * PLACES 6167 34322 540141 #to place nodes on the plane * CONNECT 4149 3274 811023 #to connect nodes * EDGE_CONN 4321 6394 564736 #used in the edge connection method in TopDownHier model * GROUPING 39856 9062 30034 #used when grouping routers into an AS, in BottomUpHier model * ASSIGNMENT 2603 24124 6350 #used in BottomUpHierModel to decide how many routers each AS gets. * BANDWIDTH 1073 33601 47040 #used to specify bandwidth to edges in a topology * </pre> * * <p>The divisions of three are to maintain compatability with the C++ version's erand48() call. */ public void parse(String filename) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(new File(filename))); } catch (IOException e) { Util.ERR("Error reading seedfile. " + e); } String line = ""; try { while ((line = br.readLine()) != null) { StringTokenizer st = new StringTokenizer(line); String seedName = st.nextToken(); String first = st.nextToken(); String second = st.nextToken(); String third = st.nextToken(); String seedString = first.trim() + second.trim() + third.trim(); long seedValue = Long.parseLong(seedString); if (seedName.equals("PLACES")) setPlaceNodesSeed(seedValue); else if (seedName.equals("CONNECT")) setConnectNodesSeed(seedValue); else if (seedName.equals("BANDWIDTH")) setBWSeed(seedValue); else if (seedName.equals("EDGE_CONN")) setEdgeConnSeed(seedValue); else if (seedName.equals("GROUPING")) setGroupingSeed(seedValue); else if (seedName.equals("ASSIGNMENT")) setAssignSeed(seedValue); } } catch (Exception e2) { Util.ERR("Error reading seedfile. " + e2); } }
/** * Export the seeds used to lastSeedFile. (generally called "last_seed_file") Export the current * state of the PRNG and to nextSeedFile so the next experiement can continue to use the * independent streams (generally this file is called "seed_file") */ public void export(String lastSeedFile, String nextSeedFile) { Util.MSG("exporting seedfiles.."); BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(new File(lastSeedFile))); bw.write("PLACES " + longTo3String(placeSeed) + "\t# used when placing nodes on the plane"); bw.newLine(); bw.write("CONNECT " + longTo3String(connectSeed) + "\t# used when interconnecting nodes"); bw.newLine(); bw.write( "EDGE_CONN " + longTo3String(ECSeed) + "\t# used in the edge connection method of top down hier"); bw.newLine(); bw.write( "GROUPING " + longTo3String(GroupSeed) + "\t# used when deciding which routers to group into an AS in bottom up hier"); bw.newLine(); bw.write( "ASSIGNMENT " + longTo3String(AssignSeed) + "\t# used when deciding how many routers to group into an AS in bottom up hier"); bw.newLine(); bw.write("BANDWIDTH " + longTo3String(BWSeed) + "\t# used when assigning bandwidths"); bw.newLine(); bw.close(); } catch (IOException e) { System.out.println("[BRITE ERROR]: Error writing seeds to seedfile. " + e); } try { bw = new BufferedWriter(new FileWriter(new File(nextSeedFile))); bw.write( "PLACES " + longTo3String(PlaceRandom.nextLong()) + "\t# used when placing nodes on the plane"); bw.newLine(); bw.write( "CONNECT " + longTo3String(ConnectRandom.nextLong()) + "\t# used when interconnecting nodes"); bw.newLine(); bw.write( "EDGE_CONN " + longTo3String(EdgeConnRandom.nextLong()) + "\t# used in the edge connection method of top down hier"); bw.newLine(); bw.write( "GROUPING " + longTo3String(GroupingRandom.nextLong()) + "\t# used when deciding which routers to group into an AS in bottom up hier"); bw.newLine(); bw.write( "ASSIGNMENT " + longTo3String(AssignRandom.nextLong()) + "\t# used when deciding how many routers to group into an AS in bottom up hier"); bw.newLine(); bw.write( "BANDWIDTH " + longTo3String(BWRandom.nextLong()) + "\t# used when assigning bandwidths"); bw.newLine(); bw.close(); } catch (IOException e) { System.out.println("[BRITE ERROR]: Error writing seeds to seedfile. " + e); } }