Class PathBest
java.lang.Object
topics.backtracking.paths.PathSimple
topics.backtracking.paths.PathBest
- Direct Known Subclasses:
PathBestPruning
Shortest Simple Path (Un-pruned)
Extends the basic pathfinder to track and store the absolute lowest cost path.
*Pedagogical Note
This problem (Shortest Path) is NOT NP-Hard. It can be solved in polynomial time using algorithms like Dijkstra (Greedy) or Floyd-Warshall (Dynamic Programming). We solve it here using Backtracking purely for educational comparative purposes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected final int[] -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class PathSimple
backtracking, getNumberSolutions, getPathString, setSource, setTarget, setWeightMatrix, writeWeights
-
Field Details
-
bestPath
protected final int[] bestPath -
bestCost
protected int bestCost -
bestLength
protected int bestLength
-
-
Constructor Details
-
PathBest
public PathBest(int n)
-
-
Method Details
-
backtrack
protected void backtrack(int current) - Overrides:
backtrackin classPathSimple
-
getBestCost
public int getBestCost() -
getBestPath
-