public static Node[] getNeighbors(Graph graph, Node[] nodes) { Set<Node> nodeTree = new HashSet<>(); graph.readLock(); try { for (Node n : nodes) { nodeTree.addAll(graph.getNeighbors(n).toCollection()); } } finally { graph.readUnlock(); } //remove original nodes for (Node n : nodes) { nodeTree.remove(n); } return nodeTree.toArray(new Node[0]); }
@Override public void endAlgo() { graph.readLock(); try { for (Node n : graph.getNodes()) { n.setLayoutData(null); } pool.shutdown(); } finally { graph.readUnlockAll(); } }
public static Node[] getNeighborsOfNeighbors(Graph graph, Node[] nodes) { Set<Node> nodeTree = new HashSet<>(); graph.readLock(); try { for (Node n : nodes) { nodeTree.addAll(graph.getNeighbors(n).toCollection()); } //remove original nodes for (Node n : nodes) { nodeTree.remove(n); } for (Node n : nodeTree.toArray(new Node[0])) { nodeTree.addAll(graph.getNeighbors(n).toCollection()); } } finally { graph.readUnlock(); } //remove original nodes for (Node n : nodes) { nodeTree.remove(n); } return nodeTree.toArray(new Node[0]); }
@Override public void select() { //Get current visible graph GraphController graphController = Lookup.getDefault().lookup(GraphController.class); Graph graph = graphController.getGraphModel().getGraphVisible(); //Build the autocomplete data. A simple map from node's label graph.readLock(); data = new HashMap<String, Node>(); for (Node n : graph.getNodes()) { String label = n.getLabel(); String id = n.getId().toString(); if (label != null) { if (!label.isEmpty()) { data.put(label, n); } } else if (id != null && !id.isEmpty()) { data.put(id, n); } } graph.readUnlock(); }
@Override public void endAlgo() { graph.readLock(); try { for (Node n : graph.getNodes()) { n.setLayoutData(null); } } finally { graph.readUnlockAll(); } }
@Override public void endAlgo() { graph.readLock(); try { for (Node n : graph.getNodes()) { n.setLayoutData(null); } } finally { graph.readUnlockAll(); } }
@Override public void endAlgo() { graph.readLock(); try { for (Node n : graph.getNodes()) { n.setLayoutData(null); } } finally { graph.readUnlockAll(); } }
@Override public void endAlgo() { graph.readLock(); try { for (Node n : graph.getNodes()) { n.setLayoutData(null); } } finally { graph.readUnlockAll(); } }
@Override public void goAlgo() { graph = graphModel.getGraphVisible(); graph.readLock(); try { for (Node n : graph.getNodes()) { n.setX((float) (-size / 2 + size * random.nextDouble())); n.setY((float) (-size / 2 + size * random.nextDouble())); } converged = true; } finally { graph.readUnlockAll(); } }
public void execute(Graph graph) { isCanceled = false; initializeAttributeColunms(graph.getModel()); graph.readLock(); try { N = graph.getNodeCount(); initializeStartValues(); HashMap<Node, Integer> indicies = createIndiciesMap(graph); Map<String, double[]> metrics = calculateDistanceMetrics(graph, indicies, isDirected, isNormalized); eccentricity = metrics.get(ECCENTRICITY); closeness = metrics.get(CLOSENESS); harmonicCloseness = metrics.get(HARMONIC_CLOSENESS); betweenness = metrics.get(BETWEENNESS); saveCalculatedValues(graph, indicies, eccentricity, betweenness, closeness, harmonicCloseness); } finally { graph.readUnlock(); } }
public void execute(Graph graph) { isCanceled = false; graph.readLock(); try { structure = new Modularity.CommunityStructure(graph); int[] comStructure = new int[graph.getNodeCount()]; if (graph.getNodeCount() > 0) {//Fixes issue #713 Modularity Calculation Throws Exception On Empty Graph HashMap<String, Double> computedModularityMetrics = computeModularity(graph, structure, comStructure, resolution, isRandomized, useWeight); modularity = computedModularityMetrics.get("modularity"); modularityResolution = computedModularityMetrics.get("modularityResolution"); } else { modularity = 0; modularityResolution = 0; } saveValues(comStructure, graph, structure); } finally { graph.readUnlock(); } }
@Override public void goAlgo() { Graph graph = graphModel.getGraphVisible(); graph.readLock(); int nodeCount = graph.getNodeCount(); Node[] nodes = graph.getNodes().toArray(); int rows = (int) Math.round(Math.sqrt(nodeCount)) + 1; int cols = (int) Math.round(Math.sqrt(nodeCount)) + 1; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols && (i * rows + j) < nodes.length; j++) { Node node = nodes[i * rows + j]; float x = (-areaSize / 2f) + ((float) j / cols) * areaSize; float y = (areaSize / 2f) - ((float) i / rows) * areaSize; float px = node.x(); float py = node.y(); node.setX(px + (x - px) * (speed / 10000f)); node.setY(py + (y - py) * (speed / 10000f)); } } graph.readUnlock(); }
public void execute(Graph graph) { isDirected = graph.isDirected(); isCanceled = false; initializeDegreeDists(); initializeAttributeColunms(graph.getModel()); graph.readLock(); try { avgWDegree = calculateAverageWeightedDegree(graph, isDirected, true); } finally { graph.readUnlockAll(); } }
public void execute(Graph graph) { isCanceled = false; Column column = initializeAttributeColunms(graph.getModel()); graph.readLock(); try { HashMap<Node, Integer> indicies = createIndiciesMap(graph); pageranks = calculatePagerank(graph, indicies, isDirected, useEdgeWeight, epsilon, probability); saveCalculatedValues(graph, column, indicies, pageranks); } finally { graph.readUnlockAll(); } }
public void execute(Graph graph) { Column column = initializeAttributeColunms(graph.getModel()); int N = graph.getNodeCount(); graph.readLock(); try { centralities = new double[N]; Progress.start(progress, numRuns); HashMap<Integer, Node> indicies = new HashMap<>(); HashMap<Node, Integer> invIndicies = new HashMap<>(); fillIndiciesMaps(graph, centralities, indicies, invIndicies); sumChange = calculateEigenvectorCentrality(graph, centralities, indicies, invIndicies, isDirected, numRuns); saveCalculatedValues(graph, column, indicies, centralities); } finally { graph.readUnlock(); } Progress.finish(progress); }
@Override public void goAlgo() { graph = graphModel.getGraphVisible(); graph.readLock(); try { double sin = Math.sin(-getAngle() * Math.PI / 180); double cos = Math.cos(-getAngle() * Math.PI / 180); double px = 0f; double py = 0f; for (Node n : graph.getNodes()) { double dx = n.x() - px; double dy = n.y() - py; n.setX((float) (px + dx * cos - dy * sin)); n.setY((float) (py + dy * cos + dx * sin)); } setConverged(true); } finally { graph.readUnlockAll(); } }
public void execute(Graph graph) { isDirected = graph.isDirected(); isCanceled = false; initializeDegreeDists(); initializeAttributeColunms(graph.getModel()); graph.readLock(); try { avgDegree = calculateAverageDegree(graph, isDirected, true); graph.setAttribute(AVERAGE_DEGREE, avgDegree); } finally { graph.readUnlockAll(); } }
public void execute(Graph graph) { initializeAttributeColunms(graph.getModel()); graph.readLock(); try { int N = graph.getNodeCount(); authority = new double[N]; hubs = new double[N]; Map<Node, Integer> indices = createIndicesMap(graph); calculateHits(graph, hubs, authority, indices, !useUndirected, epsilon); saveCalculatedValues(indices, authority, hubs); } finally { graph.readUnlockAll(); } }
protected void refreshFunctions() { graph.readLock(); try { boolean graphHasChanged = graphObserver.isNew() || graphObserver.hasGraphChanged(); if (graphHasChanged) { if (graphObserver.isNew()) { graphObserver.hasGraphChanged(); } refreshGraphFunctions(); } refreshAttributeFunctions(graphHasChanged); } finally { graph.readUnlockAll(); } }
@Override public void initAlgo() { if (graphModel == null) { return; } graph = graphModel.getGraphVisible(); graph.readLock(); try { energy = Float.POSITIVE_INFINITY; for (Node n : graph.getNodes()) { n.setLayoutData(new ForceVector()); } progress = 0; setConverged(false); setStep(initialStep); } finally { graph.readUnlockAll(); } }