protected internal override WeightedPath FetchNextOrNull() { if (_shortestIterator == null) { _shortestPaths = new List <WeightedPath>(); while (_paths.MoveNext()) { WeightedPath path = new WeightedPathImpl(_costEvaluator, _paths.Current); if (NoneStrictMath.compare(path.Weight(), _foundWeight, _epsilon) < 0) { _foundWeight = path.Weight(); _shortestPaths.Clear(); } if (NoneStrictMath.compare(path.Weight(), _foundWeight, _epsilon) <= 0) { _shortestPaths.Add(path); } } _shortestIterator = _shortestPaths.GetEnumerator(); } //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: return(_shortestIterator.hasNext() ? _shortestIterator.next() : null); }
public override IEnumerable <Relationship> Expand(Path path, BranchState <double> state) { if (NoneStrictMath.compare(state.State, ShortestSoFar.doubleValue(), Epsilon) > 0 && StopAfterLowestCost) { return(Collections.emptyList()); } return(Source.expand(path, state)); }
//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()); }
public override IEnumerable <Relationship> Expand(Path path, BranchState <double> state) { double thisState = state.State; ThisSideShortest.Value = thisState; if (NoneStrictMath.compare(thisState + OtherSideShortest.doubleValue(), ShortestSoFar.doubleValue(), Epsilon) > 0 && StopAfterLowestCost) { return(Iterables.emptyResourceIterable()); } return(Source.expand(path, state)); }
//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 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); }
public override bool CanBeRuledOut(int numberOfVisits, double?pathPriority, double?oldPriority) { return(numberOfVisits > 0 || NoneStrictMath.compare(pathPriority.Value, oldPriority.Value, Epsilon) >= 0); }