org.jgrapht.Graph.degreeOf()方法的使用及代码示例

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

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

Graph.degreeOf介绍

[英]Returns the degree of the specified vertex.

A degree of a vertex in an undirected graph is the number of edges touching that vertex. Edges with same source and target vertices (self-loops) are counted twice.

In directed graphs this method returns the sum of the "in degree" and the "out degree".
[中]返回指定顶点的阶数。
无向图中顶点的阶数是接触该顶点的边数。具有相同源顶点和目标顶点(自循环)的边将计数两次。
在有向图中,此方法返回“入度”和“出度”之和。

代码示例

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Returns the degree of the specified vertex.
 *
 * @param vertex vertex whose degree is to be calculated
 * @return the degree of the specified vertex
 */
public int degreeOf(V vertex)
{
  return delegate.degreeOf(vertex);
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
   * Compare the degrees of <code>v1</code> and <code>v2</code>, taking into account whether
   * ascending or descending order is used.
   *
   * @param v1 the first vertex to be compared.
   * @param v2 the second vertex to be compared.
   *
   * @return -1 if <code>v1</code> comes before <code>v2</code>, +1 if <code>
   * v1</code> comes after <code>v2</code>, 0 if equal.
   */
  @Override
  public int compare(V v1, V v2)
  {
    int comparison = Integer.compare(graph.degreeOf(v1), graph.degreeOf(v2));

    if (order == Order.ASCENDING)
      return comparison;
    else
      return -1 * comparison;
  }
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Tests whether a graph is <a href="http://mathworld.wolfram.com/CubicGraph.html">cubic</a>. A
 * graph is cubic if all vertices have degree 3.
 * 
 * @param graph the input graph
 * @param <V> the graph vertex type
 * @param <E> the graph edge type
 * @return true if the graph is cubic, false otherwise
 */
public static <V, E> boolean isCubic(Graph<V, E> graph)
{
  for (V v : graph.vertexSet())
    if (graph.degreeOf(v) != 3)
      return false;
  return true;
}

代码示例来源:origin: org.jgrapht/jgrapht-core

for (V vertex : vertices) {
  vertexIndices.put(vertex, i);
  int degree = graph.degreeOf(vertex);
  degrees.add(degree);

代码示例来源:origin: org.jgrapht/jgrapht-core

private void computeGlobalClusteringCoefficient()
{
  NeighborCache<V, E> neighborCache = new NeighborCache<>(graph);
  computed = true;
  double numberTriplets = 0;
  for (V v : graph.vertexSet()) {
    if (graph.getType().isUndirected()) {
      numberTriplets += 1.0 * graph.degreeOf(v) * (graph.degreeOf(v) - 1) / 2;
    } else {
      numberTriplets += 1.0 * neighborCache.predecessorsOf(v).size()
        * neighborCache.successorsOf(v).size();
    }
  }
  globalClusteringCoefficient = 3 * GraphMetrics.getNumberOfTriangles(graph) / numberTriplets;
}

代码示例来源:origin: org.jgrapht/jgrapht-core

backwardMapping.put(v, u);
Map<Integer, List<V>> labelList = new HashMap<>(tree1.degreeOf(u));

代码示例来源:origin: org.jgrapht/jgrapht-core

@Override
public VertexCoverAlgorithm.VertexCover<V> getVertexCover()
{
  // Initialize
  this.graph = GraphTests.requireUndirected(graph);
  memo = new HashMap<>();
  vertices = new ArrayList<>(graph.vertexSet());
  neighborCache = new NeighborCache<>(graph);
  vertexIDDictionary = new HashMap<>();
  N = vertices.size();
  // Sort vertices based on their weight/degree ratio in ascending order
  // TODO JK: Are there better orderings?
  vertices.sort(Comparator.comparingDouble(v -> vertexWeightMap.get(v) / graph.degreeOf(v)));
  for (int i = 0; i < vertices.size(); i++)
    vertexIDDictionary.put(vertices.get(i), i);
  // Calculate a bound on the maximum depth using heuristics and mathematical bounding
  // procedures.
  // TODO JK: Is there a lower bounding procedure which allows us to prematurely terminate the
  // search once a solution is found which is equal to the lower bound? Preferably a bounding
  // procedure which gets better throughout the search.
  upperBoundOnVertexCoverWeight = this.calculateUpperBound();
  // Invoke recursive algorithm
  BitSetCover vertexCover = this.calculateCoverRecursively(0, new BitSet(N), 0);
  // Build solution
  Set<V> verticesInCover = new LinkedHashSet<>();
  for (int i = vertexCover.bitSetCover.nextSetBit(0); i >= 0 && i < N;
    i = vertexCover.bitSetCover.nextSetBit(i + 1))
    verticesInCover.add(vertices.get(i));
  return new VertexCoverAlgorithm.VertexCoverImpl<>(verticesInCover, vertexCover.weight);
}

代码示例来源:origin: org.jgrapht/jgrapht-core

&& graph.degreeOf(v) + graph.degreeOf(w) < n)
return false;

代码示例来源:origin: org.jgrapht/jgrapht-core

Map<V, Integer> degrees = new HashMap<>();
for (V v : g.vertexSet()) {
  int d = g.degreeOf(v);
  buckets[d].add(v);
  degrees.put(v, d);

代码示例来源:origin: org.jgrapht/jgrapht-core

if (normalizeEdgeCosts) {
  allEdges.sort((e1, e2) -> {
    double degreeE1 = graph.degreeOf(graph.getEdgeSource(e1))
      + graph.degreeOf(graph.getEdgeTarget(e1));
    double degreeE2 = graph.degreeOf(graph.getEdgeSource(e2))
      + graph.degreeOf(graph.getEdgeTarget(e2));
    return comparator.compare(
      graph.getEdgeWeight(e2) / degreeE2, graph.getEdgeWeight(e1) / degreeE1);

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * {@inheritDoc}
 */
@Override
public int degreeOf(V vertex)
{
  if (type.isMixed()) {
    int d = 0;
    if (g1.containsVertex(vertex)) {
      d += g1.degreeOf(vertex);
    }
    if (g2.containsVertex(vertex)) {
      d += g2.degreeOf(vertex);
    }
    return d;
  } else if (type.isUndirected()) {
    int degree = 0;
    Iterator<E> it = edgesOf(vertex).iterator();
    while (it.hasNext()) {
      E e = it.next();
      degree++;
      if (getEdgeSource(e).equals(getEdgeTarget(e))) {
        degree++;
      }
    }
    return degree;
  } else {
    return incomingEdgesOf(vertex).size() + outgoingEdgesOf(vertex).size();
  }
}

代码示例来源:origin: org.jgrapht/jgrapht-io

private void exportNormalizedLaplacianMatrix(Graph<V, E> g, Writer writer)
{
  PrintWriter out = new PrintWriter(writer);
  ComponentNameProvider<V> nameProvider = new IntegerComponentNameProvider<>();
  for (V from : g.vertexSet()) {
    // assign ids in vertex set iteration order
    nameProvider.getName(from);
  }
  for (V from : g.vertexSet()) {
    String fromName = nameProvider.getName(from);
    Set<V> neighbors = new LinkedHashSet<>(Graphs.neighborListOf(g, from));
    if (neighbors.isEmpty()) {
      exportEntry(out, fromName, fromName, "0");
    } else {
      exportEntry(out, fromName, fromName, "1");
      for (V to : neighbors) {
        String toName = nameProvider.getName(to);
        double value = -1 / Math.sqrt(g.degreeOf(from) * g.degreeOf(to));
        exportEntry(out, fromName, toName, Double.toString(value));
      }
    }
  }
  out.flush();
}

代码示例来源:origin: org.jgrapht/jgrapht-core

graph.vertexSet().stream().filter(v -> graph.degreeOf(v) > 0).forEach(
  v -> vertexEncapsulationMap
    .put(v, new RatioVertex<V>(vertexCounter++, v, vertexWeightMap.get(v))));

代码示例来源:origin: org.jgrapht/jgrapht-core

graph.vertexSet().stream().filter(v -> graph.degreeOf(v) > 0).forEach(
  v -> vertexEncapsulationMap
    .put(v, new RatioVertex<>(vertexCounter++, v, vertexWeightMap.get(v))));

代码示例来源:origin: org.jgrapht/jgrapht-core

private void BFOddHoleCertificate(Graph<V, E> g)
    if (g.degreeOf(start) < 2)
      continue;
    Set<V> set = new HashSet<>();
    for (V neighborOfStart : g.vertexSet()) {
      if (neighborOfStart == start || !g.containsEdge(start, neighborOfStart)
        || g.degreeOf(neighborOfStart) != 2)
        continue;
      set.remove(neighborOfStart);
          || !g.containsEdge(neighborsNeighbor, neighborOfStart)
          || g.containsEdge(neighborsNeighbor, start)
          || g.degreeOf(neighborsNeighbor) < 2)
          continue;
        GraphPath<V, E> path =

代码示例来源:origin: org.jgrapht/jgrapht-core

vertexList.stream().filter(x -> graph.degreeOf(x) >= sqrtV).collect(
  Collectors.toCollection(ArrayList::new));
if (graph.degreeOf(v1) < sqrtV || graph.degreeOf(v2) < sqrtV) {

代码示例来源:origin: org.jgrapht/jgrapht-core

|| subg.edgeSet().size() != subg.vertexSet().size()
|| subg.vertexSet().size() % 2 == 0
|| subg.vertexSet().stream().anyMatch(t -> subg.degreeOf(t) != 2))
continue;

代码示例来源:origin: org.jgrapht/jgrapht-core

graph.vertexSet().stream().filter(v -> graph.degreeOf(v) % 2 == 1).collect(
  Collectors.toList());

代码示例来源:origin: org.jgrapht/jgrapht-core

if (graph.degreeOf(v) % 2 == 1) {
    return false;
for (Set<V> component : new ConnectivityInspector<>(graph).connectedSets()) {
  for (V v : component) {
    if (graph.degreeOf(v) > 0) {
      if (foundComponentWithEdges) {
        return false;

相关文章