Java Code Examples for org.jgrapht.Graphs#addAllEdges()

The following examples show how to use org.jgrapht.Graphs#addAllEdges() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphFunctions.java    From symja_android_library with GNU General Public License v3.0 6 votes vote down vote up
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
	try {
		if (ast.isAST1()) {
			GraphExpr<ExprEdge> gex = createGraph(ast.arg1());
			if (gex == null) {
				return F.NIL;
			}
			Graph<IExpr, ExprEdge> g = gex.toData();
			SpanningTreeAlgorithm<ExprEdge> k = new BoruvkaMinimumSpanningTree<IExpr, ExprEdge>(g);
			Set<ExprEdge> edgeSet = k.getSpanningTree().getEdges();
			Graph<IExpr, ExprEdge> gResult = new DefaultDirectedGraph<IExpr, ExprEdge>(ExprEdge.class);
			Graphs.addAllEdges(gResult, g, edgeSet);
			return GraphExpr.newInstance(gResult);
		}
	} catch (RuntimeException rex) {
		if (FEConfig.SHOW_STACKTRACE) {
			rex.printStackTrace();
		}
	}
	return F.NIL;
}
 
Example 2
Source File: GlyphCluster.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Extract a subgraph limited to the provided collection of glyphs.
 *
 * @param collection the provided collection of glyphs
 * @param graph      the global graph to extract from
 * @param checkEdges true if glyph edges may point outside the provided set.
 * @return the graph limited to glyph set and related edges
 */
public static SimpleGraph<Glyph, GlyphLink> getSubGraph (Collection<Glyph> collection,
                                                         SimpleGraph<Glyph, GlyphLink> graph,
                                                         boolean checkEdges)
{
    // Which edges should be extracted for this set?
    Set<GlyphLink> setEdges = new LinkedHashSet<>();
    for (Glyph glyph : collection) {
        Set<GlyphLink> glyphEdges = graph.edgesOf(glyph);

        if (!checkEdges) {
            setEdges.addAll(glyphEdges); // Take all edges
        } else {
            // Keep only the edges that link within the set
            for (GlyphLink link : glyphEdges) {
                Glyph opposite = Graphs.getOppositeVertex(graph, link, glyph);

                if (collection.contains(opposite)) {
                    setEdges.add(link);
                }
            }
        }
    }
    SimpleGraph<Glyph, GlyphLink> subGraph = new SimpleGraph<>(GlyphLink.class);
    Graphs.addAllVertices(subGraph, collection);
    Graphs.addAllEdges(subGraph, graph, setEdges);
    return subGraph;
}
 
Example 3
Source File: GamaSpatialGraph.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public GamaSpatialGraph copy(final IScope scope) {
	final GamaSpatialGraph g = new GamaSpatialGraph(GamaListFactory.EMPTY_LIST, true, directed, vertexRelation,
			edgeSpecies, scope, type.getKeyType(), type.getContentType());

	Graphs.addAllVertices(g, this.getVertices());
	Graphs.addAllEdges(g, this, this.edgeSet());
	return g;
}
 
Example 4
Source File: GamaGraph.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public IPath getCircuit(final IScope scope) {
	final SimpleWeightedGraph g = new SimpleWeightedGraph(getEdgeFactory());
	Graphs.addAllEdges(g, this, edgeSet());
	final List vertices = HamiltonianCycle.getApproximateOptimalForCompleteGraph(g);
	final int size = vertices.size();
	final IList edges = GamaListFactory.create(getGamlType().getContentType());
	for (int i = 0; i < size - 1; i++) {
		edges.add(this.getEdge(vertices.get(i), vertices.get(i + 1)));
	}
	return pathFromEdges(scope, null, null, edges);
}
 
Example 5
Source File: GamaGraph.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public IGraph copy(final IScope scope) {
	final GamaGraph g = new GamaGraph(scope, GamaListFactory.EMPTY_LIST, true, directed, vertexRelation,
			edgeSpecies, type.getKeyType(), type.getContentType());

	Graphs.addAllVertices(g, this.getVertices());
	Graphs.addAllEdges(g, this, this.edgeSet());
	return g;
}