public class UniformFAH extends SetHypergraph<HV, HE> {
...........
public DelegateTree<UUID,HOuterEdge> spanningTree() {
UndirectedSparseGraph<UUID, HOuterEdge> g = new UndirectedSparseGraph<>();
HashSet<UUID> dbg = new HashSet<>();
for(HE e : this.getEdges()) {
if (e.type!=HE.EdgeType.OUTER) continue;
HOuterEdge oe = ((HOuterEdge)e);
UUID v1 = oe.solidId;
UUID v2 = oe.solidId2;
dbg.add(v1);
dbg.add(v2);
g.addEdge(oe, v1, v2);
}
PrimMinimumSpanningTree<UUID, HOuterEdge> mst =
new PrimMinimumSpanningTree<>(new Factory<UndirectedSparseGraph<UUID, HOuterEdge>>() {
@Override
public UndirectedSparseGraph<UUID, HOuterEdge> create() {
return new UndirectedSparseGraph<>();
}
});
UndirectedSparseGraph<UUID, HOuterEdge> st = (UndirectedSparseGraph<UUID, HOuterEdge>) mst.transform(g);
UUID root = null;
int maxdeg = 0;
for(UUID v : st.getVertices()) {
if (st.getNeighborCount(v) > maxdeg) {
maxdeg = st.getNeighborCount(v);
root = v;
}
}
DelegateTree<UUID,HOuterEdge> ret = new DelegateTree<>();
ret.addVertex(root);
LinkedList<UUID> tmp = new LinkedList<>();
tmp.add(root);
while (!tmp.isEmpty()) {
UUID v = tmp.poll();
for(UUID w : st.getNeighbors(v)) {
if (!ret.containsVertex(w) && !tmp.contains(w)) tmp.add(w);
if (!ret.containsVertex(w))
ret.addChild(st.findEdge(v, w), v, w);
}
}
return ret;
}
...........
}
… generates the following exception:
Generating spaning tree...Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.StackOverflowError
at java.util.HashMap.removeEntryForKey(HashMap.java:561)
at java.util.HashMap.remove(HashMap.java:551)
at java.util.HashSet.remove(HashSet.java:233)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:111)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
at edu.uci.ics.jung.algorithms.shortestpath.PrimMinimumSpanningTree.updateTree(PrimMinimumSpanningTree.java:113)
etc.
Do you have any idea what's wrong?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You've included enough code to make it hard to grasp all of it, but not enough to actually debug anything. :(
I don't understand what problem you're trying to solve, either.
I mean, you're getting a StackOverflowException, that's clear (the InvocationTargetException appears to be a bit of a red herring). But I don't understand what relation, if any, your hypergraph and your delegate tree bear to one another, for starters.
Joshua
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My hypergraph, say H=(V,E_h, E_o), contains two types of edges: hyperedges (E_h) and outer edges (E_o) which always have exactly two mutually exclusive endpoints.
In my actual problem I neglect hyperedges (E_h) and focus on the E_o edges only. Thus subgraph $G \subset H$ such that G=(V,E_o) is the regular graph (not hyper), for which I want to find a spanning tree. That's all.
I've fixed the problem by implementing Prim's algorithm.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the clarification. In your case I would have recommended filtering and transforming the original graph to give you the graph that you actually want to process, i.e., G = (V, E_o).
Better still, maintain two separate graphs over the same vertex set, one with E_h and the other with E_o. Keeping them in the same graph is only useful if you actually want to treat both kinds of edges as, in some sense, equivalent.
Anyway, glad your problem is solved.
Joshua
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all!
The following method…
… generates the following exception:
Do you have any idea what's wrong?
Adam:
You've included enough code to make it hard to grasp all of it, but not enough to actually debug anything. :(
I don't understand what problem you're trying to solve, either.
I mean, you're getting a StackOverflowException, that's clear (the InvocationTargetException appears to be a bit of a red herring). But I don't understand what relation, if any, your hypergraph and your delegate tree bear to one another, for starters.
Joshua
My hypergraph, say H=(V,E_h, E_o), contains two types of edges: hyperedges (E_h) and outer edges (E_o) which always have exactly two mutually exclusive endpoints.
In my actual problem I neglect hyperedges (E_h) and focus on the E_o edges only. Thus subgraph $G \subset H$ such that G=(V,E_o) is the regular graph (not hyper), for which I want to find a spanning tree. That's all.
I've fixed the problem by implementing Prim's algorithm.
Adam:
Thanks for the clarification. In your case I would have recommended filtering and transforming the original graph to give you the graph that you actually want to process, i.e., G = (V, E_o).
Better still, maintain two separate graphs over the same vertex set, one with E_h and the other with E_o. Keeping them in the same graph is only useful if you actually want to treat both kinds of edges as, in some sense, equivalent.
Anyway, glad your problem is solved.
Joshua