本文整理匯總了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;
}