http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0ccedb67/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 199a4ba..e5efd7f 100644 --- a/pom.xml +++ b/pom.xml @@ -1222,6 +1222,9 @@ limitations under the License. org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java </include> <include> + org/apache/tinkerpop/gremlin/process/computer/search/path/ShortestPathVertexProgram.java + </include> + <include> org/apache/tinkerpop/gremlin/process/computer/traversal/TraversalVertexProgram.java </include> <!-- traversal -->
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0ccedb67/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java ---------------------------------------------------------------------- diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java index e0018fc..4828fef 100644 --- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java +++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java @@ -19,10 +19,10 @@ package org.apache.tinkerpop.gremlin.tinkergraph.structure; import org.apache.tinkerpop.gremlin.process.computer.Computer; -import org.apache.tinkerpop.gremlin.process.traversal.P; -import org.apache.tinkerpop.gremlin.process.traversal.Pop; -import org.apache.tinkerpop.gremlin.process.traversal.Traversal; -import org.apache.tinkerpop.gremlin.process.traversal.Traverser; +import org.apache.tinkerpop.gremlin.process.computer.ComputerResult; +import org.apache.tinkerpop.gremlin.process.computer.Memory; +import org.apache.tinkerpop.gremlin.process.computer.search.path.ShortestPathVertexProgram; +import org.apache.tinkerpop.gremlin.process.traversal.*; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; @@ -212,23 +212,99 @@ public class TinkerGraphPlayTest { @Test @Ignore public void testPlay7() throws Exception { - /*TinkerGraph graph = TinkerGraph.open(); - graph.createIndex("name",Vertex.class); - graph.io(GraphMLIo.build()).readGraph("/Users/marko/software/tinkerpop/tinkerpop3/data/grateful-dead.xml");*/ - //System.out.println(g.V().properties().key().groupCount().next()); - TinkerGraph graph = TinkerFactory.createModern(); - GraphTraversalSource g = graph.traversal(); - final List<Supplier<GraphTraversal<?, ?>>> traversals = Arrays.asList( - () -> g.V().out().as("v").match( - __.as("v").outE().count().as("outDegree"), - __.as("v").inE().count().as("inDegree")).select("v", "outDegree", "inDegree").by(valueMap()).by().by().local(union(select("v"), select("inDegree", "outDegree")).unfold().fold()) - ); - - traversals.forEach(traversal -> { - logger.info("pre-strategy: {}", traversal.get()); - logger.info("post-strategy: {}", traversal.get().iterate()); - logger.info(TimeUtil.clockWithResult(50, () -> traversal.get().toList()).toString()); - }); + final TinkerGraph graph = TinkerFactory.createModern(); + final GraphTraversalSource g = graph.traversal(); + final ShortestPathVertexProgram shortestPathByHops = ShortestPathVertexProgram.build() + .source(__.has("name", P.within("marko"))) + .target(__.has("name","josh")) + .includeEdges(true) + .create(null); + final ShortestPathVertexProgram shortestPathByWeight = ShortestPathVertexProgram.build() + .source(__.has("name", P.within("marko"))) + .target(__.has("name","josh")) + .distanceProperty("weight") + .includeEdges(true) + .create(null); +/**/ + System.out.println("Shortest path from marko to josh (by number of hops)\n--"); + graph.compute().program(shortestPathByHops).submit().get().memory() + .<List<Path>>get(ShortestPathVertexProgram.SHORTEST_PATHS) + .forEach(System.out::println); + g.inject(graph.compute().program(shortestPathByHops).submit().get().memory() + .<List<Path>>get(ShortestPathVertexProgram.SHORTEST_PATHS)) + .unfold().map(unfold().values("name","weight").fold()) + .forEachRemaining(System.out::println); + + System.out.println("\n\nShortest path from marko to josh (by weighted distance)\n--"); + graph.compute().program(shortestPathByWeight).submit().get().memory() + .<List<Path>>get(ShortestPathVertexProgram.SHORTEST_PATHS) + .forEach(System.out::println); + + g.inject(graph.compute().program(shortestPathByWeight).submit().get().memory() + .<List<Path>>get(ShortestPathVertexProgram.SHORTEST_PATHS)) + .unfold().map(unfold().values("name","weight").fold()) + .forEachRemaining(System.out::println); + + System.out.println("----"); + + g.withComputer().V().hasLabel("person").both()//.dedup() + .shortestPath().to(has("name","peter")) + .path().forEachRemaining(System.out::println); + + System.out.println("----"); + + g.withComputer().V().hasLabel("person") + .union(identity(), identity()) + .shortestPath().to(has("name","peter")) + .forEachRemaining(System.out::println); + + System.out.println("----"); + + g.withComputer().V().hasLabel("person") + .shortestPath().to(has("name","peter")) + .map(union(identity(), tail(Scope.local, 1)).fold()).forEachRemaining(System.out::println); + + System.out.println("----"); + + g.withComputer() + .V().hasLabel("person") + .shortestPath().to(has("name","peter")).identity() + .forEachRemaining(System.out::println); + + System.out.println("----"); + + g.withComputer() + .V().hasLabel("person").as("p") + .shortestPath().to(__.<Vertex>has("name","peter").where(neq("p"))) + .forEachRemaining(System.out::println); + + System.out.println("----"); + + g.withComputer() + .V()//.hasLabel("person") + .shortestPath().to(__.has("name","marko")).by(__.inE()) + .forEachRemaining(System.out::println); + + System.out.println("----"); + + g.withComputer() + .V()//.hasLabel("person") + .shortestPath().to(__.not(identity())).by(__.inE()) + .forEachRemaining(System.out::println); + + System.out.println("----"); + + g.withComputer() + .V().not(identity()) + .shortestPath().by(__.inE()) + .forEachRemaining(System.out::println); + + System.out.println("----"); + + g.withComputer() + .V().not(identity()) + .shortestPath().to(__.not(identity())).by(__.inE()) + .forEachRemaining(System.out::println); } @Test