com.google.common.graph.Network.asGraph()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(139)

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

Network.asGraph介绍

[英]Returns a live view of this network as a Graph. The resulting Graph will have an edge connecting node A to node B if this Network has an edge connecting A to B.

If this network #allowsParallelEdges(), parallel edges will be treated as if collapsed into a single edge. For example, the #degree(Object) of a node in the Graph view may be less than the degree of the same node in this Network.
[中]以图形形式返回此网络的实时视图。如果该网络具有连接A到B的边,则生成的图将具有连接节点A到节点B的边。
如果此网络#AllowsParallelEdge(),平行边将被视为折叠为一条边。例如,图视图中节点的#度(对象)可能小于该网络中同一节点的度。

代码示例

代码示例来源:origin: google/guava

/**
 * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty
 * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges)
 * starting and ending with the same node.
 *
 * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1).
 */
public static boolean hasCycle(Network<?, ?> network) {
 // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph.
 // However, in an undirected graph, any parallel edge induces a cycle in the graph.
 if (!network.isDirected()
   && network.allowsParallelEdges()
   && network.edges().size() > network.asGraph().edges().size()) {
  return true;
 }
 return hasCycle(network.asGraph());
}

代码示例来源:origin: google/j2objc

/**
 * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty
 * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges)
 * starting and ending with the same node.
 *
 * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1).
 */
public static boolean hasCycle(Network<?, ?> network) {
 // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph.
 // However, in an undirected graph, any parallel edge induces a cycle in the graph.
 if (!network.isDirected()
   && network.allowsParallelEdges()
   && network.edges().size() > network.asGraph().edges().size()) {
  return true;
 }
 return hasCycle(network.asGraph());
}

代码示例来源:origin: wildfly/wildfly

/**
 * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty
 * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges)
 * starting and ending with the same node.
 *
 * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1).
 */
public static boolean hasCycle(Network<?, ?> network) {
 // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph.
 // However, in an undirected graph, any parallel edge induces a cycle in the graph.
 if (!network.isDirected()
   && network.allowsParallelEdges()
   && network.edges().size() > network.asGraph().edges().size()) {
  return true;
 }
 return hasCycle(network.asGraph());
}

代码示例来源:origin: google/guava

String edgeString = networkString.substring(edgeStart);
Graph<N> asGraph = network.asGraph();
AbstractGraphTest.validateGraph(asGraph);
assertThat(network.nodes()).isEqualTo(asGraph.nodes());

代码示例来源:origin: jrtom/jung

/**
 * Creates an instance with the specified graph, distance metric, and averaging behavior.
 *
 * @param graph The graph on which the node scores are to be calculated.
 * @param distance The metric to use for specifying the distance between pairs of nodes.
 * @param averaging Specifies whether the values returned is the sum of all v-distances or the
 *     mean v-distance.
 * @param ignore_missing Specifies whether scores for missing distances are to ignore missing
 *     distances or be set to null.
 * @param ignore_self_distances Specifies whether distances from a node to itself should be
 *     included in its score.
 */
public DistanceCentralityScorer(
  Network<N, E> graph,
  Distance<N> distance,
  boolean averaging,
  boolean ignore_missing,
  boolean ignore_self_distances) {
 this.graph = graph.asGraph();
 this.distance = distance;
 this.averaging = averaging;
 this.ignore_missing = ignore_missing;
 this.ignore_self_distances = ignore_self_distances;
 this.output = new HashMap<N, Double>();
}

代码示例来源:origin: jrtom/jung

/** */
protected void drawShortest() {
 if (mFrom == null || mTo == null) {
  return;
 }
 BFSDistanceLabeler<String> bdl = new BFSDistanceLabeler<>();
 bdl.labelDistances(mGraph.asGraph(), mFrom);
 mPred = new HashSet<>();
 // grab a predecessor
 String v = mTo;
 Set<String> prd = bdl.getPredecessors(v);
 mPred.add(mTo);
 while (prd != null && prd.size() > 0) {
  v = prd.iterator().next();
  mPred.add(v);
  if (v.equals(mFrom)) {
   return;
  }
  prd = bdl.getPredecessors(v);
 }
}

代码示例来源:origin: jrtom/jung

public void setNetwork(Network<N, E> network, boolean forceUpdate) {
 log.trace("setNetwork to n:{} e:{}", network.nodes(), network.edges());
 this.network = network;
 this.layoutModel.setGraph(network.asGraph());
 if (forceUpdate && this.layoutAlgorithm != null) {
  log.trace("will accept {}", layoutAlgorithm);
  layoutModel.accept(this.layoutAlgorithm);
  log.trace("will fire stateChanged");
  changeSupport.fireStateChanged();
  log.trace("fired stateChanged");
 }
}

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

/**
 * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty
 * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges)
 * starting and ending with the same node.
 *
 * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1).
 */
public static boolean hasCycle(Network<?, ?> network) {
 // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph.
 // However, in an undirected graph, any parallel edge induces a cycle in the graph.
 if (!network.isDirected()
   && network.allowsParallelEdges()
   && network.edges().size() > network.asGraph().edges().size()) {
  return true;
 }
 return hasCycle(network.asGraph());
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

/**
 * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty
 * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges)
 * starting and ending with the same node.
 *
 * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1).
 */
public static boolean hasCycle(Network<?, ?> network) {
 // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph.
 // However, in an undirected graph, any parallel edge induces a cycle in the graph.
 if (!network.isDirected()
   && network.allowsParallelEdges()
   && network.edges().size() > network.asGraph().edges().size()) {
  return true;
 }
 return hasCycle(network.asGraph());
}

代码示例来源:origin: jrtom/jung

/**
 * For each node <code>v</code> in <code>g</code>, calculates the average shortest path length
 * from <code>v</code> to all other nodes in <code>g</code>, ignoring edge weights.
 *
 * @see #diameter(Hypergraph)
 * @see edu.uci.ics.jung.algorithms.scoring.ClosenessCentrality
 * @param g the graph for which distances are to be calculated
 * @param <N> the node type
 * @param <E> the edge type
 * @return a map from each node to the mean distance to each other (reachable) node
 */
public static <N, E> Function<N, Double> averageDistances(Network<N, E> g) {
 final ClosenessCentrality<N, E> cc =
   new ClosenessCentrality<N, E>(g, new UnweightedShortestPath<N>(g.asGraph()));
 return new NodeScoreTransformer<N, Double>(cc);
}

代码示例来源:origin: jrtom/jung

this.layoutModel =
  LoadingCacheLayoutModel.<N>builder()
    .setGraph(network.asGraph())
    .setSize(layoutSize.width, layoutSize.height)
    .setInitializer(

代码示例来源:origin: jrtom/jung

new AggregateLayoutModel<>(
  LoadingCacheLayoutModel.<String>builder()
    .setGraph(graph.asGraph())
    .setSize(preferredSize.width, preferredSize.height)
    .build());

代码示例来源:origin: jrtom/jung

public void visit(LayoutModel<N> layoutModel) {
 // save off the existing layoutModel
 this.layoutModel = layoutModel;
 // create a LayoutModel to hold points for the transition
 this.transitionLayoutModel =
   LoadingCacheLayoutModel.<N>builder()
     .setGraph(visualizationServer.getModel().getNetwork().asGraph())
     .setLayoutModel(layoutModel)
     .setInitializer(layoutModel)
     .build();
 // start off the transitionLayoutModel with the endLayoutAlgorithm
 transitionLayoutModel.accept(endLayoutAlgorithm);
}

代码示例来源:origin: com.google.guava/guava-tests

String edgeString = networkString.substring(edgeStart);
Graph<N> asGraph = network.asGraph();
AbstractGraphTest.validateGraph(asGraph);
assertThat(network.nodes()).isEqualTo(asGraph.nodes());

相关文章