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

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

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

Graph.addVertex介绍

[英]Creates a new vertex in this graph and returns it.

This method creates the new vertex v using this graph's vertex supplier (see #getVertexSupplier()). For the new vertex to be added v must not be equal to any other vertex in the graph. More formally, the graph must not contain any vertex v2 such that v2.equals(v). If such v2 is found then the newly created vertex v is abandoned, the method leaves this graph unchanged and throws an IllegalArgumentException.

If the underlying graph implementation's #getVertexSupplier() returns null, then this method cannot create vertices and throws an UnsupportedOperationException.

Care must also be taken when interchanging calls to methods Graph#addVertex(Object)and Graph#addVertex(). In such a case the user must make sure never to add vertices in the graph using method Graph#addVertex(Object), which are going to be returned in the future by the supplied vertex supplier. Such a sequence will result into an IllegalArgumentException when calling method Graph#addVertex().
[中]在此图中创建一个新顶点并返回它。
此方法使用此图的顶点供应器(请参见#getVertexSupplier())创建新顶点v。对于要添加的新顶点,v不得等于图形中的任何其他顶点。更正式地说,图形不能包含任何顶点v2,这样v2.equals(v)。如果找到这样的v2,那么新创建的顶点v将被放弃,该方法将保持此图不变,并抛出IllegalArgumentException。
如果基础图形实现的#getVertexSupplier()返回null,则此方法无法创建顶点并引发UnsupportedOperationException。
在交换对方法Graph#addVertex(Object)和Graph#addVertex()的调用时也必须小心。在这种情况下,用户必须确保永远不要使用graph#addVertex(Object)方法在图中添加顶点,这些顶点将在将来由提供的顶点供应商返回。调用方法Graph#addVertex()时,这样的序列将导致IllegalArgumentException。

代码示例

代码示例来源:origin: mulesoft/mule

private void addType(ErrorTypeDefinition<?> errorType,
           Graph<ErrorTypeDefinition, Pair<ErrorTypeDefinition, ErrorTypeDefinition>> graph) {
 graph.addVertex(errorType);
 String type = errorType.getType();
 if (!ANY.name().equals(type) && !CRITICAL.name().equals(type)) {
  ErrorTypeDefinition parentErrorType = errorType.getParent().orElse((ANY));
  graph.addVertex(parentErrorType);
  graph.addEdge(errorType, parentErrorType);
 }
}

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

/**
 * {@inheritDoc}
 */
@Override
public boolean addVertex(V v)
{
  return delegate.addVertex(v);
}

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

/**
   * {@inheritDoc}
   */
  @Override
  public void generateGraph(Graph<V, E> target, Map<String, V> resultMap)
  {
    for (int i = 0; i < size; ++i) {
      target.addVertex();
    }
  }
}

代码示例来源:origin: cwensel/cascading

public boolean addVertex( FlowElement flowElement )
 {
 return graph.addVertex( flowElement );
 }

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

private V addVertex(Graph<V, E> targetGraph, int i)
{
  if (!vertexMap.containsKey(i)) {
    vertexMap.put(i, targetGraph.addVertex());
  }
  return vertexMap.get(i);
}

代码示例来源:origin: Audiveris/audiveris

/**
 * Insert a new peak right before an existing one.
 *
 * @param toInsert the new peak to insert
 * @param before   the existing peak before which insertion must be done
 */
public void insertPeak (StaffPeak toInsert,
            StaffPeak before)
{
  int index = peaks.indexOf(before);
  if (index == -1) {
    throw new IllegalArgumentException("insertPeak() before a non-existing peak");
  }
  peaks.add(index, toInsert);
  peakGraph.addVertex(toInsert);
}

代码示例来源:origin: org.aksw.jena-sparql-api/jena-sparql-api-algebra

public static void addEdge(org.jgrapht.Graph<Node, LabeledEdge<Node, Node>> graph, Node edgeLabel, Node source, Node target) {
  graph.addVertex(source);
  graph.addVertex(target);
  graph.addEdge(source, target, new LabeledEdgeImpl<>(source, target, edgeLabel));
}

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

public static void addEdge(org.jgrapht.Graph<Node, LabeledEdge<Node, Node>> graph, Node edgeLabel, Node source, Node target) {
  graph.addVertex(source);
  graph.addVertex(target);
  graph.addEdge(source, target, new LabeledEdgeImpl<>(source, target, edgeLabel));
}

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

/**
 * Adds {@code vertex} to the graph being built.
 *
 * @param vertex the vertex to add
 *
 * @return this builder object
 *
 * @see Graph#addVertex(Object)
 */
public B addVertex(V vertex)
{
  this.graph.addVertex(vertex);
  return this.self();
}

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

/**
 * {@inheritDoc}
 */
@Override
public V addVertex()
{
  /*
   * Use our own vertex supplier, if provided.
   */
  if (vertexSupplier != null) {
    V v = vertexSupplier.get();
    return this.addVertex(v) ? v : null;
  }
  return delegate.addVertex();
}

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

private void generateNonSimpleRegularGraph(Graph<V, E> target)
{
  List<V> vertices = new ArrayList<>(n * d);
  for (int i = 0; i < n; i++) {
    V vertex = target.addVertex();
    for (int j = 0; j < d; j++) {
      vertices.add(vertex);
    }
  }
  Collections.shuffle(vertices, rng);
  for (int i = 0; i < (n * d) / 2; i++) {
    V u = vertices.get(2 * i);
    V v = vertices.get(2 * i + 1);
    target.addEdge(u, v);
  }
}

代码示例来源:origin: cwensel/cascading

@Override
public boolean addHeadVertex( FlowElement flowElement )
 {
 if( !graph.containsVertex( Extent.head ) )
  graph.addVertex( Extent.head );
 if( flowElement == Extent.head )
  return false;
 boolean result = true;
 if( !graph.containsVertex( flowElement ) )
  result = graph.addVertex( flowElement );
 return result && graph.addEdge( Extent.head, flowElement ) != null;
 }

代码示例来源:origin: cwensel/cascading

@Override
public boolean addTailVertex( FlowElement flowElement )
 {
 if( !graph.containsVertex( Extent.tail ) )
  graph.addVertex( Extent.tail );
 if( flowElement == Extent.tail )
  return false;
 boolean result = true;
 if( !graph.containsVertex( flowElement ) )
  result = graph.addVertex( flowElement );
 return result && graph.addEdge( flowElement, Extent.tail ) != null;
 }

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

public void processPrimitivePath(Path path) {
  D edgeLabel = primitivePathMapper.apply(path);
  V s = vertexFactory.get();
  graph.addVertex(s);
  PartialNfa<V, D> partialNfa = PartialNfa.create(s, Collections.singletonList(new HalfEdge<V, D>(s, edgeLabel)));
  stack.push(partialNfa);
}

代码示例来源:origin: Galigator/openllet

@Override
protected void initialize()
{
  _equivalents = CollectionUtils.makeIdentityMap();
  _graph = new DefaultDirectedGraph<>(DefaultEdge.class);
  _graph.addVertex(TOP);
  for (final ATermAppl c : _kb.getClasses())
    _graph.addVertex(c);
}

代码示例来源:origin: Galigator/openllet

@Override
protected void initialize()
{
  _equivalents = CollectionUtils.makeIdentityMap();
  _graph = new DefaultDirectedGraph<>(DefaultEdge.class);
  _graph.addVertex(TOP);
  for (final ATermAppl c : _kb.getClasses())
    _graph.addVertex(c);
}

代码示例来源:origin: org.mule.runtime/mule-module-extensions-support

private void addType(ErrorTypeDefinition<?> errorType,
           Graph<ErrorTypeDefinition, Pair<ErrorTypeDefinition, ErrorTypeDefinition>> graph) {
 graph.addVertex(errorType);
 String type = errorType.getType();
 if (!ANY.name().equals(type) && !CRITICAL.name().equals(type)) {
  ErrorTypeDefinition parentErrorType = errorType.getParent().orElse((ANY));
  graph.addVertex(parentErrorType);
  graph.addEdge(errorType, parentErrorType);
 }
}

代码示例来源:origin: io.github.oliviercailloux.jmcda/utils

static public <V, E> void copyTo(Graph<V, E> source, Graph<V, E> target) {
  for (V vertex : source.vertexSet()) {
    target.addVertex(vertex);
  }
  for (E edge : source.edgeSet()) {
    final boolean added = target.addEdge(source.getEdgeSource(edge), source.getEdgeTarget(edge), edge);
    if (!added) {
      throw new IllegalArgumentException("Target graph does not support addition of (some) source edges.");
    }
  }
}

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

private Pair<V, Graph<V, E>> createSingleRootGraph(Graph<V, E> forest, Set<V> roots)
{
  Graph<V, E> freshForest = GraphTypeBuilder.forGraph(forest).weighted(false).buildGraph();
  roots.forEach(freshForest::addVertex);
  V freshVertex = freshForest.addVertex();
  for (V root : roots)
    freshForest.addEdge(freshVertex, root);
  return Pair.of(freshVertex, new AsGraphUnion<>(freshForest, forest));
}

代码示例来源:origin: SmartDataAnalytics/DL-Learner

private void buildGraph(Graph<Vertex, Edge> graph, QueryTree<N> tree){
  PrefixCCMap prefixes = PrefixCCMap.getInstance();
  List<QueryTree<N>> children = tree.getChildren();
  Vertex parent = new Vertex(tree.getId(), prefixed(prefixes, tree.getUserObject().toString()));
  graph.addVertex(parent);
  for (QueryTree<N> child : children) {
    Vertex childVertex = new Vertex(child.getId(), prefixed(prefixes, child.getUserObject().toString()));
    graph.addVertex(childVertex);
    Edge edge = new Edge(Long.parseLong(parent.getId() + "0" + childVertex.getId()), prefixed(prefixes, tree.getEdge(child).toString()));
    graph.addEdge(parent, childVertex, edge);
    buildGraph(graph, child);
  }
}

相关文章