//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void withState() public virtual void WithState() { /* Graph * * (a)-[1]->(b)-[2]->(c)-[5]->(d) */ Graph.makeEdgeChain("a,b,c,d"); SetWeight("a", "b", 1); SetWeight("b", "c", 2); SetWeight("c", "d", 5); InitialBranchState <int> state = new Org.Neo4j.Graphdb.traversal.InitialBranchState_State <int>(0, 0); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Map<org.neo4j.graphdb.Node, int> encounteredState = new java.util.HashMap<>(); IDictionary <Node, int> encounteredState = new Dictionary <Node, int>(); PathExpander <int> expander = new PathExpanderAnonymousInnerClass(this, state, encounteredState); PathFinder <WeightedPath> finder = new Dijkstra(expander, state, CommonEvaluators.doubleCostEvaluator("weight")); AssertPaths(finder.FindAllPaths(Graph.getNode("a"), Graph.getNode("d")), "a,b,c,d"); assertEquals(1, encounteredState[Graph.getNode("b")]); assertEquals(3, encounteredState[Graph.getNode("c")]); assertEquals(8, encounteredState[Graph.getNode("d")]); }
//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(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 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); }
public PathFinder dijkstra( PathExpander expander ) { return new Dijkstra( expander, CommonEvaluators.doubleCostEvaluator( "length" ) ); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testSmallGraphWithDefaults() public virtual void TestSmallGraphWithDefaults() { Relationship shortCTOXRelationship = CreateGraph( true ); PathFinder<WeightedPath> finder = factory.dijkstra( PathExpanders.forTypeAndDirection( MyRelTypes.R1, Direction.OUTGOING ), CommonEvaluators.doubleCostEvaluator( "cost", 1.0d ) ); // Assert that there are two matching paths Node startNode = Graph.getNode( "start" ); Node endNode = Graph.getNode( "x" ); AssertPaths( finder.FindAllPaths( startNode, endNode ), "start,a,b,c,x", "start,a,b,c,d,e,x" ); // Assert that for the shorter one it picked the correct relationship // of the two from (c) --> (x) foreach ( WeightedPath path in finder.FindAllPaths( startNode, endNode ) ) { if ( GetPathDef( path ).Equals( "start,a,b,c,x" ) ) { AssertContainsRelationship( path, shortCTOXRelationship ); } } }
public PathFinder <WeightedPath> dijkstra(PathExpander expander) { return(new Dijkstra(expander, InitialBranchState.NO_STATE, CommonEvaluators.DoubleCostEvaluator("length"))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void test6() public virtual void Test6() { Graph.makeEdgeChain("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,z", "cost", ( double )1); Graph.makeEdge("a", "b2", "cost", ( double )4); Graph.makeEdge("b2", "c", "cost", -2); Dijkstra <double> dijkstra = new Dijkstra <double>(0.0, Graph.getNode("a"), Graph.getNode("z"), CommonEvaluators.doubleCostEvaluator("cost"), new DoubleAdder(), double?.compareTo, Direction.OUTGOING, MyRelTypes.R1); IList <IList <Node> > paths = dijkstra.PathsAsNodes; assertEquals(2, paths.Count); }
protected internal virtual Dijkstra <double> GetDijkstra(SimpleGraphBuilder graph, double?startCost, string startNode, string endNode) { return(new Dijkstra <double>(startCost, graph.GetNode(startNode), graph.GetNode(endNode), CommonEvaluators.doubleCostEvaluator("cost"), new DoubleAdder(), double?.compareTo, Direction.BOTH, MyRelTypes.R1)); }
public TestDijkstra(DijkstraIteratorTest outerInstance) : base(0.0, null, null, CommonEvaluators.doubleCostEvaluator("cost"), new DoubleAdder(), double?.compareTo, Direction.BOTH, MyRelTypes.R1) { this._outerInstance = outerInstance; }
/// <summary> /// Test case for extracting paths /// </summary> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testPath() public virtual void TestPath() { Graph.makeEdge("a", "b", "cost", ( double )1); Graph.makeEdge("b", "c", "cost", ( float )1); Graph.makeEdge("c", "d", "cost", 1); Graph.makeEdge("d", "e", "cost", ( long )1); Graph.makeEdge("e", "f", "cost", ( sbyte )1); FloydWarshall <double> floydWarshall = new FloydWarshall <double>(0.0, double.MaxValue, Direction.OUTGOING, CommonEvaluators.doubleCostEvaluator("cost"), new Org.Neo4j.Graphalgo.impl.util.DoubleAdder(), double?.compareTo, Graph.AllNodes, Graph.AllEdges); IList <Node> path = floydWarshall.GetPath(Graph.getNode("a"), Graph.getNode("f")); assertEquals(6, path.Count); assertEquals(path[0], Graph.getNode("a")); assertEquals(path[1], Graph.getNode("b")); assertEquals(path[2], Graph.getNode("c")); assertEquals(path[3], Graph.getNode("d")); assertEquals(path[4], Graph.getNode("e")); assertEquals(path[5], Graph.getNode("f")); }
/// <summary> /// Test case for paths of length 0 and 1, and an impossible path /// </summary> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testMinimal() public virtual void TestMinimal() { Graph.makeEdge("a", "b", "cost", ( double )1); Graph.makeEdge("a", "c", "cost", ( float )1); Graph.makeEdge("a", "d", "cost", ( long )1); Graph.makeEdge("a", "e", "cost", 1); Graph.makeEdge("b", "c", "cost", ( double )1); Graph.makeEdge("c", "d", "cost", ( sbyte )1); Graph.makeEdge("d", "e", "cost", ( short )1); Graph.makeEdge("e", "b", "cost", ( sbyte )1); FloydWarshall <double> floydWarshall = new FloydWarshall <double>(0.0, double.MaxValue, Direction.OUTGOING, CommonEvaluators.doubleCostEvaluator("cost"), new Org.Neo4j.Graphalgo.impl.util.DoubleAdder(), double?.compareTo, Graph.AllNodes, Graph.AllEdges); assertEquals(0.0, floydWarshall.GetCost(Graph.getNode("a"), Graph.getNode("a")), 0.0); assertEquals(1.0, floydWarshall.GetCost(Graph.getNode("a"), Graph.getNode("b")), 0.0); assertEquals(floydWarshall.GetCost(Graph.getNode("b"), Graph.getNode("a")), double.MaxValue, 0.0); }
public BestFirstSelectorFactoryAnonymousInnerClass(TestBestFirstSelectorFactory outerInstance, Org.Neo4j.Graphalgo.impl.util.PathInterest <int> interest) : base(interest) { this.outerInstance = outerInstance; evaluator = CommonEvaluators.intCostEvaluator(outerInstance.length); }
private void InitializeInstanceFields() { _evaluator = CommonEvaluators.doubleCostEvaluator(_length); }