package org.psjava.example;

import junit.framework.Assert;

import org.junit.Test;
import org.psjava.algo.graph.shortestpath.BellmanFord;
import org.psjava.algo.graph.shortestpath.Dijkstra;
import org.psjava.algo.graph.shortestpath.SingleSourceShortestPathResult;
import org.psjava.algo.graph.shortestpath.SingleSourceShortestPath;
import org.psjava.ds.graph.AdjacencyListableDirectedWeightedGraph;
import org.psjava.ds.graph.AdjacencyListableDirectedWeightedGraphFactory;
import org.psjava.ds.graph.MutableDirectedWeightedGraph;
import org.psjava.ds.heap.BinaryHeapFactory;
import org.psjava.goods.GoodSingleSourceShortestPath;
import org.psjava.math.ns.IntegerNumberSystem;

public class ShortestPathExample {

	@Test
	public void example() {

		// Let's construct a graph.

		MutableDirectedWeightedGraph<Integer> graph = new MutableDirectedWeightedGraph<Integer>();
		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);
		AdjacencyListableDirectedWeightedGraph<Integer> adjacencyList = AdjacencyListableDirectedWeightedGraphFactory.create(graph);

		// Let's calculate distances from a single source - 'A'.
		// Choose algorithm, and do it.
		// algorithm with binary heap.

		SingleSourceShortestPath algorithm = GoodSingleSourceShortestPath.getInstance();
		SingleSourceShortestPathResult<Integer> result = algorithm.calc(adjacencyList, "A", IntegerNumberSystem.getInstance());

		int distanceAToC = result.getDistance("C");

		Assert.assertEquals(30, distanceAToC);

		// The good one should be Dijkstra's Algorithm but you can specify.
		new Dijkstra(new BinaryHeapFactory());
		new BellmanFord();
	}
}

@@ -1232,21 +1232,20 @@
 %0A%0D%0A%09%09// 
-Let's
+Then
  calcula
@@ -1323,42 +1323,9 @@
  it.
-%0D%0A%09%09// algorithm with binary heap.
+ 
 %0D%0A%0D%0A
@@ -1674,16 +1674,34 @@
 lgorithm
+ with binary heap.
  but you
@@ -1712,16 +1712,23 @@
  specify
+ others
 .%0D%0A%09%09new

improve comment