Hi Justin,

That's a good suggestion, I should have added to my initial post that I run the 
process repeatedly for every edge in the main graph and the success rate goes 
substantially as more and sub-graphs have been created. But I do create new 
objects each time I try to create a sub-graph.

You got me thinking though, is it possible that there is some manipulation of 
the underlying graph going on in the background? It looks like the sub-graphs 
might be changing the underlying graph somehow (which would explain why the 
rate of success drops as more and more are created), but I can't see how they 
would be doing this. To get the subgraph I use the visited nodes and edges in 
the BasicGraph constructor, but again I don't think that this should do 
anything to the underlying graph.

Anyway if you can't think of anything I'll produce a test case.

Thanks for the help!

Nick




On 11 Aug 2011, at 15:21, Justin Deoliveira wrote:

Hi Nick,

Could it be possible that the same iterator is being used for multiple 
traversals. It maintains state internally so if it were say reused for a second 
call it would not return any graph objects since they have already been marked 
as "seen".

Other then that the only thing I can think of is the graph itself... is it 
directed?

If all else fails and you can write a test case that reproduces the problem we 
can look at it.

-Justin

On Thu, Aug 11, 2011 at 5:34 AM, Nick Malleson 
<[email protected]<mailto:[email protected]>> wrote:
Hi,

I'm having a problem with a graph traversal and I was wondering if anyone
has some suggestions.

What I want to do is quite simple: given an origin edge in a graph, I want
to create a sub-graph around the origin containing N edges. To do this I
have created a visitor (called SubGraphVisitor) which counts and records the
number of graph components it has visitted. It termines once it has visitted
N componets and can be used to create a subgraph from the components it has
seen.

The problem is that sometimes it doesn't work, the 'visit' method of my
SubGraphVisitor isn't called and so no sub-graph is created. I have checked
that paths can be created from the edge so I think the graph is correct. I
have also checked that the graph is complete.

Here is the code that does the walking:

SubGraphVisitor graphVisitor = new SubGraphVisitor(); // This is my visitor
BreadthFirstIterator iterator = new BreadthFirstIterator();
BasicGraphTraversal bgt = new BasicGraphTraversal(
       this.graph,
       new SimpleGraphWalker(graphVisitor),
       iterator);
iterator.setSource(edge1);
bgt.traverse();
Graph subGraph = graphVisitor.getSubGraph(); // Sometimes the graph is empty

Can anyone sugggest why the call to traverse() doesn't lead to my visitor's
visit() method being called? I've had a look through the source code for
BasicGraphTraversal it looks as if the iterator isn't returning a component,
but I'm not sure why this might be.

Thanks for your help,
Nick

P.S.
Thanks for all the work that has gone into gt-graph and geotools in general,
it's invaluable for my work.

--
View this message in context: 
http://osgeo-org.1803224.n2.nabble.com/Problem-iterating-over-a-graph-tp6676019p6676019.html
Sent from the geotools-gt2-users mailing list archive at 
Nabble.com<http://Nabble.com>.

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it.
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users



--
Justin Deoliveira
OpenGeo - http://opengeo.org<http://opengeo.org/>
Enterprise support for open source geospatial.



------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. 
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to