2010/4/29 Alex Averbuch <alex.averb...@gmail.com> > Hey, > Is there any example code on how to use the NetworkDiameter class? > I'm not at all an expert in the network diameter classes and the only thing I can think of is the NetworkDiameterTest class.
> > The use case is an unweighted graph where all edge types should be > considered. > > Problems I'm having: > > - How do I consider more than 2 edge types? > SingleSourceShortestPathDijkstra seems to take a RelationshipType... types so you could pass in as many relationship types there as you want. > - Which node should the startNode be? Is the Reference node alright? > If the reference node is somehow a "member" of the graph you're querying on, then yes > - How do I define the nodeSet? I would like diameter of the entire graph, > not of any subgraph/connected component. > I think this would require a little modification of the ShortestPathBasedCentrality class in that if nodeSet == null, use graphDb.getAllNodes() instead. And for that you'd have to pass in the GraphDatabaseService in the constructor of it as well (if you don't have a Node or Relationship somehow, because of the newly added getGraphDatabase() method on their super-interface PropertyContainer). > > My first attempt at setting this up is below but it's obviously not > working. > Would be really cool if someone could either give me a sample code snippet, > or point me in the right direction. > At the moment I can't help you here, but I'll see what I can do... or if someone else have used this functionality with similar requirements? > > Cheers! > Alex > Cherrio! > > PS, The reason I need this is I'll be using the Diameter value to construct > meaningful simulated access patterns. > > > > CostEvaluator<Integer> costEval = new CostEvaluator<Integer>() { > > @Override > public Integer getCost(Relationship relationship, boolean backwards) { > return 1; > } > }; > > CostAccumulator<Integer> costAcc = new CostAccumulator<Integer>() { > > @Override > public Integer addCosts(Integer c1, Integer c2) { > return c1 + c2; > } > }; > > Comparator<Integer> costComp = new Comparator<Integer>() { > > @Override > public int compare(Integer arg0, Integer arg1) { > if (arg0 > arg1) > return -1; > if (arg0 < arg1) > return 1; > return 0; > } > }; > > Node startNode = graphDb.getReferenceNode(); > Integer startCost = 0; > SingleSourceShortestPathDijkstra<Integer> singleSourceShortestPath = new > SingleSourceShortestPathDijkstra<Integer>( > startCost, startNode, costEval, costAcc, costComp, Direction.BOTH, > RelationshipExpander.forTypes(GISRelationshipTypes.FOOT_WAY, > Direction.BOTH, GISRelationshipTypes.BICYCLE_WAY, > Direction.BOTH, GISRelationshipTypes.CAR_WAY, > Direction.BOTH, GISRelationshipTypes.CAR_SHORTEST_WAY, > Direction.BOTH)); > > Integer zeroValue = 0; > > Set<Node> nodeSet = graphDb.getAllNodes(); > > NetworkDiameter<Integer> networkDiameter = new NetworkDiameter<Integer>( > singleSourceShortestPath, zeroValue, nodeSet, costComp); > _______________________________________________ > Neo mailing list > User@lists.neo4j.org > https://lists.neo4j.org/mailman/listinfo/user > -- Mattias Persson, [matt...@neotechnology.com] Hacker, Neo Technology www.neotechnology.com _______________________________________________ Neo mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user