@Override public void endAlgo() { graph.readLock(); try { for (Node n : graph.getNodes()) { n.setLayoutData(null); } } finally { graph.readUnlockAll(); } }
@Override public Iterable<Edge> getElements() { return graph.getEdges(); }
@Override public Number[] getValues(Graph graph) { List<Integer> values = new ArrayList<>(graph.getNodeCount()); for (Node n : graph.getNodes()) { int degree = graph.getDegree(n); values.add(degree); } return values.toArray(new Number[0]); }
public double calculateDensity(Graph graph, boolean isGraphDirected) { double result; double edgesCount = graph.getEdgeCount(); double nodesCount = graph.getNodeCount(); double multiplier = 1; if (!isGraphDirected) { multiplier = 2; } result = (multiplier * edgesCount) / (nodesCount * nodesCount - nodesCount); return result; }
@Override public boolean init(Graph graph) { return !(graph.getNodeCount() == 0 || !(graph.isDirected())); }
private void calculateCorrection(Graph graph, HashMap<Node, Integer> indicies, double[] nodeBetweenness, boolean directed, boolean normalized) { int n = graph.getNodeCount(); for (Node s : graph.getNodes()) { int s_index = indicies.get(s); if (!directed) { nodeBetweenness[s_index] /= 2; } if (normalized) { nodeBetweenness[s_index] /= directed ? (n - 1) * (n - 2) : (n - 1) * (n - 2) / 2; } } }
@Override public Graph filter(Graph graph) { GraphView graphView = graph.getView(); Collection<Node> nodes = graph.getNodes().toCollection(); Graph mainGraph = graph.getModel().getGraph(); for (int i = 0; i < depth; i++) { Node[] nei = neighbours.toArray(new Node[0]); for (Node n : nei) { for (Node neighbor : mainGraph.getNeighbors(n)) { neighbours.add(neighbor); result.add(neighbor); for (Node node : mainGraph.getNodes()) { if (result.contains(node)) { graph.addNode(node); } else if (graph.contains(node)) { graph.removeNode(node); for (Edge edge : mainGraph.getEdges()) { if (graph.contains(edge.getSource()) && graph.contains(edge.getTarget())) { graph.addEdge(edge);
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(); } }
@Override public Graph filter(Subgraph[] graphs) { if (graphs.length > 1) { throw new IllegalArgumentException("Not Filter accepts a single graph in parameter"); } Graph graph = graphs[0]; Graph mainGraph = graph.getView().getGraphModel().getGraph(); for (Node n : mainGraph.getNodes().toArray()) { if (!graph.contains(n)) { //The node n is not in graph graph.addNode(n); } else { //The node n is in graph graph.removeNode(n); } } for (Edge e : mainGraph.getEdges()) { Node source = e.getSource(); Node target = e.getTarget(); if (graph.contains(source) && graph.contains(target)) { Edge edgeInGraph = graph.getEdge(source, target, e.getType()); if (edgeInGraph == null) { graph.addEdge(e); } } } return graph; }
private void initCache() { int maxNodeStoreId = graphStore.nodeStore.maxStoreId(); nodeCache = new NodeImpl[maxNodeStoreId]; for (Node n : graph.getNodes()) { NodeImpl nImpl = (NodeImpl) n; nodeCache[nImpl.storeId] = nImpl; } int maxEdgeStoreId = graphStore.edgeStore.maxStoreId(); edgeCache = new EdgeImpl[maxEdgeStoreId]; for (Edge e : graph.getEdges()) { EdgeImpl eImpl = (EdgeImpl) e; edgeCache[eImpl.storeId] = eImpl; } }
Graph mainGraph = graph.getView().getGraphModel().getGraph(); for (Edge e : mainGraph.getEdges()) { boolean source = graph.contains(e.getSource()); boolean target = graph.contains(e.getTarget()); boolean keep = false; switch (option) { graph.clearEdges(); for (Node n : mainGraph.getNodes()) { if (!graph.contains(n)) { graph.addNode(n); graph.addEdge(e);
@Override public Iterable<Node> getElements() { return graph.getNodes(); }
@Override public Number[] getValues(Graph graph) { List<Number> vals = new ArrayList<>(); if (AttributeUtils.isNodeColumn(column)) { for (Element n : graph.getNodes()) { Object val = n.getAttribute(column, graph.getView()); if (val != null) { vals.add((Number) val); } } } else { for (Element e : graph.getEdges()) { Object val = e.getAttribute(column, graph.getView()); if (val != null) { vals.add((Number) val); } } } return vals.toArray(new Number[0]); }
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(); } }
@Override public Item[] getItems(Graph graph) { EdgeItem[] items = new EdgeItem[graph.getEdgeCount()]; int i = 0; for (Edge e : graph.getEdges()) { EdgeItem item = new EdgeItem(e); item.setData(EdgeItem.WEIGHT, e.getWeight(graph.getView())); item.setData(EdgeItem.DIRECTED, e.isDirected()); if (graph.isDirected(e)) { item.setData(EdgeItem.MUTUAL, ((DirectedGraph) graph).getMutualEdge(e) != null); } item.setData(EdgeItem.SELF_LOOP, e.isSelfLoop()); item.setData(EdgeItem.COLOR, e.alpha() == 0 ? null : e.getColor()); items[i++] = item; } return items; }
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(); } }
@Override protected void refresh() { if (graph.getEdgeCount() > 0) { double minV = Double.MAX_VALUE; double maxV = Double.MIN_VALUE; for (Edge e : graph.getEdges()) { if (e.hasDynamicWeight()) { TimeMap timeMap = (TimeMap) e.getAttribute("weight"); if (timeMap != null) { Double numMin = (Double) timeMap.get(graph.getView().getTimeInterval(), Estimator.MIN); Double numMax = (Double) timeMap.get(graph.getView().getTimeInterval(), Estimator.MAX); minV = Math.min(numMin, minV); maxV = Math.max(numMax, maxV); } } else { minV = Math.min(e.getWeight(), minV); maxV = Math.max(e.getWeight(), maxV); } } min = minV; max = maxV; } } }
protected GraphObserverImpl createGraphObserver(Graph graph, boolean withDiff) { if (graph.getView() != mainGraphView) { throw new RuntimeException("This graph doesn't belong to this store"); } if (observers != null) { GraphObserverImpl observer = new GraphObserverImpl(this, version, graph, withDiff); observers.add(observer); return observer; } return null; }
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(); } }