我使用DefaultDirectedGraph创建有向图,其中每个顶点都是一个对象。
DefaultDirectedGraph g=新DefaultDirectedGraph(DefaultEdge.class);
我想知道是否有可能刻画这些边缘?例如,我想保留学生之间友谊的信息。
或者我应该在友谊的边缘和对象之间画一张地图?
发布于 2018-03-19 21:12:05
你当然可以在边缘存储信息。下面是我最近用过的一种用法:
public class Intersection{
    public final long latitude;
    public final long longitude;
    public Intersection(long latitude, long longitude){ ...}
}
public class Street extends DefaultWeightedEdge{
    public final String streetName;
    public final int speedLimit;
    public final Street(...){...}
}
public class RoadNetwork{
    public final Graph<Intersection, Street> network=new DefaultDirectedGraph<>(Street.class);
    Intersection i1=new Intersection(..);
    Intersection i2=new Intersection(..);
    Street s=new Street(..);
    //Network with 1 street
    network.addVertex(i1);
    network.addVertex(i2);
    network.addEdge(i1,i2,s);
}备注:
https://stackoverflow.com/questions/49344537
复制相似问题