当前位置: 首页>>代码示例>>Java>>正文


Java Subgraph类代码示例

本文整理汇总了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());
}
 
开发者ID:ls-cwi,项目名称:eXamine,代码行数:21,代码来源:Network.java

示例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;
}
 
开发者ID:WellingR,项目名称:Maximal-Common-Subgraph,代码行数:68,代码来源:Marcs.java


注:本文中的org.jgrapht.graph.Subgraph类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。