Hi there, I've looked over your code, and it doesn't seem like you are doing anything wrong, AFAICS.
It would be easier to help you if I could run the code, and I would need to have a copy of your database for that. Could you send a script that loads a database with data? Cheers, Andrés On Fri, Oct 8, 2010 at 5:30 PM, French, Bernie T. <[email protected]> wrote: > Hi Folks, > > I just joined the list and have begun my initial explorations of neo4j. > I've been able to build a simple directed graph database, create a > TraversalDescription, traverse the graph and write a Pruner. > > I then started to explore the graph algorithms, starting with the > "shortest path" algorithm from the GraphAlgoFactory class. Although I > can traverse my graph using a Traverser, I cannot seem to be able to get > a path from using the GraphAlgoFactory. > > The path that is always returned by the following statement is always > null, even though I know the path exists using the Traverser. > > path = pathFinder.findSinglePath(startNode, endNode); > > Here is the snapshot of my class, first using the Traverser, and then > trying to use the Graph Algorithms. Any insight into what I'm > overlooking would be greatly appreciated. > > public class FindShortestPath { > > public static void main(String[] args) { > > String databaseLocation = > "/home/neo4j/simpleDirectedGraphDb"; > GraphDatabaseService graphDb = new > EmbeddedGraphDatabase(databaseLocation); > IndexService indexService = new > LuceneIndexService(graphDb); > Transaction tx = graphDb.beginTx(); > PropertyContainer propertyContainer; > StringBuffer pathBuffer; > try { > > String startName = "Jack"; > String endName = "Jill"; > Node startNode = > indexService.getSingleNode("NAME", startName); > Node endNode = > indexService.getSingleNode("NAME", endName); > System.out.println("StartNode: " + > startNode.getProperty("NAME")); > System.out.println("EndNode: " + > endNode.getProperty("NAME")); > > // Traverse the Graph - Traversing is > successfull here.... > > TraversalDescription td = new > TraversalDescriptionImpl(); > td = td.depthFirst(); > td = td.relationships(RelationshipTypes.LIKES, > Direction.OUTGOING); > td = td.relationships(RelationshipTypes.KNOWS, > Direction.OUTGOING); > Traverser traverser = td.traverse(startNode); > Iterator<Path> traversalIterator = > traverser.iterator(); > int pathCount = 0; > Path path = null; > while (traversalIterator.hasNext()) { > pathCount++; > path = (Path) traversalIterator.next(); > > Iterable<Node> nodeIterable = > path.nodes(); > Iterator<Node> nodeIterator = > nodeIterable.iterator(); > pathBuffer = new StringBuffer(); > while (nodeIterator.hasNext()) { > Node node = (Node) > nodeIterator.next(); > > pathBuffer.append(node.getProperty("NAME") + "->"); > } > System.out.println("TRAVERSE: " + > pathBuffer.toString()); > > } > > // Start Graph Algorithm > > StandardExpander expander = new > OrderedByTypeExpander(); > expander.add(RelationshipTypes.KNOWS, > Direction.OUTGOING); > expander.add(RelationshipTypes.LIKES, > Direction.OUTGOING); > PathFinder<Path> pathFinder = > GraphAlgoFactory.shortestPath(expander, 20); > > path = pathFinder.findSinglePath(startNode, > endNode); > > /* PATH IS ALWAYS NULL HERE */ > > if (path != null) { > Iterator<PropertyContainer> pathIterator > = path.iterator(); > pathBuffer = new StringBuffer(); > while (pathIterator.hasNext()) { > propertyContainer = > (PropertyContainer) pathIterator.next(); > String name = (String) > propertyContainer.getProperty("NAME"); > pathBuffer.append(name + "->"); > } > System.out.println("Single Path: " + > pathBuffer.toString()); > } else { > System.out.println("Could not find a > path, path is null"); > } > tx.success(); > } catch (Exception e) { > e.printStackTrace(); > graphDb.shutdown(); > } > graphDb.shutdown(); > > } > > } > > Thanks! > > -- Bernie > > > > Confidentiality Notice: This electronic message transmission, including any > attachment(s), may contain confidential, proprietary, or privileged > information from Chemical Abstracts Service ("CAS"), a division of the > American Chemical Society ("ACS"). If you have received this transmission in > error, be advised that any disclosure, copying, distribution, or use of the > contents of this information is strictly prohibited. Please destroy all > copies of the message and contact the sender immediately by either replying > to this message or calling 614-447-3600. > > _______________________________________________ > Neo4j mailing list > [email protected] > https://lists.neo4j.org/mailman/listinfo/user > _______________________________________________ Neo4j mailing list [email protected] https://lists.neo4j.org/mailman/listinfo/user

