0

Right now I have a GraphML file that was built by writing out a JUNG DelegateTree graph using JUNG's GraphMLWriter. I'm trying to now read that file back into a new DelegateTree. When using GraphMLReader, you cannot read into a tree type (you get "use addChild() to add vertices" exceptions). So, I read the file into a DirectedGraph.

Now how do I convert that DirectedGraph into my desired DelegateTree type. I need it in this type for various reasons, mainly for display purposes. Thanks.

Smitty
  • 403
  • 2
  • 11

1 Answers1

0

DelegateTree has a constructor that allows you to specify the DirectedGraph to which it delegates: http://jung.sourceforge.net/doc/api/edu/uci/ics/jung/graph/DelegateTree.html

Joshua O'Madadhain
  • 2,704
  • 1
  • 14
  • 18
  • I've tried that and unfortunately it doesn't work. Right now I'm manually building my tree from the directed graph and was hoping there was an easier way. – Smitty Aug 09 '13 at 13:28
  • Sorry, it gives null pointer exceptions. Maybe (Probably) I'm missing something fundamental. I used: `new DelegateTree(myDirectedGraph)` to create it. – Smitty Aug 09 '13 at 15:45
  • I should specify that the null pointer exceptions came when trying to use the new DelegateTree. – Smitty Aug 09 '13 at 15:58
  • Stack trace? (Or "traces"if it's happening in multiple places.) – Joshua O'Madadhain Aug 09 '13 at 16:36
  • I think the problem is that the constructor doesn't set the root node. When I manually call setRoot(root) it is working. But it doesn't make sense that you pass a graph to a constructor that "Assumes that graph is already a tree" and it doesn't set the root? Weird. Plus unless you go through the entire graph you wouldn't know what the root is yourself. – Smitty Aug 09 '13 at 16:58
  • Ah, I see. That's a good point. I agree that DelegateTree should probably try to set the root, and probably throw if the answer is ambiguous (should be exactly one root candidate unless the graph is empty). Thanks for pointing this out. – Joshua O'Madadhain Aug 09 '13 at 21:55