Java SmallWorldExample的实现

Java SmallWorldExample的实现,java,graph,jung,Java,Graph,Jung,我对如何实现一些JUNG类感到非常困惑。我试图用“KleinbergSmallWorldGenerator”创建一个图形,但我不确定如何正确初始化 我的代码: Factory<? extends Graph<Integer, Integer>> graph_factory; Factory<Integer> vertexFactory; Factory<Integer> edgeFactory; KleinbergSmallWorldGenera

我对如何实现一些JUNG类感到非常困惑。我试图用“KleinbergSmallWorldGenerator”创建一个图形,但我不确定如何正确初始化

我的代码:

Factory<? extends Graph<Integer, Integer>> graph_factory;
Factory<Integer> vertexFactory;
Factory<Integer> edgeFactory;

KleinbergSmallWorldGenerator<Integer,Integer> smallWorld;

public GraphView() {
    smallWorld = new KleinbergSmallWorldGenerator<Integer,Integer>(graph_factory, vertexFactory, edgeFactory, 20, 3) ;
    Graph2 = smallWorld.create();
}

工厂
图形工厂
顶点工厂
边缘工厂
在施工时均为
。这是由于他们使用

在构造函数中,我可以想象您希望传递这些对象的活动实例,而不是在无参数构造函数中初始化它们。

示例:

static class GraphFactory implements Factory<Graph<Integer,String>> {
        public Graph<Integer,String> create() {
            return new SparseMultigraph<Integer,String>();
        }
    }

    static class VertexFactory implements Factory<Integer> {
        int a = 0;
        public Integer create() {
            return a++;
        }

    }
    static class EdgeFactory implements Factory<String> {
        char aa = 'a';
        public String create() {
            return Character.toString(aa++);
        }

    }
静态类GraphFactory实现工厂{
公共图创建(){
返回新的SparMultigraph();
}
}
静态类VertexFactory实现工厂{
int a=0;
公共整数创建(){
返回一个++;
}
}
静态类EdgeFactory实现工厂{
char aa='a';
公共字符串create(){
返回字符.toString(aa++);
}
}
然后你打这个例子

Graph<Integer, String>  Eppstein = new EppsteinPowerLawGenerator<Integer,String>(new GraphFactory(), new VertexFactory(), new EdgeFactory(), 100, 400, 100).create();
Graph-Eppstein=new-EppsteinPowerLawGenerator(new-GraphFactory(),new-VertexFactory(),new-EdgeFactory(),100400100)。create();

但它们唯一的方法是create()等。我不知道使用它们作为接口的合适架构。问题是我无法访问您正在使用的API(Google fu没有帮助)。如果这些
Factory
类型是接口,那么应该有一些具体的支持来实例化它们。你必须用它来实例化它们。我真的对JUNG的东西感到困惑,这里的大多数问题都是显示问题。你需要在将工厂放入生成器之前初始化它们。