📄 loaddistribution.java
字号:
package sim;import java.util.*;import java.io.*;public class LoadDistribution extends Simulation{ double costsBefore = 0.0; double costsAfter = 0.0; int measurement = 1; public LoadDistribution(Properties properties){ super(properties); //System.out.println("LoadDistribution started"); } public void setup() { // create the overlay and broker network try{ net = Network.loadOverlay(this); }catch(Exception e){ System.out.println(e); e.printStackTrace(); System.exit(-1); } System.out.println("Things are scaled."); net.scaleCommunicationCosts(); net.assignProcessingCosts(); net.scaleProcessingCosts(); net.assignLoad(); net.scaleLoad(); net.createRandomTree(); // create the applications application = Application.createApplication(this); application.assignTo(net); // schedule Measurement Events scheduleEventAt(1000, new MeasureStartEvent()); scheduleEventAt(1750, new Event(){ public void handle(){ net.clearCaches(); } }); scheduleEventAt(2001, new MeasureStopEvent()); scheduleEventAt(2002, new Event() { public void handle() { net.startHeuristic(); } }); scheduleEventAt(24000, new Event() { public void handle() { net.stopHeuristic(); } }); scheduleEventAt(25000, new MeasureStartEvent()); scheduleEventAt(26001, new MeasureStopEvent()); scheduleEventAt(26002, new StopEvent()); } public void measure(){ if(measurement==1){ costsBefore = costs; measurement++; }else{ costsAfter = costs; out.println("# [costs before]\t[costs after]"); out.println(costsBefore+"\t"+costsAfter); } super.measure(); } // STATIC PART static String networkDir = "top/"; static String[] networks = {"top_100_a", "top_100_b", "top_100_c", "top_100_d", "top_100_e", "top_100_f", "top_100_g", "top_100_h", "top_100_i", "top_100_j", "top_100_k", "top_100_l", "top_100_m", "top_100_n", "top_100_o", "top_100_p", "top_100_q", "top_100_r", "top_100_s", "top_100_t", "top_100_u", "top_100_v", "top_100_w", "top_100_x", "top_100_y"}; static long[] networkSeeds = {-4515041865123927644L, -3933120523127033677L, -89753100835057852L, -2246939190084205288L, -4787191585183580137L, -4786913696067450174L, -6854358495074917031L, -5772303672735176780L, 2780642805011571475L, 2484887152919567080L, 7854960487905540437L, 3801418673539879598L, -292750896662828082L, 7058416063696821981L, -2592230874963103482L, 5655535948271851249L, -702041118509464497L, -3613813915364344556L, 8929653671402034948L, -6367631756964324863L, -7214673192719500127L, 8892490431749408044L, 7319428280250199549L, -4300401289142228810L, 2207295284731872802L}; static long[] applicationSeeds = { 6818759081432290199L, -9043549785126778424L, -4518915502978874806L, 8060158354073923478L, 5702008636583926206L, -2991648973446689819L, -8668430393692868381L, 1562325910739552378L, 1027850340222963412L, -4188475806252798227L, 5210888291360478653L, 9009240942721303267L, 7252995081531589214L, 9184024745824449343L, 7669291608638354103L, 7382656061168597548L, -2597155057491128153L, -2665186445686518793L, 4846676222359313084L, -6093812332889223719L, -8758368925231169974L, -6908651371430828329L, -1702167356932891370L, -669489382872811316L, -132841763694430825L}; static long[] brokerSeeds = {-5830134178093239754L, -3172067125697071388L, 8528066146489991466L, 7553944233115880630L, -7265686543594323217L, -305973066061097213L, 2280405442936781127L, -7211204845428064343L, 5789647022080235442L, -2182258746597356672L, -7970513032856719319L, -1317369443966199063L, 580447626328105997L, -4821670513098990197L, 5551680529041800389L, -6261301004649565705L, 2407602274839396850L, 2982261456732165427L, -9066858375267613403L, -482248434219446624L, -1018855744347185856L, -1629810895159267865L, 4829271904149263475L, -6291062194082857660L, -7498887299650463362L}; static String heuristic = "COSTS_AND_INTERESTS"; static String heuristicShort = "cai"; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try{ if(args.length>=2){ if(args[1].equalsIgnoreCase("MIN")){ heuristic="COSTS"; heuristicShort="min"; }else if(args[1].equalsIgnoreCase("MAX")){ heuristic="INTERESTS"; heuristicShort="max"; } } if(args[0].equalsIgnoreCase("MAKE_EXPERIMENT")){ makeExperiment(); }else if(args[0].equalsIgnoreCase("COLLECT_RESULTS")){ collectResults(); } }catch(Exception e){ System.err.println(e); e.printStackTrace(); System.exit(-1); } } private static void makeExperiment() throws Exception{ File f; String expDir; String expFile; PrintWriter out; expDir = "exp/load/"+heuristicShort+"/"; f = new File(expDir); f.mkdirs(); for(int net=0; net<networks.length; net++){ for(int i=1; i<21; i++){ expFile = expDir+networks[net]+"_"+heuristicShort+"_"+i; out = new PrintWriter(new FileWriter(expFile+".exp"),true); out.println("# experiment: load distribution "+i); out.println(); out.println("# general:"); out.println("simulation=sim.LoadDistribution"); out.println("outFile="+expFile+".rst"); out.println("netFile="+networkDir+networks[net]); out.println("measureInterval=1000"); out.println(); out.println("# random seeds"); out.println("networkSeed="+networkSeeds[net]); out.println("applicationSeed="+applicationSeeds[net]); out.println("brokerSeed="+brokerSeeds[net]); out.println(); out.println("# network"); out.println("minCommunicationCosts=0"); out.println("maxCommunicationCosts=10"); out.println("minProcessingCosts=0"); out.println("maxProcessingCosts=10"); out.println("minLoad=1"); out.println("maxLoad="+i); out.println("communicationDelayConstant=0"); out.println("communicationDelayFactor=1"); out.println("processingDelayConstant=0"); out.println("processingDelayFactor=0.001"); out.println(); out.println("# application"); out.println("numberOfJobs=50"); out.println("numberOfSubscribers=9"); out.println("publicationInterval=EXPONENTIAL"); out.println("publicationConstant=0.2"); out.println("reassignmentInterval=CONSTANT"); out.println("reassignmentConstant=100000"); out.println("locality=0"); out.println("localityPower=2"); out.println(); out.println("# broker"); out.println("heuristic="+heuristic); out.println("cacheSize=8192"); out.println("filterSize=100000"); out.println("broadcastInterval=250"); out.println("updateInterval=400"); out.println("order=UNORDERED"); out.println("environmentSize=4"); out.println("numberOfHashs=5"); out.flush(); out.close(); } } } private static void collectResults() throws Exception{ String expDir; String expFile; PrintWriter out; double before; double after; LineNumberReader in; String line; String[] tokens; double b; double a; double percent; double p; int n = networks.length; expDir = "exp/load/"+heuristicShort+"/"; out = new PrintWriter(new FileWriter(expDir+"RESULTS"),true); out.println("# [maxLoad] [improvement]"); for(int i=1; i<21; i++){ percent = before = after = 0; for(int net = 0; net < n; net++){ expFile = expDir+networks[net]+"_"+heuristicShort+"_"+i+".rst"; in = new LineNumberReader(new FileReader(expFile)); b=a=0; while((line=in.readLine())!=null){ if(line.startsWith("#") || line.equals("")){ continue; } tokens = line.split("\t"); b = Double.parseDouble(tokens[0]); a = Double.parseDouble(tokens[1]); } before += b; after += a; percent += (a*100.0d/b); in.close(); } p = percent/((double)n); out.println(i+"\t"+(100d-p)); } out.flush(); out.close(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -