问题描述
我正在jgrapht
中使用Java
来工作基于网络的算法。我先阅读一个邻接表,然后创建基于jgrapht
的图。现在,给定一个名为subNodes
的节点子集,我想生成一个子图。我正在尝试使用this link所示的Subgraph
类,但是我无法使用它。
import org.jgrapht.*;
import org.jgrapht.graph.*;
......
HashMap<Integer,HashSet<Integer>> adjacencyList = new HashMap<Integer,HashSet<Integer>>();
\\fill out adjacency list
\\create your graph
Graph<Integer,DefaultEdge> myGraph = new SimpleGraph<>(DefaultEdge.class);
int numNodes = ...;
for(int i = 0 ; i <numNodes; i++)
myGraph.addVertex(i);
for(int i = 0 ; i< numNodes; i++) {
if(adjacencyList.get(i) != null) {
for(Integer j : adjacencyList.get(i)) {
myGraph.addEdge(i,j);
}
}
}
Set<Integer> subNodes = new HashSet<Integer>();
\\generate a sub set of vertices to have a subgprah
一个类似的帖子是here,但这也没有帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)