//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: public Iterable<org.neo4j.graphalgo.WeightedPath> findAllPaths(org.neo4j.graphdb.Node start, final org.neo4j.graphdb.Node end) public override IEnumerable <WeightedPath> FindAllPaths(Node start, Node end) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.traversal.Traverser traverser = traverser(start, end, org.neo4j.graphalgo.impl.util.PathInterestFactory.allShortest(epsilon)); Traverser traverser = traverser(start, end, PathInterestFactory.allShortest(_epsilon)); return(() => new TopFetchingWeightedPathIterator(traverser.GetEnumerator(), _costEvaluator)); }
public Dijkstra(PathExpander expander, InitialBranchState stateFactory, CostEvaluator <double> costEvaluator, bool stopAfterLowestCost) { this._expander = expander; this._costEvaluator = costEvaluator; this._stateFactory = stateFactory; _interest = stopAfterLowestCost ? PathInterestFactory.allShortest(NoneStrictMath.EPSILON) : PathInterestFactory.all(NoneStrictMath.EPSILON); _epsilon = NoneStrictMath.EPSILON; this._stateInUse = true; }
//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 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); }
//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(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(); } }
public Dijkstra(PathExpander expander, CostEvaluator <double> costEvaluator, bool stopAfterLowestCost) : this(expander, costEvaluator, NoneStrictMath.EPSILON, stopAfterLowestCost ? PathInterestFactory.allShortest(NoneStrictMath.EPSILON) : PathInterestFactory.all(NoneStrictMath.EPSILON)) { }
/// <summary> /// See <seealso cref="Dijkstra(PathExpander, CostEvaluator, double, PathInterest)"/> /// Use <seealso cref="NoneStrictMath.EPSILON"/> as tolerance. /// Use <seealso cref="PathInterestFactory.allShortest(double)"/> as PathInterest. /// </summary> public Dijkstra(PathExpander expander, CostEvaluator <double> costEvaluator) : this(expander, costEvaluator, PathInterestFactory.allShortest(NoneStrictMath.EPSILON)) { }
/// <summary> /// See <seealso cref="dijkstra(PathExpander, CostEvaluator)"/> for documentation /// /// Instead of finding all shortest paths with equal cost, find the top {@code numberOfWantedPaths} paths. /// This is usually slower than finding all shortest paths with equal cost. /// </summary> /// <param name="expander"> the <seealso cref="PathExpander"/> to use for expanding /// <seealso cref="Relationship"/>s for each <seealso cref="Path"/>. </param> /// <param name="costEvaluator"> evaluator that can return the cost represented /// by each relationship the algorithm traverses. </param> /// <param name="numberOfWantedPaths"> number of paths to find. </param> /// <returns> an algorithm which finds the cheapest path between two nodes /// using the Dijkstra algorithm. </returns> public static PathFinder <WeightedPath> Dijkstra(PathExpander expander, CostEvaluator <double> costEvaluator, int numberOfWantedPaths) { return(new Dijkstra(expander, costEvaluator, NoneStrictMath.EPSILON, PathInterestFactory.numberOfShortest(NoneStrictMath.EPSILON, numberOfWantedPaths))); }
public override WeightedPath FindSinglePath(Node start, Node end) { return(firstOrNull(new TopFetchingWeightedPathIterator(Traverser(start, end, PathInterestFactory.single(_epsilon)).GetEnumerator(), _costEvaluator))); }