我在 HGraph 类中有一个如下所示的超图结构
Map<HEdge, ArrayList<HVertex>> hGraph = new HashMap<HEdge, ArrayList<HVertex>>();
并希望使用以下函数打印所有 (key, value) 对。但我得到的只是:
Hypergraph:
e4(2.0)[]
e3(2.0)[]
e1(3.0)[]
e2(2.0)[]
e5(2.0)[]
[] 里面什么都没有,甚至没有我用于调试的“#”符号!我还覆盖了 HEdge 和 HVertex 类中的 toString 方法来打印它们的标签。
public void printHGraph(HGraph hGraph) {
Set<HEdge> edges = hGraph.getAllHEdges();
HEdge edge;
HVertex vertex;
ArrayList<HVertex> edge_vertices;
System.out.println("Hypergraph:");
Iterator<HEdge> edge_iterator = edges.iterator();
while(edge_iterator.hasNext()) {
edge = edge_iterator.next();
System.out.print(edge.toString());
System.out.print("[");
edge_vertices = hGraph.getHVertices(edge);
Iterator<HVertex> vertex_iterator = edge_vertices.iterator();
while(vertex_iterator.hasNext()) {
System.out.print("#"); //@debug
vertex = vertex_iterator.next();
System.out.print(vertex.toString()+", ");
}
System.out.print("]");
System.out.println();
}