org.gephi.graph.api.Graph类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(247)

本文整理了Java中org.gephi.graph.api.Graph类的一些代码示例,展示了Graph类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph类的具体详情如下:
包路径:org.gephi.graph.api.Graph
类名称:Graph

Graph介绍

[英]Graph interface.
[中]图形界面。

代码示例

代码示例来源:origin: org.gephi/layout-plugin

@Override
public void endAlgo() {
  graph.readLock();
  try {
    for (Node n : graph.getNodes()) {
      n.setLayoutData(null);
    }
  } finally {
    graph.readUnlockAll();
  }
}

代码示例来源:origin: org.gephi/appearance-api

@Override
public Iterable<Edge> getElements() {
  return graph.getEdges();
}

代码示例来源:origin: org.gephi/filters-plugin

@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]);
}

代码示例来源:origin: org.gephi/statistics-plugin

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;
}

代码示例来源:origin: org.gephi/filters-plugin

@Override
public boolean init(Graph graph) {
  return !(graph.getNodeCount() == 0 || !(graph.isDirected()));
}

代码示例来源:origin: org.gephi/statistics-plugin

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;
    }
  }
}

代码示例来源:origin: org.gephi/filters-plugin

@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);

代码示例来源:origin: org.gephi/statistics-plugin

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();
  }
}

代码示例来源:origin: org.gephi/filters-plugin

@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;
}

代码示例来源:origin: org.gephi/graphstore

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;
  }
}

代码示例来源:origin: org.gephi/filters-plugin

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);

代码示例来源:origin: org.gephi/appearance-api

@Override
public Iterable<Node> getElements() {
  return graph.getNodes();
}

代码示例来源:origin: org.gephi/filters-plugin

@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]);
}

代码示例来源:origin: org.gephi/statistics-plugin

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();
  }
}

代码示例来源:origin: org.gephi/preview-plugin

@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;
}

代码示例来源:origin: org.gephi/statistics-plugin

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();
  }
}

代码示例来源:origin: org.gephi/appearance-api

@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;
    }
  }
}

代码示例来源:origin: org.gephi/graphstore

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;
}

代码示例来源:origin: org.gephi/filters-plugin

@Override
public Number[] getValues(Graph graph) {
  List<Number> values = new ArrayList<>();
  for (Edge e : graph.getEdges()) {
    double weight = e.getWeight(graph.getView());
    values.add(weight);
  }
  return values.toArray(new Number[0]);
}

代码示例来源:origin: org.gephi/statistics-plugin

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();
  }
}

相关文章