diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java index fd172f0..b0a4837 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java @@ -1,9 +1,131 @@ package org.insa.graphs.algorithm.shortestpath; +import java.util.ArrayList; +import java.util.Collections; + +import javax.print.attribute.standard.Destination; + +import org.insa.graphs.algorithm.AbstractSolution.Status; +import org.insa.graphs.algorithm.utils.BinaryHeap; +import org.insa.graphs.model.Arc; +import org.insa.graphs.model.Graph; +import org.insa.graphs.model.Node; +import org.insa.graphs.model.Path; +import org.insa.graphs.model.Point; + public class AStarAlgorithm extends DijkstraAlgorithm { public AStarAlgorithm(ShortestPathData data) { super(data); } + @Override + protected ShortestPathSolution doRun() { + + + + // retrieve data from the input problem (getInputData() is inherited from the + // parent class ShortestPathAlgorithm) + final ShortestPathData data = getInputData(); + + // the graph + Graph graph = data.getGraph(); + + // node number + final int nbNodes = graph.size(); + int nodeId = 0; + + // initialize the labelstar list + LabelStar[] labels = new LabelStar[nbNodes]; + for(Node node : graph.getNodes()){ + nodeId = node.getId(); + labels[nodeId] = new LabelStar(node, false, Double.POSITIVE_INFINITY, Point.distance(node.getPoint(), data.getDestination().getPoint())); + } + + labels[data.getOrigin().getId()].computedCost = 0; + // variable that will contain the solution of the shortest path problem + ShortestPathSolution solution = null; + + //binary heap for selected lowest cost + BinaryHeap