-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Dijkstra Romania problem test. Modified RomaniaProblemOptimalSe…
…arch test to add cost/score for the missing cities expanded by the algorithm.
- Loading branch information
1 parent
86c5e94
commit 8d53b4a
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...sc/citius/hipster/algorithm/problem/romanian/DijkstraRomaniaProblemOptimalSearchTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package es.usc.citius.hipster.algorithm.problem.romanian; | ||
|
||
import es.usc.citius.hipster.algorithm.Hipster; | ||
import es.usc.citius.hipster.model.HeuristicNode; | ||
import es.usc.citius.hipster.model.problem.SearchProblem; | ||
import es.usc.citius.hipster.util.examples.RomanianProblem; | ||
import es.usc.citius.hipster.util.graph.GraphSearchProblem; | ||
import org.junit.Test; | ||
|
||
import java.util.Iterator; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* @author Adrián González Sieira <[email protected]> | ||
* @since 31/07/2014 | ||
*/ | ||
public class DijkstraRomaniaProblemOptimalSearchTest extends RomaniaProblemOptimalSearchTest{ | ||
|
||
@Override | ||
public Iterator<HeuristicNode<Double, RomanianProblem.City, Double, ?>> createIterator() { | ||
SearchProblem p = GraphSearchProblem | ||
.startingFrom(RomanianProblem.City.Arad) | ||
.in(graph) | ||
.takeCostsFromEdges() | ||
.build(); | ||
|
||
return Hipster.createDijkstra(p).iterator(); | ||
} | ||
|
||
|
||
/** | ||
* In the case of Dijkstra's Algorithm, | ||
*/ | ||
@Override | ||
@Test | ||
public void scoresFromAradToBucharest() { | ||
HeuristicNode<?, RomanianProblem.City, Double, ?> node; | ||
//search optimal path | ||
do{ | ||
node = searchIterator.next(); | ||
//compare returned score with expected | ||
assertEquals( | ||
"Failed checking score of " + node.state().toString(), | ||
costsFromArad.get(node.state()), node.getScore() | ||
); | ||
}while(searchIterator.hasNext() && !node.state().equals(RomanianProblem.City.Bucharest)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters