public virtual Path PathToReference(Node me) { PathFinder <Path> finder = GraphAlgoFactory.shortestPath(PathExpanders.allTypesAndDirections(), 6); using (Transaction tx = me.GraphDatabase.beginTx()) { Node other; if (me.hasRelationship(RelationshipType.withName("friend"))) { ResourceIterable <Relationship> relationships = (ResourceIterable <Relationship>)me.getRelationships(RelationshipType.withName("friend")); using (ResourceIterator <Relationship> resourceIterator = relationships.GetEnumerator()) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: other = resourceIterator.next().getOtherNode(me); } } else { other = me.GraphDatabase.createNode(); } Path path = finder.FindSinglePath(other, me); tx.Success(); return(path); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void canGetPathsInTriangleGraph() public virtual void CanGetPathsInTriangleGraph() { /* NODE (NAME/INDEX) * * (A/0) ------- 2 -----> (B/1) * \ / * - 10 -> (C/2) <- 3 - */ Node nodeA = Graph.makeNode( "A" ); Node nodeB = Graph.makeNode( "B" ); Node nodeC = Graph.makeNode( "C" ); Graph.makeEdge( "A", "B", "length", 2d ); Graph.makeEdge( "B", "C", "length", 3L ); Graph.makeEdge( "A", "C", "length", ( sbyte )10 ); PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() ); IEnumerator<WeightedPath> paths = finder.findAllPaths( nodeA, nodeC ).GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue( "expected at least one path", paths.hasNext() ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertPath( paths.next(), nodeA, nodeB, nodeC ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse( "expected at most one path", paths.hasNext() ); AssertPath( finder.findSinglePath( nodeA, nodeC ), nodeA, nodeB, nodeC ); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void canContinueGettingPathsByDiminishingCost() public virtual void CanContinueGettingPathsByDiminishingCost() { /* * NODE (NAME/INDEX) * * (A)-*2->(B)-*3->(C)-*1->(D) * | \ ^ ^ * | ----*5-----/ | * \ | * ---------*6----------- */ Node nodeA = Graph.makeNode( "A" ); Graph.makeNode( "B" ); Graph.makeNode( "C" ); Node nodeD = Graph.makeNode( "D" ); // Path "1" Graph.makeEdge( "A", "B", "length", 2d ); Graph.makeEdge( "B", "C", "length", 3L ); Graph.makeEdge( "C", "D", "length", ( sbyte )1 ); // = 6 // Path "2" Graph.makeEdge( "B", "D", "length", ( short )5 ); // = 7 // Path "3" Graph.makeEdge( "A", "D", "length", ( float )6 ); // = 6 PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() ); AssertPaths( finder.findAllPaths( nodeA, nodeD ), "A,B,C,D", "A,D" ); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Parameterized.Parameters public static java.util.Collection<Object[]> data() public static ICollection <object[]> Data() { return(Arrays.asList(new object[][] { new object[] { PathExpanders.allTypesAndDirections(), PathInterestFactory.All(), Uniqueness.NODE_PATH, new string[] { "a", "a,b", "a,c", "a,b,d", "a,b,c", "a,c,b", "a,c,b,d" } }, new object[] { PathExpanders.allTypesAndDirections(), PathInterestFactory.AllShortest(), Uniqueness.NODE_PATH, new string[] { "a", "a,b", "a,c", "a,b,d" } }, new object[] { PathExpanders.forDirection(Direction.OUTGOING), PathInterestFactory.All(), Uniqueness.NODE_PATH, new string[] { "a", "a,b", "a,c", "a,b,d", "a,c,b", "a,c,b,d" } }, new object[] { PathExpanders.allTypesAndDirections(), PathInterestFactory.All(), Uniqueness.NODE_GLOBAL, new string[] { "a", "a,b", "a,c", "a,b,d" } }, new object[] { PathExpanders.allTypesAndDirections(), PathInterestFactory.All(), Uniqueness.RELATIONSHIP_GLOBAL, new string[] { "a", "a,b", "a,c", "a,b,d", "a,b,c" } } })); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void betterTentativePath() public virtual void BetterTentativePath() { // GIVEN EstimateEvaluator <double> estimator = (node, goal) => ( double? )node.getProperty("estimate"); PathFinder <WeightedPath> finder = aStar(PathExpanders.allTypesAndDirections(), doubleCostEvaluator("weight", 0d), estimator); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Node node1 = graph.makeNode("1", "estimate", 0.003d); Node node1 = Graph.makeNode("1", "estimate", 0.003d); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Node node2 = graph.makeNode("2", "estimate", 0.002d); Node node2 = Graph.makeNode("2", "estimate", 0.002d); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Node node3 = graph.makeNode("3", "estimate", 0.001d); Node node3 = Graph.makeNode("3", "estimate", 0.001d); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Node node4 = graph.makeNode("4", "estimate", 0d); Node node4 = Graph.makeNode("4", "estimate", 0d); Graph.makeEdge("1", "3", "weight", 0.253d); Graph.makeEdge("1", "2", "weight", 0.018d); Graph.makeEdge("2", "4", "weight", 0.210d); Graph.makeEdge("2", "3", "weight", 0.180d); Graph.makeEdge("2", "3", "weight", 0.024d); Graph.makeEdge("3", "4", "weight", 0.135d); Graph.makeEdge("3", "4", "weight", 0.013d); // WHEN WeightedPath best14 = finder.FindSinglePath(node1, node4); // THEN assertPath(best14, node1, node2, node3, node4); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Parameters public static java.util.Collection<Object[]> data() public static ICollection <object[]> Data() { return(Arrays.asList(new object[][] { new object[] { GraphAlgoFactory.aStar(PathExpanders.allTypesAndDirections(), doubleCostEvaluator("length"), EstimateEvaluator) }, new object[] { new TraversalAStar(PathExpanders.allTypesAndDirections(), doubleCostEvaluator("length"), EstimateEvaluator) } })); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnPathsInIncreasingOrderOfCost() public virtual void ShouldReturnPathsInIncreasingOrderOfCost() { /* * * ----- (e) - 1 - (f) --- * / \ * / ------- (a) -------- \ * 1 / \ \ 2 * | 2 0 0 | * | / \ \| * (s) - 1 - (c) - 1 - (d) - 1 - (t) * \ / * -- 1 - (b) - 1 - * */ Node s = Graph.makeNode("s"); Node t = Graph.makeNode("t"); Graph.makeEdgeChain("s,e,f", "length", 1.0); Graph.makeEdge("f", "t", "length", 2); Graph.makeEdge("s", "a", "length", 2); Graph.makeEdge("a", "t", "length", 0); Graph.makeEdge("s", "c", "length", 1); Graph.makeEdge("c", "d", "length", 1); Graph.makeEdge("s", "b", "length", 1); Graph.makeEdge("b", "d", "length", 1); Graph.makeEdge("d", "a", "length", 0); Graph.makeEdge("d", "t", "length", 1); PathExpander expander = PathExpanders.allTypesAndDirections(); Dijkstra algo = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), PathInterestFactory.all(NoneStrictMath.EPSILON)); IEnumerator <WeightedPath> paths = algo.FindAllPaths(s, t).GetEnumerator(); for (int i = 1; i <= 3; i++) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue("Expected at least " + i + " path(s)", paths.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue("Expected 3 paths of cost 2", NoneStrictMath.Equals(paths.next().weight(), 2)); } for (int i = 1; i <= 3; i++) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue("Expected at least " + i + " path(s)", paths.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue("Expected 3 paths of cost 3", NoneStrictMath.Equals(paths.next().weight(), 3)); } //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue("Expected at least 7 paths", paths.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue("Expected 1 path of cost 4", NoneStrictMath.Equals(paths.next().weight(), 4)); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse("Expected exactly 7 paths", paths.hasNext()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleSimpleChainOddDepth() public virtual void ShouldHandleSimpleChainOddDepth() { // (a) - (b) - (c) - (d) Graph.makeEdgeChain("a,b,c,d"); Node a = Graph.getNode("a"); Node d = Graph.getNode("d"); AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 3, int.MaxValue, false)).findAllPaths(a, d), "a,b,c,d"); AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 3, int.MaxValue, false)).findAllPaths(a, d), "a,b,c,d"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 5000) public void testForLoops() public virtual void TestForLoops() { /* * * (b) * / \ 0 * 0 0 / \ - 0 - (c1) - 0 - * \ / \/ / \ * (s) - 1 - (a1) - 1 - (a2) - 1 - (a3) (a4) - 1 - (t) * \ / * - 0 - (c2) - 0 - * */ using (Transaction tx = GraphDb.beginTx()) { Node s = Graph.makeNode("s"); Node t = Graph.makeNode("t"); // Blob loop Graph.makeEdge("s", "a1", "length", 1); Graph.makeEdge("a1", "b", "length", 0); Graph.makeEdge("b", "a1", "length", 0); // Self loop Graph.makeEdge("a1", "a2", "length", 1); Graph.makeEdge("a2", "a2", "length", 0); // Diamond loop Graph.makeEdge("a2", "a3", "length", 1); Graph.makeEdge("a3", "c1", "length", 0); Graph.makeEdge("a3", "c2", "length", 0); Graph.makeEdge("c1", "a4", "length", 0); Graph.makeEdge("c1", "a4", "length", 0); Graph.makeEdge("a4", "t", "length", 1); PathExpander expander = PathExpanders.allTypesAndDirections(); Dijkstra algo = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), PathInterestFactory.all(NoneStrictMath.EPSILON)); IEnumerator <WeightedPath> paths = algo.FindAllPaths(s, t).GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue("Expected at least one path", paths.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertEquals("Expected first path of length 6", 6, paths.next().length()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue("Expected at least two paths", paths.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertEquals("Expected second path of length 6", 6, paths.next().length()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse("Expected exactly two paths", paths.hasNext()); tx.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testKShortestPaths() public virtual void TestKShortestPaths() { /* * ----- (e) - 3 - (f) --- * / \ * / ------- (a) -------- \ * 3 / \ \ 3 * | 2 0 0 | * | / \ \| * (s) - 1 - (c) - 1 - (d) - 1 - (t) * \ / * -- 1 - (b) - 1 - * */ Node s = Graph.makeNode("s"); Node t = Graph.makeNode("t"); Graph.makeEdge("s", "a", "length", 2); Graph.makeEdge("s", "b", "length", 1); Graph.makeEdge("s", "c", "length", 1); Graph.makeEdge("s", "e", "length", 3); Graph.makeEdge("a", "t", "length", 0); Graph.makeEdge("b", "d", "length", 1); Graph.makeEdge("c", "d", "length", 1); Graph.makeEdge("d", "a", "length", 0); Graph.makeEdge("d", "t", "length", 1); Graph.makeEdge("e", "f", "length", 3); Graph.makeEdge("f", "t", "length", 3); PathExpander expander = PathExpanders.allTypesAndDirections(); PathFinder <WeightedPath> algo = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), PathInterestFactory.numberOfShortest(NoneStrictMath.EPSILON, 6)); IEnumerator <WeightedPath> paths = algo.FindAllPaths(s, t).GetEnumerator(); int count = 0; while (paths.MoveNext()) { count++; WeightedPath path = paths.Current; double expectedWeight; if (count <= 3) { expectedWeight = 2.0; } else { expectedWeight = 3.0; } assertTrue("Expected path number " + count + " to have weight of " + expectedWeight, NoneStrictMath.Equals(path.Weight(), expectedWeight)); } assertEquals("Expected exactly 6 returned paths", 6, count); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void canFindNeighbour() public virtual void CanFindNeighbour() { /* * (A) - 1 -(B) */ Node nodeA = Graph.makeNode( "A" ); Node nodeB = Graph.makeNode( "B" ); Graph.makeEdge( "A", "B", "length", 1 ); PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() ); AssertPaths( finder.findAllPaths( nodeA, nodeB ), "A,B" ); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleNeighbouringNodes() public virtual void ShouldHandleNeighbouringNodes() { // (a) - (b) Graph.makeEdgeChain("a,b"); Node a = Graph.getNode("a"); Node b = Graph.getNode("b"); ExactDepthPathFinder pathFinder = new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, int.MaxValue, false); IEnumerable <Path> allPaths = pathFinder.FindAllPaths(a, b); AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, int.MaxValue, false)).findAllPaths(a, b), "a,b"); AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, int.MaxValue, false)).findAllPaths(a, b), "a,b"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void pathToSelfReturnsZero() public virtual void PathToSelfReturnsZero() { // GIVEN Node start = Graph.makeNode( "A" ); // WHEN PathFinder<WeightedPath> finder = factory.dijkstra( PathExpanders.allTypesAndDirections() ); WeightedPath path = finder.FindSinglePath( start, start ); // THEN assertNotNull( path ); assertEquals( start, path.StartNode() ); assertEquals( start, path.EndNode() ); assertEquals( 0, path.Length() ); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void canFindOrphanGraph() public virtual void CanFindOrphanGraph() { /* * * (A)=1 (relationship to self) * * Should not find (A)-(A). Should find (A) */ Node nodeA = Graph.makeNode( "A" ); Graph.makeEdge( "A", "A", "length", 1d ); PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() ); AssertPaths( finder.findAllPaths( nodeA, nodeA ), "A" ); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleNondirectedGraph() public virtual void ShouldHandleNondirectedGraph() { // (b) ----------------- (c) length 3 // / \ // (a) - (h) - (i) - (j) - (k) - (g) length 5 // \ / // (d) - (e) ------------ (f) length 4 Graph.makeEdgeChain("a,b,c,g"); Graph.makeEdgeChain("a,d,e,f,g"); Graph.makeEdgeChain("a,h,i,j,k,g"); Node a = Graph.getNode("a"); Node g = Graph.getNode("g"); AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 3, int.MaxValue, false)).findAllPaths(a, g), "a,b,c,g"); AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 4, int.MaxValue, false)).findAllPaths(a, g), "a,d,e,f,g"); AssertPaths((new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 5, int.MaxValue, false)).findAllPaths(a, g), "a,h,i,j,k,g"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldOnlyFindTheShortestPaths() public virtual void ShouldOnlyFindTheShortestPaths() { /* * * ----- (e) - 1 - (f) --- * / \ * / ------- (a) -------- \ * 1 / \ \ 2 * | 2 0 0 | * | / \ \| * (s) - 1 - (c) - 1 - (d) - 1 - (t) * \ / * -- 1 - (b) - 1 - * */ Node s = Graph.makeNode( "s" ); Node t = Graph.makeNode( "t" ); Node a = Graph.makeNode( "a" ); Node b = Graph.makeNode( "b" ); Node c = Graph.makeNode( "c" ); Graph.makeEdgeChain( "s,e,f", "length", 1.0 ); Graph.makeEdge( "f", "t", "length", 2 ); Graph.makeEdge( "s","a", "length", 2 ); Graph.makeEdge( "a","t", "length", 0 ); Graph.makeEdge( "s", "c", "length", 1 ); Graph.makeEdge( "c","d", "length", 1 ); Graph.makeEdge( "s","b", "length", 1 ); Graph.makeEdge( "b","d", "length", 1 ); Graph.makeEdge( "d","a", "length", 0 ); Graph.makeEdge( "d","t", "length", 1 ); PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() ); IEnumerator<WeightedPath> paths = finder.findAllPaths( s, t ).GetEnumerator(); for ( int i = 1; i <= 3; i++ ) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue( "Expected at least " + i + " path(s)", paths.hasNext() ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue( "Expected 3 paths of cost 2", NoneStrictMath.Equals( paths.next().weight(), 2 ) ); } //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse( "Expected exactly 3 paths", paths.hasNext() ); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void allPathsToSelfReturnsZero() public virtual void AllPathsToSelfReturnsZero() { // GIVEN Node start = Graph.makeNode( "A" ); // WHEN PathFinder<WeightedPath> finder = factory.dijkstra( PathExpanders.allTypesAndDirections() ); IEnumerable<WeightedPath> paths = finder.FindAllPaths( start, start ); // THEN foreach ( WeightedPath path in paths ) { assertNotNull( path ); assertEquals( start, path.StartNode() ); assertEquals( start, path.EndNode() ); assertEquals( 0, path.Length() ); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void canGetMultiplePathsInTriangleGraph() public virtual void CanGetMultiplePathsInTriangleGraph() { /* NODE (NAME/INDEX) * ==> (two relationships) * * (A/0) ====== 1 =====> (B/1) * \ / * - 5 -> (C/2) <- 2 - */ Node nodeA = Graph.makeNode( "A" ); Node nodeB = Graph.makeNode( "B" ); Node nodeC = Graph.makeNode( "C" ); ISet<Relationship> expectedFirsts = new HashSet<Relationship>(); expectedFirsts.Add( Graph.makeEdge( "A", "B", "length", 1d ) ); expectedFirsts.Add( Graph.makeEdge( "A", "B", "length", 1 ) ); Relationship expectedSecond = Graph.makeEdge( "B", "C", "length", 2L ); Graph.makeEdge( "A", "C", "length", 5d ); PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() ); IEnumerator<WeightedPath> paths = finder.findAllPaths( nodeA, nodeC ).GetEnumerator(); for ( int i = 0; i < 2; i++ ) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue( "expected more paths", paths.hasNext() ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: Path path = paths.next(); AssertPath( path, nodeA, nodeB, nodeC ); IEnumerator<Relationship> relationships = path.Relationships().GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue( "found shorter path than expected", relationships.hasNext() ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue( "path contained unexpected relationship", expectedFirsts.remove( relationships.next() ) ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue( "found shorter path than expected", relationships.hasNext() ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertEquals( expectedSecond, relationships.next() ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse( "found longer path than expected", relationships.hasNext() ); } //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse( "expected at most two paths", paths.hasNext() ); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testFinderShouldNotFindAnythingBeyondLimit() public virtual void TestFinderShouldNotFindAnythingBeyondLimit() { // Layout: // // (a)-->(b)-->(c)-->(d)-->(e) // Graph.makeEdgeChain("a,b,c,d,e"); TestShortestPathFinder(finder => assertPaths(finder.findAllPaths(Graph.getNode("a"), Graph.getNode("b"))), PathExpanders.allTypesAndDirections(), 0); TestShortestPathFinder(finder => { AssertPaths(finder.findAllPaths(Graph.getNode("a"), Graph.getNode("c"))); AssertPaths(finder.findAllPaths(Graph.getNode("a"), Graph.getNode("d"))); }, PathExpanders.allTypesAndDirections(), 1); TestShortestPathFinder(finder => { AssertPaths(finder.findAllPaths(Graph.getNode("a"), Graph.getNode("d"))); AssertPaths(finder.findAllPaths(Graph.getNode("a"), Graph.getNode("e"))); }, PathExpanders.allTypesAndDirections(), 2); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void canKeepSearchingUntilFoundTrueShortest() public virtual void CanKeepSearchingUntilFoundTrueShortest() { /* * * 1 - (B) - 1 - (C) - 1 - (D) - 1 - (E) - 1 * | | * (A) --- 1 --- (G) -- 2 -- (H) --- 1 --- (F) * */ Node a = Graph.makeNode( "A" ); Node b = Graph.makeNode( "B" ); Node c = Graph.makeNode( "C" ); Node d = Graph.makeNode( "D" ); Node e = Graph.makeNode( "E" ); Node f = Graph.makeNode( "F" ); Node g = Graph.makeNode( "G" ); Node h = Graph.makeNode( "H" ); Graph.makeEdgeChain( "A,B,C,D,E,F", "length", 1 ); Graph.makeEdge( "A", "G", "length", 1 ); Graph.makeEdge( "G", "H", "length", 2 ); Graph.makeEdge( "H", "F", "length", 1 ); PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() ); IEnumerator<WeightedPath> paths = finder.findAllPaths( a, f ).GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue( "Expect at least one path", paths.hasNext() ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: WeightedPath path = paths.next(); assertPath( path, a,g,h,f ); assertEquals( "Expect weight 1", 4, path.Weight(), 0.0 ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse( "Expected at most one path", paths.hasNext() ); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void canFindNeighbourMultipleIncorrectPaths() public virtual void CanFindNeighbourMultipleIncorrectPaths() { /* * - 2.0 - * / \ * (A) - 1 - (B) */ Node nodeA = Graph.makeNode( "A" ); Node nodeB = Graph.makeNode( "B" ); Graph.makeEdge( "A", "B", "length", 2.0 ); Graph.makeEdge( "A", "B", "length", 1 ); PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() ); IEnumerator<WeightedPath> paths = finder.findAllPaths( nodeA, nodeB ).GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue( "Expect at least one path", paths.hasNext() ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: WeightedPath path = paths.next(); assertPath( path, nodeA, nodeB ); assertEquals( "Expect weight 1", 1, path.Weight(), 0.0 ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse( "Expected at most one path", paths.hasNext() ); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void canFetchLongerPaths() public virtual void CanFetchLongerPaths() { /* * 1-(b)-1 * / \ * (s) - 1 - (a) - 1 - (c) - 10 - (d) - 10 - (t) * */ Node s = Graph.makeNode("s"); Node a = Graph.makeNode("a"); Node b = Graph.makeNode("b"); Node c = Graph.makeNode("c"); Node d = Graph.makeNode("d"); Node t = Graph.makeNode("t"); Graph.makeEdge("s", "a", "length", 1); Graph.makeEdge("a", "c", "length", 1); Graph.makeEdge("s", "b", "length", 1); Graph.makeEdge("b", "a", "length", 1); Graph.makeEdge("c", "d", "length", 10); Graph.makeEdge("d", "t", "length", 10); PathExpander expander = PathExpanders.allTypesAndDirections(); Dijkstra algo = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), PathInterestFactory.all(NoneStrictMath.EPSILON)); IEnumerator <WeightedPath> paths = algo.FindAllPaths(s, t).GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue("Expected at least one path.", paths.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertPath(paths.next(), s, a, c, d, t); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue("Expected two paths", paths.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertPath(paths.next(), s, b, a, c, d, t); }
protected internal virtual PathFinder <Path> InstantiatePathFinder(int maxDepth) { return(GraphAlgoFactory.allSimplePaths(PathExpanders.allTypesAndDirections(), maxDepth)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void canGetMultiplePathsInASmallRoadNetwork() public virtual void CanGetMultiplePathsInASmallRoadNetwork() { /* NODE (NAME/INDEX) * * --------------------- 25 ----------------------- * / \ * (A/0) - 2 - (B/1) - 2.5 - (D/3) - 3 - (E/4) - 5 - (F/5) * | / / / * 2.5 ---------- 7.3 ----- / / * | / / / * (C/2) ------------------ 5 --------- / * \ / * ------------------ 12 -------------------- * */ Node nodeA = Graph.makeNode( "A" ); Node nodeB = Graph.makeNode( "B" ); Node nodeC = Graph.makeNode( "C" ); Node nodeD = Graph.makeNode( "D" ); Node nodeE = Graph.makeNode( "E" ); Node nodeF = Graph.makeNode( "F" ); Graph.makeEdge( "A", "B", "length", 2d ); Graph.makeEdge( "A", "C", "length", 2.5f ); Graph.makeEdge( "C", "D", "length", 7.3d ); Graph.makeEdge( "B", "D", "length", 2.5f ); Graph.makeEdge( "D", "E", "length", 3L ); Graph.makeEdge( "C", "E", "length", 5 ); Graph.makeEdge( "E", "F", "length", ( sbyte )5 ); Graph.makeEdge( "C", "F", "length", ( short )12 ); Graph.makeEdge( "A", "F", "length", ( long )25 ); PathFinder finder = factory.dijkstra( PathExpanders.allTypesAndDirections() ); // Try the search in both directions. foreach (Node[] nodes in new Node[][] { new Node[] { nodeA, nodeF }, new Node[] { nodeF, nodeA } }) { int found = 0; IEnumerator<WeightedPath> paths = finder.findAllPaths( nodes[0], nodes[1] ).GetEnumerator(); for ( int i = 0; i < 2; i++ ) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue( "expected more paths", paths.hasNext() ); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: Path path = paths.next(); if ( path.Length() != found && path.Length() == 3 ) { AssertContains( path.Nodes(), nodeA, nodeC, nodeE, nodeF ); } else if ( path.Length() != found && path.Length() == 4 ) { AssertContains( path.Nodes(), nodeA, nodeB, nodeD, nodeE, nodeF ); } else { fail( "unexpected path length: " + path.Length() ); } found = path.Length(); } //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse( "expected at most two paths", paths.hasNext() ); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void withFilters() public virtual void WithFilters() { // Layout: // // (a)-->(b)-->(c)-->(d) // \ ^ // -->(g)-->(h)--/ // Graph.makeEdgeChain("a,b,c,d"); Graph.makeEdgeChain("a,g,h,d"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Node a = graph.getNode("a"); Node a = Graph.getNode("a"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Node d = graph.getNode("d"); Node d = Graph.getNode("d"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.Node b = graph.getNode("b"); Node b = Graph.getNode("b"); b.SetProperty("skip", true); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final System.Predicate<org.neo4j.graphdb.Node> filter = item -> System.Predicate <Node> filter = item => { bool skip = ( bool? )item.getProperty("skip", false).Value; return(!skip); }; TestShortestPathFinder(finder => assertPaths(finder.findAllPaths(a, d), "a,g,h,d"), (( StandardExpander )PathExpanders.allTypesAndDirections()).addNodeFilter(filter), 10); }
private PathFinder <Path> NewFinder() { return(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 4, 4, true)); }
protected internal virtual PathFinder <Path> InstantiatePathFinder(int maxDepth) { return(allPaths(PathExpanders.allTypesAndDirections(), maxDepth)); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: private org.neo4j.graphdb.traversal.Traverser traverseToDepth(org.neo4j.graphdb.GraphDatabaseService graphDb, final org.neo4j.graphdb.Node startNode, final int depth) private Traverser TraverseToDepth(GraphDatabaseService graphDb, Node startNode, int depth) { TraversalDescription traversalDescription = graphDb.TraversalDescription().expand(PathExpanders.allTypesAndDirections()).depthFirst().evaluator(path => { if (path.length() < depth) { return(Evaluation.INCLUDE_AND_CONTINUE); } else { return(Evaluation.INCLUDE_AND_PRUNE); } }); return(traversalDescription.Traverse(startNode)); }
public virtual Path PathToReference(Node me) { PathFinder <Path> finder = GraphAlgoFactory.shortestPath(PathExpanders.allTypesAndDirections(), 6); return(finder.FindSinglePath(me.GraphDatabase.createNode(), me)); }