org.gephi.graph.api.Graph.readLock()方法的使用及代码示例

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

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

Graph.readLock介绍

[英]Opens a read lock for the current thread.
[中]打开当前线程的读锁。

代码示例

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

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

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

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

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

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

代码示例来源:origin: gephi/gephi-plugins-bootcamp

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

代码示例来源: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/layout-plugin

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

代码示例来源: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/layout-plugin

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

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

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

代码示例来源: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/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();
  }
}

代码示例来源:origin: gephi/gephi-plugins-bootcamp

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

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

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

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

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

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

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

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

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

代码示例来源: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/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/appearance-api

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

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

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

相关文章