我有一个使用创建的有向图:
public static DirectedGraph<Point, DefaultEdge> directedGraph = new DefaultDirectedGraph<Point, DefaultEdge>(DefaultEdge.class);
void setup() {
Point myPoint = new Point(x, y);
Point myNextPoint = new Point(xToFillNext, yToFillNext);
directedGraph.addVertex(myPoint);
directedGraph.addVertex(myNextPoint);
directedGraph.addEdge(myPoint, myNextPoint);
Point mySecondPoint = new Point(x, y);
Point mySecondNextPoint = new Point(xToFillNext, yToFillNext);
directedGraph.addVertex(mySecondPoint);
directedGraph.addVertex(mySecondNextPoint);
directedGraph.addEdge(mySecondPoint, mySecondNextPoint);
System.out.println("#vertices: "+ directedGraph.vertexSet());
}
public static class Point {
public int x;
public int y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
@Override
public String toString() {
return ("[x="+x+" y="+y+"]");
}
@Override
public int hashCode() {
int hash = 7;
hash = 71 * hash + this.x;
hash = 71 * hash + this.y;
return hash;
}
@Override
public boolean equals(Object other)
{
if (this == other)
return true;
if (!(other instanceof Point))
return false;
Point otherPoint = (Point) other;
return otherPoint.x == x && otherPoint.y == y;
}
}
我想使用以下方法获取每个顶点的向外边数:
directedGraph.outDegreeOf()
但我不想每个顶点都做一个顶点(这是一个简单的代码,可以更容易地通过它,在我的整个程序中我有更多的顶点)并且我想通过顶点集并返回无论有多少顶点,集合中每个顶点的向外边的数量都会自动计算。
我应该如何继续这样做?
(我使用基于java的处理)