package org.psjava.example.algo;

import org.junit.Assert;
import org.junit.Test;
import org.psjava.algo.graph.shortestpath.Dijkstra;
import org.psjava.algo.graph.shortestpath.SingleSourceShortestPath;
import org.psjava.algo.graph.shortestpath.SingleSourceShortestPathResult;
import org.psjava.ds.graph.DirectedWeightedEdge;
import org.psjava.ds.graph.MutableDirectedWeightedGraph;
import org.psjava.ds.heap.BinaryHeapFactory;
import org.psjava.ds.numbersystrem.IntegerNumberSystem;

/**
 * @implementation {@link Dijkstra}
 * @see {@link ShortestPathAlgorithmExample}
 * @see {@link BellmanFordAlgorithmExample}
 */
public class DijkstraAlgorithmExample {

	@Test
	public void example() {

		// Dijkstra's algorithm is awesome... Let's construct a simple graph.

		MutableDirectedWeightedGraph<String, Integer> graph = MutableDirectedWeightedGraph.create();
		graph.insertVertex("A");
		graph.insertVertex("B");
		graph.insertVertex("C");
		graph.insertVertex("D");
		graph.addEdge("A", "C", 100);
		graph.addEdge("A", "B", 10);
		graph.addEdge("B", "C", 20);

		// Then calculate distances from a single source 'A'

		SingleSourceShortestPath dijkstra = new Dijkstra(new BinaryHeapFactory());
		SingleSourceShortestPathResult<String, Integer, DirectedWeightedEdge<String, Integer>> res = dijkstra.calc(graph, "A", IntegerNumberSystem.getInstance());

		boolean reachabilityOfC = res.isReachable("C"); // must be true
		boolean reachabilityOfD = res.isReachable("D"); // must be false
		int distanceToC = res.getDistance("C"); // must be 30

		Assert.assertTrue(reachabilityOfC);
		Assert.assertEquals(30, distanceToC);
		Assert.assertFalse(reachabilityOfD);
	}
}

@@ -409,87 +409,80 @@
 .ds.
-heap.BinaryHeapFactory;%0D%0Aimport org.psjava.ds.numbersystrem.IntegerNumberSystem
+numbersystrem.IntegerNumberSystem;%0D%0Aimport org.psjava.goods.GoodDijkstra
 ;%0D%0A%0D
@@ -707,43 +707,8 @@
 %09%09//
- Dijkstra's algorithm is awesome...
  Let
@@ -1055,14 +1055,9 @@
 %09// 
-Then c
+C
 alcu
@@ -1141,20 +1141,20 @@
 a = 
-new 
+Good
 Dijkstra
 (new
@@ -1153,33 +1153,22 @@
 stra
-(new BinaryHeapFactory
+.getInstance
 ()
-)
 ;%0D%0A%09
@@ -1258,16 +1258,19 @@
 er%3E%3E res
+ult
  = dijks
@@ -1356,24 +1356,27 @@
 ityOfC = res
+ult
 .isReachable
@@ -1389,20 +1389,23 @@
  // 
-must be true
+C is reachable.
 %0D%0A%09%09
@@ -1433,16 +1433,19 @@
 fD = res
+ult
 .isReach
@@ -1462,21 +1462,27 @@
  // 
-must be false
+D is not reachable.
 %0D%0A%09%09
@@ -1502,16 +1502,19 @@
 oC = res
+ult
 .getDist

improve DijkstraAlgorithmExample