本文整理汇总了Java中org.jgrapht.graph.Subgraph类的典型用法代码示例。如果您正苦于以下问题:Java Subgraph类的具体用法?Java Subgraph怎么用?Java Subgraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Subgraph类属于org.jgrapht.graph包,在下文中一共展示了Subgraph类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: induce
import org.jgrapht.graph.Subgraph; //导入依赖的package包/类
/**
* Induce subgraph from super network.
*/
public static UndirectedGraph<HNode, DefaultEdge>
induce(Set<HNode> nodeSubset, SuperNetwork superNetwork) {
// Verify whether entire subset is present in super network.
for(HNode node: nodeSubset) {
if(!superNetwork.graph.containsVertex(node)) {
System.err.println("Sub network node " + node +
" not contained by super network.");
}
}
Graph<HNode, DefaultEdge> subGraph =
new Subgraph(superNetwork.graph, nodeSubset);
return new UndirectedSubgraph(superNetwork.graph,
subGraph.vertexSet(),
subGraph.edgeSet());
}
示例2: toGraph
import org.jgrapht.graph.Subgraph; //导入依赖的package包/类
/**
*
* @param connectedOnly if true, the result will be a connected graph
* @return
*/
public Graph<V,E> toGraph(){
if(subgraph != null) return subgraph;
if(directed){
subgraph = new DirectedMultigraph<V,E>(g2.getEdgeFactory());
} else {
subgraph = new Multigraph<V,E>(g2.getEdgeFactory());
}
E edge;
V source;
V target;
for(int x=0;x<dimx;x++){
for(int y=0;y<dimy;y++){
if(matrix[x][y]){
edge = edgeList2.get(y);
source = g2.getEdgeSource(edge);
target = g2.getEdgeTarget(edge);
if(mappedVerticesFromG2.contains(source) && mappedVerticesFromG2.contains(target)){
//make sure the source and target vertices have been added, then add the edge
subgraph.addVertex(source);
subgraph.addVertex(target);
subgraph.addEdge(source, target, edge);
}
}
}
}
if(connectedOnly){
//make sure this subgraph is connected, if it is not return the largest connected part
List<Set<V>> connectedVertices = new ArrayList<Set<V>>();
for(V v : subgraph.vertexSet()){
if(!SharedStaticMethods.containsV(connectedVertices, v)){
connectedVertices.add(SharedStaticMethods.getConnectedVertices(subgraph, v));
}
}
//ConnectedVertices now contains Sets of connected vertices every vertex of the subgraph is contained exactly once in the list
//if there is more then 1 set, then this method should return the largest connected part of the graph
if(connectedVertices.size() > 1){
Graph<V,E> largestResult = null;
Graph<V,E> currentGraph;
int largestSize = -1;
Set<V> currentSet;
for(int i=0;i<connectedVertices.size();i++){
currentSet = connectedVertices.get(i);
/*note that 'subgraph' is the result from the Mcgregor algorithm, 'currentGraph' is an
* induced subgraph of 'subgraph'. 'currentGraph' is connected, because the vertices in
* 'currentSet' are connected with edges in 'subgraph'
*/
currentGraph = new Subgraph<V,E,Graph<V,E>>(subgraph, currentSet);
if(currentGraph.edgeSet().size() > largestSize){
largestResult = currentGraph;
}
}
return largestResult;
}
}
return subgraph;
}