//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); }
public virtual Stream <NodeResult> GraphAlgosDijkstra(Node start, Node end, string relType, string weightProperty) { PathFinder <WeightedPath> pathFinder = GraphAlgoFactory.dijkstra(PathExpanders.forTypeAndDirection(RelationshipType.withName(relType), Direction.BOTH), weightProperty); WeightedPath path = pathFinder.FindSinglePath(start, end); //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: return(StreamSupport.stream(path.Nodes().spliterator(), false).map(NodeResult::new)); }
private void AssertContainsRelationship( WeightedPath path, Relationship relationship ) { foreach ( Relationship rel in path.Relationships() ) { if ( rel.Equals( relationship ) ) { return; } } fail( path + " should've contained " + relationship ); }
//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 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 pathToSelfReturnsZero() public virtual void PathToSelfReturnsZero() { // GIVEN Node start = Graph.makeNode("start", "x", 0d, "y", 0d); // WHEN 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: @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void canUseBranchState() public virtual void CanUseBranchState() { // This test doesn't use the predefined finder, which only means an unnecessary instantiation // if such an object. And this test will be run twice (once for each finder type in data()). /// <summary> /// <pre> /// 012345 A - B: 2 /// +------>y A - B: 2 /// 0|A B - C: 3 /// 1| A - C: 10 /// 2| B /// 3| /// 4| /// 5| /// 6| /// 7|C /// V /// x /// /// </pre> /// </summary> Node nodeA = Graph.makeNode("A", "x", 0d, "y", 0d); Node nodeB = Graph.makeNode("B", "x", 2d, "y", 1d); Node nodeC = Graph.makeNode("C", "x", 7d, "y", 0d); Graph.makeEdge("A", "B", "length", 2d); Graph.makeEdge("A", "B", "length", 2d); Graph.makeEdge("B", "C", "length", 3d); Graph.makeEdge("A", "C", "length", 10d); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Map<org.neo4j.graphdb.Node, double> seenBranchStates = new java.util.HashMap<>(); IDictionary <Node, double> seenBranchStates = new Dictionary <Node, double>(); PathExpander <double> expander = new PathExpanderAnonymousInnerClass(this, seenBranchStates); double initialStateValue = 0D; PathFinder <WeightedPath> traversalFinder = new TraversalAStar(expander, new Org.Neo4j.Graphdb.traversal.InitialBranchState_State(initialStateValue, initialStateValue), doubleCostEvaluator("length"), EstimateEvaluator); WeightedPath path = traversalFinder.FindSinglePath(nodeA, nodeC); assertEquals(( double? )5.0D, ( double? )path.Weight()); AssertPathDef(path, "A", "B", "C"); assertEquals(MapUtil.genericMap <Node, double>(nodeA, 0D, nodeB, 2D), seenBranchStates); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void wikipediaExample() public virtual void WikipediaExample() { /* GIVEN * * (start)---2--->(d) * \ \ * 1.5 .\ * v 3 * (a)-\ v * -2-\ (e) * ->(b) \ * / \ * /-- 2 * /-3- v * v --4------->(end) * (c)------/ */ Node start = Graph.makeNode("start", "x", 0d, "y", 0d); Graph.makeNode("a", "x", 0.3d, "y", 1d); Graph.makeNode("b", "x", 2d, "y", 2d); Graph.makeNode("c", "x", 0d, "y", 3d); Graph.makeNode("d", "x", 2d, "y", 0d); Graph.makeNode("e", "x", 3d, "y", 1.5d); Node end = Graph.makeNode("end", "x", 3.3d, "y", 2.8d); Graph.makeEdge("start", "a", "length", 1.5d); Graph.makeEdge("a", "b", "length", 2f); Graph.makeEdge("b", "c", "length", 3); Graph.makeEdge("c", "end", "length", 4L); Graph.makeEdge("start", "d", "length", ( short )2); Graph.makeEdge("d", "e", "length", ( sbyte )3); Graph.makeEdge("e", "end", "length", 2); // WHEN WeightedPath path = _finder.findSinglePath(start, end); // THEN AssertPathDef(path, "start", "d", "e", "end"); }
//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() ); }