From b48d1f16ecf8baa22b84401aacfc7380b83ef79e Mon Sep 17 00:00:00 2001 From: Nabzzz Date: Sun, 3 May 2020 12:18:39 +0200 Subject: [PATCH] Etape 5 terminee --- .../shortestpath/AStarAlgorithm.java | 33 +++++++++++++- .../shortestpath/DijkstraAlgorithm.java | 41 ++++++++++++++---- .../graphs/algorithm/shortestpath/Label.java | 26 +++++++++-- .../algorithm/shortestpath/LabelStar.java | 35 +++++++++++++++ .../shortestpath/AStarAlgorithm.class | Bin 524 -> 2731 bytes .../shortestpath/DijkstraAlgorithm.class | Bin 6655 -> 7043 bytes .../graphs/algorithm/shortestpath/Label.class | Bin 1736 -> 1947 bytes 7 files changed, 121 insertions(+), 14 deletions(-) create mode 100644 be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/LabelStar.java 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..5182549 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,38 @@ package org.insa.graphs.algorithm.shortestpath; -public class AStarAlgorithm extends DijkstraAlgorithm { +import org.insa.graphs.model.Graph; +import org.insa.graphs.model.Node; +import org.insa.graphs.model.Point; +import org.insa.graphs.algorithm.AbstractInputData.Mode; +public class AStarAlgorithm extends DijkstraAlgorithm { + public AStarAlgorithm(ShortestPathData data) { super(data); } - + + @Override protected void init(Label[] tabLabel, ShortestPathData data) + { double maxspeed=data.getMaximumSpeed(); + System.out.println("Max speed avant: "+maxspeed+"\n"); + if(maxspeed==-1) + { + maxspeed=(data.getGraph().getGraphInformation().getMaximumSpeed()); + //System.out.println("Max speed 2: "+maxspeed+"\n"); + maxspeed=maxspeed/3.6; + } + System.out.println("Max speed 3: "+maxspeed+"\n"); + if(data.getMode()==Mode.LENGTH) + { + maxspeed=1.0; + } + System.out.println("Max speed 4: "+maxspeed+"\n"); + //Initialization + for(Node n: data.getGraph().getNodes()) + { + tabLabel[n.getId()]=new LabelStar(n,Point.distance(n.getPoint(),data.getDestination().getPoint())/maxspeed); + } + //tabLabel[data.getOrigin().getId()].setCout(Point.distance(data.getOrigin().getPoint(),data.getDestination().getPoint())/maxspeed); + + } + } 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 db622ca..fc99775 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 @@ -16,7 +16,21 @@ import org.insa.graphs.model.Graph; import org.insa.graphs.model.Node; import org.insa.graphs.model.Path; public class DijkstraAlgorithm extends ShortestPathAlgorithm { - + + + protected void init(Label[] tabLabel, ShortestPathData data) + { + + //Initialization + for(Node n:data.getGraph().getNodes()) + { + tabLabel[n.getId()]=new Label(n); + } + //tabLabel[data.getOrigin().getId()].setCout(0); + + } + + public DijkstraAlgorithm(ShortestPathData data) { super(data); } @@ -28,12 +42,14 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { Graph graph = data.getGraph(); final int nbNodes=graph.size(); BinaryHeap