Skip to content

Commit

Permalink
Added Dijkstra Romania problem test. Modified RomaniaProblemOptimalSe…
Browse files Browse the repository at this point in the history
…arch test to add cost/score for the missing cities expanded by the algorithm.
  • Loading branch information
gonzalezsieira committed Jul 31, 2014
1 parent 86c5e94 commit 8d53b4a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public RomaniaProblemOptimalSearchTest(){
costsFromArad.put(RomanianProblem.City.Craiova, 366d);
costsFromArad.put(RomanianProblem.City.Pitesti, 317d);
costsFromArad.put(RomanianProblem.City.Bucharest, 418d);
costsFromArad.put(RomanianProblem.City.Lugoj, 229d);
costsFromArad.put(RomanianProblem.City.Mehadia, 299d);
costsFromArad.put(RomanianProblem.City.Drobeta, 374d);
//obtain score map for expanding nodes to Bucharest
scoresFromArad = new HashMap<RomanianProblem.City, Double>();
scoresFromArad.put(RomanianProblem.City.Arad, 366d);
Expand All @@ -58,6 +61,9 @@ public RomaniaProblemOptimalSearchTest(){
scoresFromArad.put(RomanianProblem.City.Craiova, 526d);
scoresFromArad.put(RomanianProblem.City.Pitesti, 417d);
scoresFromArad.put(RomanianProblem.City.Bucharest, 418d);
scoresFromArad.put(RomanianProblem.City.Lugoj, 473d);
scoresFromArad.put(RomanianProblem.City.Mehadia, 540d);
scoresFromArad.put(RomanianProblem.City.Drobeta, 616d);
}

/**
Expand Down

0 comments on commit 8d53b4a

Please sign in to comment.