本文整理汇总了Java中org.jgrapht.graph.DirectedSubgraph类的典型用法代码示例。如果您正苦于以下问题:Java DirectedSubgraph类的具体用法?Java DirectedSubgraph怎么用?Java DirectedSubgraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DirectedSubgraph类属于org.jgrapht.graph包,在下文中一共展示了DirectedSubgraph类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intersect
import org.jgrapht.graph.DirectedSubgraph; //导入依赖的package包/类
@Override
public DirectedGraph<Node, Triple> intersect(DirectedGraph<Node, Triple> baseGraph, DirectedGraph<Node, Triple> removalGraph) {
DirectedGraph<Node, Triple> result = new DirectedSubgraph<>(baseGraph, removalGraph.vertexSet(), removalGraph.edgeSet());
//Materialize the intersection
//DirectedGraph<Node, Triple> tmp = createNew();
//Graphs.addGraph(tmp, result);
//result = tmp
return result;
}
示例2: sortChanges
import org.jgrapht.graph.DirectedSubgraph; //导入依赖的package包/类
/**
* Sorts the graph to provide a consistent topological ordering.
*
* @param graph The input graph
* @param subsetVertices The subset vertices of the graph we want to sort
* @param comparator The comparator on which to order the vertices to guarantee a consistent topological ordering
*/
public <T> ImmutableList<T> sortChanges(DirectedGraph<T, DefaultEdge> graph, RichIterable<T> subsetVertices, Comparator<? super T> comparator) {
if (subsetVertices.toSet().size() != subsetVertices.size()) {
throw new IllegalStateException("Unexpected state - have some dupe elements here: " + subsetVertices);
}
DirectedGraph<T, DefaultEdge> subsetGraph = new DirectedSubgraph<T, DefaultEdge>(
graph, subsetVertices.toSet(), null);
// At one point, we _thought_ that the DirectedSubGraph was dropping vertices that don't have edges, so we
// manually add them back to the graph to ensure that we can still order them.
// However, that no longer seems to be the case. We add a check here just in case this comes up again.
if (subsetVertices.size() != subsetGraph.vertexSet().size()) {
throw new IllegalArgumentException("This case should never happen! [subsetVertices: " + subsetVertices + ", subsetGraphVertices: " + subsetGraph.vertexSet());
}
return sortChanges(subsetGraph, comparator);
}
示例3: getSubGraph
import org.jgrapht.graph.DirectedSubgraph; //导入依赖的package包/类
/**
* @param base
* the graph to create a subgraph from.
* @param vertexSubSet
* the vertices to include in the subgraph
* @return a subgraph based on the base graph
* @throws NotAJGraphTAdapterException
* if the base graph is not a JGraphT library
*/
@Override
public Graph<V> getSubGraph(final Graph<V> base, final Set<V> vertexSubSet)
throws NotAJGraphTAdapterException {
if (base instanceof JGraphTGraphAdapter) {
JGraphTGraphAdapter<V> baseGraph = (JGraphTGraphAdapter<V>) base;
return new JGraphTGraphAdapter<V>(
new DirectedSubgraph<V, DefaultEdge>(
baseGraph.getInternalGraph(), vertexSubSet, null),
edgeFact, baseGraph.getVertexIdentifiers());
} else {
throw new NotAJGraphTAdapterException();
}
}
示例4: getSubgraphOfClass
import org.jgrapht.graph.DirectedSubgraph; //导入依赖的package包/类
private DirectedSubgraph<CodeElement, CodeElemetEdge> getSubgraphOfClass(ClassInfo classInfo) {
Set<CodeElemetEdge> edgeSubset = directedGraph.edgeSet().stream().filter(edge -> edge.isWithinClass(classInfo))
.collect(Collectors.toSet());
Set<CodeElement> vertexSubset = edgeSubset.stream()
.flatMap(edge -> Stream.of(edge.getSourceElement(), edge.getTargetElement()))
.collect(Collectors.toSet());
return new DirectedSubgraph<>(directedGraph, vertexSubset, edgeSubset);
}
示例5: getStronglyConnectedComponents
import org.jgrapht.graph.DirectedSubgraph; //导入依赖的package包/类
/**
* Constructs a list of NFA graphs each representing a strongly connected
* component in the graph given as parameter.
*
* @param m
* The NFA graph to find the strongly connected components in.
* @return A list containing all the strongly connected components.
* @throws InterruptedException
*/
public static LinkedList<NFAGraph> getStronglyConnectedComponents(NFAGraph m) throws InterruptedException {
StrongConnectivityInspector<NFAVertexND, NFAEdge> sci = new StrongConnectivityInspector<NFAVertexND, NFAEdge>(m);
List<DirectedSubgraph<NFAVertexND, NFAEdge>> sccs = sci.stronglyConnectedSubgraphs();
LinkedList<NFAGraph> sccNFAs = new LinkedList<NFAGraph>();
for (DirectedSubgraph<NFAVertexND, NFAEdge> scc : sccs) {
if (isInterrupted()) {
throw new InterruptedException();
}
/* scc's consisting of no edges are irrelevant for our purpose */
if (scc.edgeSet().size() > 0) {
NFAGraph currentNFAG = new NFAGraph();
for (NFAVertexND v : scc.vertexSet()) {
if (isInterrupted()) {
throw new InterruptedException();
}
currentNFAG.addVertex(v);
}
for (NFAEdge e : scc.edgeSet()) {
if (isInterrupted()) {
throw new InterruptedException();
}
currentNFAG.addEdge(e);
}
sccNFAs.add(currentNFAG);
}
}
return sccNFAs;
}
示例6: traverseDepdendencyCycles
import org.jgrapht.graph.DirectedSubgraph; //导入依赖的package包/类
private static <V, E> void traverseDepdendencyCycles(GraphVisitor<V, E> cyclesVisitor, DirectedGraph<V, E> graph) {
StrongConnectivityAlgorithm<V, E> inspector = new GabowStrongConnectivityInspector<>(graph);
List<DirectedSubgraph<V, E>> cycleGraphs = inspector.stronglyConnectedSubgraphs();
int index = 1;
ExtendedDirectedGraph<V, E> traversalGraph;
for (DirectedSubgraph<V, E> subgraph : cycleGraphs) {
if (subgraph.vertexSet().size() > 1) {// ignore dependency cycles within one vertex (these cycles have no impact in software design)
traversalGraph = new ExtendedDirectedGraph<V, E>(subgraph);
cyclesVisitor.visitGraph(traversalGraph, index);
traversalGraph.traverseDepthFirst(null, cyclesVisitor, false);
index++;
}
}
}
示例7: createSubgraphView
import org.jgrapht.graph.DirectedSubgraph; //导入依赖的package包/类
public static <V, E> GraphView<V, E> createSubgraphView(ExtendedDirectedGraph<V, E> graph, Set<V> vertices, boolean reversed) {
if (vertices == null && reversed == false) {
return graph;
}
if (reversed) {
return new ExtendedDirectedGraph<V, E>(
new EdgeReversedGraph<V, E>(new DirectedSubgraph<V, E>(graph.getDelegate(), vertices, null))
);
}
return new ExtendedDirectedGraph<V, E>(
new DirectedSubgraph<V, E>(graph.getDelegate(), vertices, null)
);
}