本文整理了Java中org.jgrapht.Graph.addEdge()
方法的一些代码示例,展示了Graph.addEdge()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.addEdge()
方法的具体详情如下:
包路径:org.jgrapht.Graph
类名称:Graph
方法名:addEdge
[英]Creates a new edge in this graph, going from the source vertex to the target vertex, and returns the created edge. Some graphs do not allow edge-multiplicity. In such cases, if the graph already contains an edge from the specified source to the specified target, than this method does not change the graph and returns null
.
The source and target vertices must already be contained in this graph. If they are not found in graph IllegalArgumentException is thrown.
This method creates the new edge e
using this graph's edge supplier (see #getEdgeSupplier()). For the new edge to be added e
must not be equal to any other edge the graph (even if the graph allows edge-multiplicity). More formally, the graph must not contain any edge e2
such that e2.equals(e)
. If such e2
is found then the newly created edge e
is abandoned, the method leaves this graph unchanged and returns null
.
If the underlying graph implementation's #getEdgeSupplier() returns null
, then this method cannot create edges and throws an UnsupportedOperationException.
[中]在此图中创建从源顶点到目标顶点的新边,并返回创建的边。有些图不允许边多重性。在这种情况下,如果图形已经包含从指定源到指定目标的边,则此方法不会更改图形并返回[$0$]。
源顶点和目标顶点必须已包含在此图中。如果在图中找不到它们,则抛出argargumentException。
此方法使用此图的边供应商(请参见#getEdgeSupplier())创建新边e
。对于要添加的新边,e
不得等于图形中的任何其他边(即使图形允许边多重性)。更正式地说,图形不能包含任何边e2
,这样e2.equals(e)
。如果找到这样的e2
,则新创建的边e
将被放弃,该方法将保持此图不变并返回null
。
如果基础图形实现的#getEdgeSupplier()返回null
,则此方法无法创建边并引发UnsupportedOperationException。
代码示例来源: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 addEdge(V sourceVertex, V targetVertex, E e)
{
return delegate.addEdge(sourceVertex, targetVertex, e);
}
代码示例来源:origin: Galigator/openllet
@Override
protected void addUses(final ATermAppl c, final ATermAppl usedByC)
{
if (c.equals(TOP))
addEquivalent(TOP, usedByC);
else
if (!c.equals(usedByC))
_graph.addEdge(c, usedByC);
}
代码示例来源:origin: Galigator/openllet
@Override
protected void addUses(final ATermAppl c, final ATermAppl usedByC)
{
if (c.equals(TOP))
addEquivalent(TOP, usedByC);
else
if (!c.equals(usedByC))
_graph.addEdge(c, usedByC);
}
代码示例来源:origin: org.jgrapht/jgrapht-core
/**
* {@inheritDoc}
*/
@Override
public E addEdge(V sourceVertex, V targetVertex)
{
/*
* Use our own edge supplier, if provided.
*/
if (edgeSupplier != null) {
E e = edgeSupplier.get();
return this.addEdge(sourceVertex, targetVertex, e) ? e : null;
}
return delegate.addEdge(sourceVertex, targetVertex);
}
代码示例来源: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: org.danilopianini/jirf
private <S, D> void addEdge(
final Class<S> source,
final Class<D> target,
final Function<? super S, ? extends D> implicit) {
edgeFactory.addImplicitConversion(source, target, implicit);
implicits.removeEdge(source, target);
Objects.requireNonNull(implicits.addEdge(source, target));
}
代码示例来源:origin: org.jgrapht/jgrapht-core
/**
* {@inheritDoc}
*/
@Override
public void generateGraph(Graph<V, E> target, Map<String, V> resultMap)
{
if (size < 1) {
return;
}
Map<String, V> privateMap = new HashMap<>();
new LinearGraphGenerator<V, E>(size).generateGraph(target, privateMap);
V startVertex = privateMap.get(LinearGraphGenerator.START_VERTEX);
V endVertex = privateMap.get(LinearGraphGenerator.END_VERTEX);
target.addEdge(endVertex, startVertex);
}
}
代码示例来源:origin: org.jgrapht/jgrapht-core
private void addEdge(Graph<V, E> targetGraph, int i, int j)
{
V u = addVertex(targetGraph, i);
V v = addVertex(targetGraph, j);
targetGraph.addEdge(u, v);
}
代码示例来源:origin: cwensel/cascading
public boolean addEdge( FlowElement sourceVertex, FlowElement targetVertex, Scope scope )
{
// prevent multiple edges from head or to tail
if( !allowMultipleExtentEdges() && ( sourceVertex == Extent.head || targetVertex == Extent.tail ) && graph.containsEdge( sourceVertex, targetVertex ) )
return true;
return graph.addEdge( sourceVertex, targetVertex, scope );
}
代码示例来源:origin: cwensel/cascading
public Scope addEdge( FlowElement sourceVertex, FlowElement targetVertex )
{
// prevent multiple edges from head or to tail
if( !allowMultipleExtentEdges() && ( sourceVertex == Extent.head || targetVertex == Extent.tail ) && graph.containsEdge( sourceVertex, targetVertex ) )
return graph.getEdge( sourceVertex, targetVertex );
return graph.addEdge( sourceVertex, targetVertex );
}
代码示例来源: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: 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: 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: 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: 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: org.jgrapht/jgrapht-core
@Override
protected void transformGraph(List<E> previousPath)
{
V source, target;
E reversedEdge;
// replace previous path edges with reversed edges with negative weight
for (E originalEdge : previousPath) {
source = workingGraph.getEdgeSource(originalEdge);
target = workingGraph.getEdgeTarget(originalEdge);
double originalEdgeWeight = workingGraph.getEdgeWeight(originalEdge);
workingGraph.removeEdge(originalEdge);
workingGraph.addEdge(target, source);
reversedEdge = workingGraph.getEdge(target, source);
workingGraph.setEdgeWeight(reversedEdge, -originalEdgeWeight);
}
}
代码示例来源: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);
}
}
内容来源于网络,如有侵权,请联系作者删除!