Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
DFS query optimization
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Gergely Svigruha  
View profile  
 More options Oct 6 2012, 1:53 am
From: Gergely Svigruha <sgerg...@gmail.com>
Date: Fri, 5 Oct 2012 22:53:18 -0700 (PDT)
Local: Sat, Oct 6 2012 1:53 am
Subject: DFS query optimization

Hi,

I would like to get all the nodes at most N distance from a specific node.
I use DFS with a bound for the depth. I don't want to visit a node multiple
times so I use a Set<Long> for storing the already visited nodes' ids. My
question is when I have the edges (Relationship objects) of a node is it
possible to get the corresponding nodes' id without referencing the Node
object (I think this is when Neo4j loads the Node from the physical drive
when it's not cached, isn't it)? I assume the Relationship object stores
the corresponding 2 Nodes' ids? Can it make any difference or not because
the already visited nodes are probably cached (1M total nodes,
neostore.nodestore.db.mapped_memory=1000M)? I use Neo4j community 1.8 on
Linux.

        GraphDatabaseService graphDb = new EmbeddedGraphDatabase(dbPath,
config);
        Set<String> cities = new HashSet<String>();
Set<Long> visitedIds = new HashSet<Long>();
        Transaction tx = graphDb.beginTx();
        try
        {
            Node startNode = graphDb.getNodeById(startNodeId);
            getDepth(startNode, 1, 6, cities, visitedIds);
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        private static void getDepth(Node node, int depth, int maxDepth,
Set<String> cities, Set<Long> visitedIds) {
if(!visitedIds.contains(node.getId())) {
visitedIds.add(node.getId());
cities.add(String.valueOf(node.getProperty("City")));
if(depth<=maxDepth) {
 for(Relationship rel : node.getRelationships()) {

                                         //instead of this something
like visitedIds.contains(rel.getEndNodeId())
 Node target = rel.getEndNode();

 if(target.getId() != node.getId()) {
 getDepth(target, depth+1, maxDepth, cities, visitedIds);
 }
                }

}
}
}

Thanks,
Greg

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Hunger  
View profile  
 More options Oct 6 2012, 2:49 am
From: Michael Hunger <michael.hun...@neopersistence.com>
Date: Sat, 6 Oct 2012 08:49:03 +0200
Local: Sat, Oct 6 2012 2:49 am
Subject: Re: [Neo4j] DFS query optimization

Neo4j traversal api already comes with uniqueness constraints

Use evaluators.toDepth(x)

See mark needhams example in yesterdays post in the google group

No the node is just a thin wrapper around the id if you didn't access props or other rels

Sent from mobile device

Am 06.10.2012 um 07:53 schrieb Gergely Svigruha <sgerg...@gmail.com>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »