private void executeSynthetic() { int toPercentCoef, percent = 0; int userNb = Network.size(); HashMap<Integer, VirtualEntity> coords; SolipsisProtocol solipsis; VirtualEntity entity; System.err.println("Populating Virtual World with " + userNb + " participants..."); VirtualWorldDistribution vwd = new VirtualWorldDistribution( this.distribution, userNb, Globals.zoneNb, Globals.outOfZoneNb, Globals.mapSize, Globals.zoneSize, Globals.smallZoneSize, Globals.smallZoneNb, this.applicativeLayerId); Globals.distribution = vwd; coords = vwd.getDistribution(); Iterator it = coords.entrySet().iterator(); toPercentCoef = userNb / 100; System.err.println("Joining nodes..."); for (int i = 0; i < userNb; i++) { entity = (VirtualEntity) ((Map.Entry) it.next()).getValue(); solipsis = (SolipsisProtocol) Network.get(i).getProtocol(applicativeLayerId); solipsis.setVirtualEntity(entity); solipsis.setPeersimNodeId(i); entity.setProtocol(solipsis); entity.setOrder(i + 1); if (i > 0) { solipsis.join((SolipsisProtocol) Network.get(i - 1).getProtocol(applicativeLayerId)); } if (i % toPercentCoef == 0) System.err.println(++percent + "%"); // System.out.println("peer "+i+": // "+solipsis.getVirtualEntity().getNeighbors().size()); } System.err.println("Done."); // System.out.println("uci2"); System.err.println("Normalizing Solipsis topology..."); percent = 0; it = coords.entrySet().iterator(); for (int i = 0; i < userNb; i++) { entity = (VirtualEntity) ((Map.Entry) it.next()).getValue(); // System.out.println("peer "+i+": "+entity.getNeighbors().size()); entity.getProtocol().finalizeKnowledgeZone(); // System.out.println("peer "+i+": "+entity.getNeighbors().size()); entity.getProtocol().simplifyTopology(); // System.out.println("peer "+i+": "+entity.getNeighbors().size()); if (i % (3 * toPercentCoef) == 0) System.err.println(++percent + "%"); } it = coords.entrySet().iterator(); for (int i = 0; i < userNb; i++) { entity = (VirtualEntity) ((Map.Entry) it.next()).getValue(); entity.refreshState(); if (i % (3 * toPercentCoef) == 0) System.err.println(++percent + "%"); } it = coords.entrySet().iterator(); for (int i = 0; i < userNb; i++) { entity = (VirtualEntity) ((Map.Entry) it.next()).getValue(); entity.getProtocol().maintainKnowledgeZone(); entity.getProtocol().finalizeKnowledgeZone(); entity.getProtocol().removeUnwantedNeighbors(); // System.out.println("peer "+i+": "+entity.getNeighbors().size()); if (i % (3 * toPercentCoef) == 0) System.err.println(++percent + "%"); } System.out.println("Done."); // for (int i = 0; i < 15; i++) { // System.out.println("cycle..."); // Globals.distribution.animate(); // // } Globals.topologyIsReady = true; System.err.println("Populated"); // System.err.println("Collisions:" + this.collisionCount()); // System.exit(2); if (Globals.realTime) { // VirtualWorldMonitor map = new VirtualWorldMonitor(vwd); // Globals.monitor = map; // map.showVirtualWorld(); Globals.recorder = new VirtualWorldRecorder(); } else { Globals.evaluator = new StatisticsGatherer(); } }
public boolean execute() { if (CDState.getCycle() % period != 0) return false; MycoCast mycocast = (MycoCast) Network.get(0).getProtocol(mycocastPid); int bio = mycocast.countBiomass(); int ext = mycocast.countExtending(); int bra = mycocast.countBranching(); int imm = mycocast.countImmobile(); // Update vertices Set<MycoNode> activeNodes = new HashSet<MycoNode>(); for (int i = 0; i < Network.size(); i++) { MycoNode n = (MycoNode) Network.get(i); activeNodes.add(n); HyphaData data = n.getHyphaData(); // if (data.isBiomass()) { continue; } if (graph.containsVertex(n)) { graph.removeVertex(n); } if (!graph.containsVertex(n)) { graph.addVertex(n); } } Set<MycoNode> jungNodes = new HashSet<MycoNode>(graph.getVertices()); jungNodes.removeAll(activeNodes); for (MycoNode n : jungNodes) { graph.removeVertex(n); } // Update edges for (int i = 0; i < Network.size(); i++) { MycoNode n = (MycoNode) Network.get(i); HyphaData data = n.getHyphaData(); HyphaLink link = n.getHyphaLink(); synchronized (graph) { // We now add in all links and tune out display in Visualizer java.util.List<MycoNode> neighbors = (java.util.List<MycoNode>) link.getNeighbors(); //// Adding only links to hypha thins out links to biomass // (java.util.List<MycoNode>) link.getHyphae(); Collection<MycoNode> jungNeighbors = graph.getNeighbors(n); // Remove edges from Jung graph that are not in peersim graph for (MycoNode o : jungNeighbors) { if (!neighbors.contains(o)) { MycoEdge edge = graph.findEdge(n, o); while (edge != null) { graph.removeEdge(edge); edge = graph.findEdge(n, o); } } } // Add missing edges to Jung graph that are in peersim graph for (MycoNode o : neighbors) { if (graph.findEdge(n, o) == null) { MycoEdge edge = new MycoEdge(); graph.addEdge(edge, n, o, EdgeType.DIRECTED); } } } // log.finest("VERTICES: " + graph.getVertices()); // log.finest("EDGES: " + graph.getEdges()); } for (ChangeListener cl : changeListeners) { cl.stateChanged(new ChangeEvent(graph)); } if (walking) { try { Thread.sleep(walkDelay); } catch (InterruptedException e) { } stepBlocked = false; } try { while (stepBlocked && !noBlock) { synchronized (JungGraphObserver.class) { JungGraphObserver.class.wait(); } } } catch (InterruptedException e) { stepBlocked = true; } stepBlocked = true; // System.out.println(graph.toString()); return false; }