📄 network.java
字号:
brokers[j+1] = subscribers[j]; } for(int j=0; j < brokers.length; j++){ for(int k=j+1; k<brokers.length; k++){ Edge e = overlay.getEdge(brokers[j],brokers[k]); Value v = (Value)e.getProperty(ints); if(v == null){ v = new Value(1); e.setProperty(ints,v); }else{ v.current += 1; } } } } Graph myTree = new Graph(); int compcount = 0; LinkedList es = new LinkedList(); for(Iterator it = overlay.edgeIterator(); it.hasNext(); ){ es.add(it.next()); } Edge[] edges = (Edge[])es.toArray(new Edge[0]); Arrays.sort(edges,new Comparator(){ public int compare(Object o1, Object o2){ Edge e1 = (Edge)o1; Edge e2 = (Edge)o2; Value v1 = (Value)e1.getProperty(ints); Value v2 = (Value)e2.getProperty(ints); if(v1==null && v2==null){ return 0; } if(v1==null && v2!=null){ return 1; } if(v1!=null && v2==null){ return -1; } if(v1.current<v2.current){ return 1; } if(v1.current>v2.current){ return -1; } return 0; } }); int ohne = 0; for(int i=0; i<edges.length; i++){ Edge e = edges[i]; Value vs = (Value)e.s.getProperty(component); Value vt = (Value)e.t.getProperty(component); if(vs == null){ vs = new Value(compcount++); e.s.setProperty(component, vs); } if(vt == null){ vt = new Value(compcount++); e.t.setProperty(component, vt); } if(vs.current == vt.current){ //System.out.println("Continued"); continue; } myTree.addEdge(e); System.out.println("Adding edge from "+e.s+" (Component "+vs.current+") to "+e.t+" (Component "+vt.current+") mit Interesse "+(Value)e.getProperty(ints)+" size:"+myTree.getNumberOfVertices()); double min = Math.min(vs.current,vt.current); double max = Math.max(vs.current,vt.current); for(Iterator it = myTree.vertexIterator(); it.hasNext(); ){ Value v = (Value)((Broker)it.next()).getProperty(component); //System.out.println("vs: "+vs.current+" vt: "+vt.current+" v: "+v.current); if(v.current == max){ v.current = min; } } } component.clear(); ints.clear(); tree = myTree; this.setNeighbors(); } public void createStar(Application app){ Job[] jobs = app.getJobs(); for(int i=0; i<jobs.length; i++) { Broker[] brokers = new Broker[10]; brokers[0] = jobs[i].getPublisher(); Broker[] subscribers = jobs[i].getSubscribers(); for(int j=0; j<subscribers.length; j++){ brokers[j+1] = subscribers[j]; } for(int j=0; j < brokers.length; j++){ Value v = (Value)brokers[j].getProperty(ints); if(v == null){ v = new Value(1); brokers[j].setProperty(ints,v); } } } Broker bMax = null; double max = 0; for (Iterator it=overlay.vertexIterator(); it.hasNext(); ){ Broker b = (Broker)it.next(); Value w = (Value)b.getProperty(ints); if(w!=null){ if(w.current>max){ max = w.current; bMax = b; } } } Graph myTree = new Graph(); for (Iterator it = overlay.vertexIterator(); it.hasNext(); ){ Broker b = (Broker)it.next(); if(b != bMax){ Edge e = overlay.getEdge(bMax,b); myTree.addEdge(e); System.out.println("Adding edge from "+bMax+" to "+b+" size:"+myTree.getNumberOfVertices()); } } ints.clear(); tree = myTree; this.setNeighbors(); } public void scaleLoad(){ if(minLoad == 0.0){ scaleLoad(maxLoad); }else{ scaleLoad(minLoad,maxLoad); } } public void scaleLoad(double max){ double currentMax; Broker b; Value v; currentMax = Double.MIN_VALUE; for(Iterator it = overlay.vertexIterator(); it.hasNext(); ){ b = (Broker)it.next(); v = (Value)b.getProperty(load); if(v.current>currentMax){ currentMax = v.current; } } scaleLoadBy(max/currentMax); } public void scaleLoad(double min, double max){ double currentMin; double currentMax; double delta; Broker b; Value v; currentMin = Double.MAX_VALUE; currentMax = Double.MIN_VALUE; for(Iterator it = overlay.vertexIterator(); it.hasNext(); ){ b = (Broker)it.next(); v = (Value)b.getProperty(load); if(v.current<currentMin){ currentMin = v.current; } if(v.current>currentMax){ currentMax = v.current; } } delta = currentMax - currentMin; delta = delta == 0.0 ? 1.0 : delta; for(Iterator it = overlay.vertexIterator(); it.hasNext(); ){ b = (Broker)it.next(); v = (Value)b.getProperty(load); v.current = (v.current-currentMin) * ((max-min)/delta) + min; } } public void scaleLoadBy(double factor){ Broker b; Value v; for(Iterator it = overlay.vertexIterator(); it.hasNext(); ){ b = (Broker)it.next(); v = (Value)b.getProperty(load); v.current = v.current*factor; } } public void scaleProcessingCosts(double min, double max){ double currentMin; double currentMax; double delta; Broker b; Value v; currentMin = Double.MAX_VALUE; currentMax = Double.MIN_VALUE; for(Iterator it = overlay.vertexIterator(); it.hasNext(); ){ b = (Broker)it.next(); v = (Value)b.getProperty(processingCosts); if(v.current<currentMin){ currentMin = v.current; } if(v.current>currentMax){ currentMax = v.current; } } delta = currentMax - currentMin; delta = delta == 0.0 ? 1.0 : delta; for(Iterator it = overlay.vertexIterator(); it.hasNext(); ){ b = (Broker)it.next(); v = (Value)b.getProperty(processingCosts); v.current = (v.current-currentMin) * ((max-min)/delta) + min; } } public void scaleProcessingCostsBy(double factor){ Broker b; Value v; for(Iterator it = overlay.vertexIterator(); it.hasNext(); ){ b = (Broker)it.next(); v = (Value)b.getProperty(processingCosts); v.current = v.current*factor; } } public void scaleProcessingCosts(double max){ double currentMax; Broker b; Value v; currentMax = Double.MIN_VALUE; for(Iterator it = overlay.vertexIterator(); it.hasNext(); ){ b = (Broker)it.next(); v = (Value)b.getProperty(processingCosts); if(v.current>currentMax){ currentMax = v.current; } } scaleProcessingCostsBy(max/currentMax); } public void scaleProcessingCosts(){ if(minProcessingCosts == 0.0){ scaleProcessingCosts(maxProcessingCosts); }else{ scaleProcessingCosts(minProcessingCosts,maxProcessingCosts); } } public void scaleCommunicationCosts(double min, double max){ double currentMin; double currentMax; double delta; Edge e; Value v; currentMin = Double.MAX_VALUE; currentMax = Double.MIN_VALUE; for(Iterator it = overlay.edgeIterator(); it.hasNext(); ){ e = (Edge)it.next(); v = (Value)e.getProperty(communicationCosts); if(v.current<currentMin){ currentMin = v.current; } if(v.current>currentMax){ currentMax = v.current; } } delta = currentMax - currentMin; delta = delta == 0.0 ? 1.0 : delta; for(Iterator it = overlay.edgeIterator(); it.hasNext(); ){ e = (Edge)it.next(); v = (Value)e.getProperty(communicationCosts); v.current = (v.current-currentMin) * ((max-min)/delta) + min; } } public void scaleCommunicationCostsBy(double factor){ Edge e; Value v; for(Iterator it = overlay.edgeIterator(); it.hasNext(); ){ e = (Edge)it.next(); v = (Value)e.getProperty(communicationCosts); v.current = v.current*factor; //System.out.println(v.current); } //System.out.println("War faktor"); } public void scaleCommunicationCosts(){ if(minCommunicationCosts == 0.0){ scaleCommunicationCosts(maxCommunicationCosts); }else{ scaleCommunicationCosts(minCommunicationCosts,maxCommunicationCosts); } } public void scaleCommunicationCosts(double max){ double currentMax; Edge e; Value v; currentMax = Double.MIN_VALUE; for(Iterator it = overlay.edgeIterator(); it.hasNext(); ){ e = (Edge)it.next(); v = (Value)e.getProperty(communicationCosts); if(v.current>currentMax){ currentMax = v.current; } } //System.out.println("max CommunicationCosts: "+currentMax); scaleCommunicationCostsBy(max/currentMax); } public void assignLoad(){ Broker b; Value v; for(Iterator it = overlay.vertexIterator(); it.hasNext(); ){ b = (Broker)it.next(); v = (Value)b.getProperty(load); if(v==null){ v = new Value(0); b.setProperty(load, v); } v.current = (maxLoad-minLoad)*rand.nextDouble()+minLoad; } } public void assignParetoLoad(){ Broker b; Value v; LinkedList brokers; brokers = new LinkedList(); for(Iterator it= overlay.vertexIterator(); it.hasNext(); ){ brokers.add(it.next()); } for(int i=0; !brokers.isEmpty(); i++){ b = (Broker)brokers.get(rand.nextInt(brokers.size())); brokers.remove(b); v = (Value)b.getProperty(load); if(v==null){ v = new Value(0); b.setProperty(load, v); } if(i<10){ v.current = 8.0d; }else{ v.current = 0.5d; } } } public void assignProcessingCosts(){ Broker b; Value v; for(Iterator it = overlay.vertexIterator(); it.hasNext(); ){ b = (Broker)it.next(); v = (Value)b.getProperty(processingCosts); if(v==null){ v = new Value(0); b.setProperty(processingCosts, v); } v.current = (maxProcessingCosts-minProcessingCosts)*rand.nextDouble()+minProcessingCosts; } } public void clearCaches(){ for(Iterator it = overlay.vertexIterator(); it.hasNext(); ){ ((Broker)it.next()).clearCache(); } } public void comCosts(){ LinkedList brokers = new LinkedList(); for(Iterator it = this.brokerIterator(); it.hasNext();){ brokers.add(it.next()); } Broker b1 = (Broker)brokers.get(5); Broker b2 = (Broker)brokers.get(15); double c = this.getCommunicationCosts(b1,b2); double p = this.getProcessingCosts(b1); double l = this.getLoad(b1); System.out.println("c="+c+" p="+p+" l="+l); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -