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..8678668 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,33 @@ package org.insa.graphs.algorithm.shortestpath; +import org.insa.graphs.algorithm.AbstractInputData.Mode; +import org.insa.graphs.model.LabelStar; +import org.insa.graphs.model.Node; + public class AStarAlgorithm extends DijkstraAlgorithm { public AStarAlgorithm(ShortestPathData data) { super(data); } + + @Override + protected void initAlgo() { + + // Dijkstra guidée init + this.labels = new LabelStar[data.getGraph().size()]; + + if(data.getMode() == Mode.TIME) { + //time based, need to set LabelStar with maxspeed + for(Node node : data.getGraph().getNodes()) { + labels[node.getId()] = new LabelStar(node, getInputData().getDestination(), data.getGraph().getGraphInformation().getMaximumSpeed()); + } + } + else { + for(Node node : data.getGraph().getNodes()) { + labels[node.getId()] = new LabelStar(node, getInputData().getDestination()); + } + } + + } } diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java index 99b7b06..dd17fa1 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java @@ -12,16 +12,27 @@ import org.insa.graphs.model.Node; import org.insa.graphs.model.Path; public class DijkstraAlgorithm extends ShortestPathAlgorithm { + + + protected Label[] labels; public DijkstraAlgorithm(ShortestPathData data) { super(data); } + protected void initAlgo() { + // Dijkstra Init + this.labels = new Label[data.getGraph().size()]; + for(Node node : data.getGraph().getNodes()) { + labels[node.getId()] = new Label(node); + } + } + @Override protected ShortestPathSolution doRun() { final ShortestPathData data = getInputData(); - int numberOfNodes = data.getGraph().size(); + initAlgo(); double shortestCostToDestination = Double.POSITIVE_INFINITY; @@ -29,13 +40,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { // useful double lastMarkedNodeCost = 0; - // Dijkstra Init - Label[] labels = new Label[numberOfNodes]; - - - for(Node node : data.getGraph().getNodes()) { - labels[node.getId()] = new Label(node); - } // Let's set the origin cost at 0 labels[data.getOrigin().getId()].setNewCost(null, 0d); diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/Label.java b/be-graphes-model/src/main/java/org/insa/graphs/model/Label.java index 6163c4b..f82aef4 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/Label.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/Label.java @@ -2,10 +2,10 @@ package org.insa.graphs.model; public class Label implements Comparable