我想知道从SimpleWeightedGraph库中扩展JgraphT的正确方法,这样我就可以使用一个简化的别名,并在需要时还包括额外的功能。
而不是每次创建一个新的图表
SimpleWeightedGraph<Node, DefaultWeightedEdge> graph
= new SimpleWeightedGraph<Node, DefaultWeightedEdge>(DefaultWeightedEdge.class);我创建了一个类
public class CustomGraph extends SimpleWeightedGraph<Node, DefaultWeightedEdge>{
public CustomGraph(){
super(DefaultWeightedEdge.class);
}
/*Additional custom methods*/
}这样我就可以使用
CustomGraph graph = new CustomGraph();但这似乎并没有创建这个对象。我是否遗漏了其他构造函数?
发布于 2015-06-16 09:21:47
好吧我想明白了。下面是必须包含的边界工厂构造函数的类。
public class CustomGraph extends SimpleWeightedGraph<Node, DefaultWeightedEdge>{
/**
* Creates a new simple weighted graph with the specified edge factory.
*
* @param ef the edge factory of the new graph.
*/
public CustomGraph(EdgeFactory<Node, DefaultWeightedEdge> ef)
{
super(ef);
}
/**
* Creates a new simple weighted graph.
*
* @param edgeClass class on which to base factory for edges
*/
public CustomGraph(Class<? extends DefaultWeightedEdge> edgeClass)
{
this(new ClassBasedEdgeFactory<Node, DefaultWeightedEdge>(edgeClass));
}
}https://stackoverflow.com/questions/30784655
复制相似问题