Remise Du BE - Version fonctionnelle : Correction de l'erreur sur l'estimation dans A*, finalisation des tests d'optimalité, ajout des tests de performances
This commit is contained in:
parent
c912cac967
commit
1eef4d2656
7 changed files with 107 additions and 53 deletions
|
@ -19,26 +19,14 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
|
|||
}
|
||||
|
||||
if (data.getMode() == Mode.LENGTH) {
|
||||
MaxSpeed = 1;
|
||||
MaxSpeed = 1.01;
|
||||
} else {
|
||||
MaxSpeed = MaxSpeed / 3.6;
|
||||
}
|
||||
|
||||
//double longueurArc = 0.0;
|
||||
|
||||
for (Node node: data.getGraph().getNodes()) {
|
||||
double estimation = Point.distance(node.getPoint(), data.getDestination().getPoint())/MaxSpeed;
|
||||
labels[node.getId()] = new LabelStar(node, estimation);
|
||||
/*if (node.getId() == 6800) {
|
||||
for (Arc arc: node.getSuccessors()) {
|
||||
if (arc.getDestination().getId() == 6299) {
|
||||
longueurArc = arc.getLength();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
//System.out.println("La distance entre les nodes " + data.getGraph().getNodes().get(6800).getId() + " et " + data.getGraph().getNodes().get(6299).getId() + " est : " + Point.distance(data.getGraph().getNodes().get(6800).getPoint(), data.getGraph().getNodes().get(6299).getPoint()) + " et la longeur de l'arc est : " + longueurArc);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,10 +55,9 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
notifyNodeMarked(current.getSommetCourant());
|
||||
|
||||
// POUR LE TEST SUR LES COUTS CROISSANTS
|
||||
//System.out.println("Test sur le coût : " + labels[currentID].getTotalCost());
|
||||
if (labels[currentID].compareTo(labels[ancienID]) == -1) {
|
||||
System.out.println("Erreur : Couts non croissants : noeud" + ancienID + " contre " + currentID);
|
||||
}
|
||||
System.out.println("Erreur : Couts non croissants : noeud " + ancienID + " (" + labels[ancienID].getTotalCost() + "; " + labels[ancienID].getEstimation() + ") contre " + currentID + " (" + labels[currentID].getTotalCost() + "; " + labels[currentID].getEstimation() + ") ");
|
||||
}
|
||||
ancienID = currentID;
|
||||
|
||||
//nbNonMarque--;
|
||||
|
@ -93,8 +92,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
if (compteur_successeurs != labels[currentID].getSommetCourant().getNumberOfSuccessors()) {
|
||||
System.out.println("ERREUR Nombre de successeurs visités : " + compteur_successeurs + "/" + labels[currentID].getSommetCourant().getNumberOfSuccessors());
|
||||
}
|
||||
//System.out.println("Nombre de successeurs visités : " + compteur_successeurs + "/" + labels[currentID].getSommetCourant().getNumberOfSuccessors());
|
||||
}
|
||||
}
|
||||
catch (EmptyPriorityQueueException e) {
|
||||
encore = false;
|
||||
}
|
||||
|
|
|
@ -51,16 +51,17 @@ public class Label implements Comparable<Label>{
|
|||
}
|
||||
|
||||
public int compareTo(Label o) {
|
||||
double epsilon = 0.0;
|
||||
double diff = this.getTotalCost() - o.getTotalCost();
|
||||
if (diff < 0.0) {
|
||||
if (diff < -epsilon) {
|
||||
return -1;
|
||||
} else if (diff > 0.0) {
|
||||
} else if (diff > epsilon) {
|
||||
return 1;
|
||||
} else {
|
||||
diff = this.getEstimation() - o.getEstimation();
|
||||
if (diff < 0.0) {
|
||||
if (diff < -epsilon) {
|
||||
return -1;
|
||||
} else if (diff > 0.0) {
|
||||
} else if (diff > epsilon) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
|
|
|
@ -17,6 +17,6 @@ public class LabelStar extends Label implements Comparable<Label>{
|
|||
}
|
||||
|
||||
public double getTotalCost() {
|
||||
return this.estimation + this.getCost();
|
||||
return this.estimation + super.getCost();
|
||||
}
|
||||
}
|
|
@ -175,14 +175,18 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
|||
|
||||
public boolean IsValid() {
|
||||
boolean valid = true;
|
||||
int last_element_a_check = (int)(Math.pow(2.0, Math.floor(Math.log(this.currentSize))) - 1);
|
||||
int i = 0;
|
||||
while (i < last_element_a_check && valid) {
|
||||
if ((this.array.get(i).compareTo(this.array.get(this.indexLeft(i))) == 1) || (this.array.get(i).compareTo(this.array.get(this.indexLeft(i) + 1))) == 1) {
|
||||
valid = false;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
if (!this.isEmpty()) {
|
||||
int last_element_a_check = (int)(Math.pow(2.0, Math.floor(Math.log(this.currentSize))) - 1);
|
||||
int i = 0;
|
||||
while (i < last_element_a_check && valid) {
|
||||
if (this.indexLeft(i) < this.currentSize && (this.array.get(this.indexLeft(i)).compareTo(this.array.get(i)) == -1)) {
|
||||
valid = false;
|
||||
}
|
||||
if (this.indexLeft(i)+1 < this.currentSize &&(this.array.get(this.indexLeft(i) + 1).compareTo(this.array.get(i)) == -1)) {
|
||||
valid = false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
|
|
@ -157,26 +157,4 @@ public class OptimaliteTest {
|
|||
assertEquals(solutionBellmanFord.getPath().getLength(),solutionDijkstra.getPath().getLength(), OptimaliteTest.delta);
|
||||
assertEquals(solutionBellmanFord.getPath().getLength(),solutionAStar.getPath().getLength(), OptimaliteTest.delta);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDijkstraPlusRapide() {
|
||||
// On ne fait le test qu'avec un filtre sur les chemins autorisés
|
||||
ShortestPathData data = new ShortestPathData(graph, graph.get(75870), graph.get(103867), ArcInspectorFactory.getAllFilters().get(0));
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathAlgorithm aStar = new AStarAlgorithm(data);
|
||||
ShortestPathSolution solutionAStar = aStar.run();
|
||||
ShortestPathSolution solutionDijkstra = dijkstra.run();
|
||||
assertTrue(solutionDijkstra.getSolvingTime().compareTo(solutionAStar.getSolvingTime()) < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAStarPlusRapide() {
|
||||
// On ne fait le test qu'avec un filtre sur les chemins autorisés
|
||||
ShortestPathData data = new ShortestPathData(graph, graph.get(12305), graph.get(103867), ArcInspectorFactory.getAllFilters().get(0));
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathAlgorithm aStar = new AStarAlgorithm(data);
|
||||
ShortestPathSolution solutionAStar = aStar.run();
|
||||
ShortestPathSolution solutionDijkstra = dijkstra.run();
|
||||
assertTrue(solutionDijkstra.getSolvingTime().compareTo(solutionAStar.getSolvingTime()) > 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
package org.insa.graphs.algorithm.shortestpath;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import org.insa.graphs.model.io.BinaryGraphReader;
|
||||
import org.insa.graphs.model.io.GraphReader;
|
||||
import org.insa.graphs.model.Graph;
|
||||
|
||||
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.AStarAlgorithm;
|
||||
|
||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
||||
|
||||
public class PerformancesTest {
|
||||
|
||||
// Graph utilisé pour les tests
|
||||
static Graph graph;
|
||||
|
||||
//Lecture du graphe
|
||||
@BeforeClass
|
||||
public static void initAll() throws Exception {
|
||||
final String mapName = "/home/paulfaure/Documents/3A/JAVA/Cartes BE/haute-garonne/europe/france/haute-garonne.mapgr";
|
||||
|
||||
// Create a graph reader.
|
||||
final GraphReader reader = new BinaryGraphReader(
|
||||
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
|
||||
|
||||
// Read the graph.
|
||||
PerformancesTest.graph = reader.read();
|
||||
|
||||
reader.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDijkstraPlusRapidePetitTrajet() {
|
||||
// On ne fait le test qu'avec un filtre sur les chemins autorisés
|
||||
ShortestPathData data = new ShortestPathData(graph, graph.get(87500), graph.get(103867), ArcInspectorFactory.getAllFilters().get(0));
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathAlgorithm aStar = new AStarAlgorithm(data);
|
||||
ShortestPathSolution solutionAStar = aStar.run();
|
||||
ShortestPathSolution solutionDijkstra = dijkstra.run();
|
||||
assertTrue(solutionDijkstra.getSolvingTime().compareTo(solutionAStar.getSolvingTime()) < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDijkstraPlusRapideCheminNul() {
|
||||
// On ne fait le test qu'avec un filtre sur les chemins autorisés
|
||||
ShortestPathData data = new ShortestPathData(graph, graph.get(103867), graph.get(103867), ArcInspectorFactory.getAllFilters().get(0));
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathAlgorithm aStar = new AStarAlgorithm(data);
|
||||
ShortestPathSolution solutionAStar = aStar.run();
|
||||
ShortestPathSolution solutionDijkstra = dijkstra.run();
|
||||
assertTrue(solutionDijkstra.getSolvingTime().compareTo(solutionAStar.getSolvingTime()) < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDijkstraPlusRapideCheminInexistant() {
|
||||
// On ne fait le test qu'avec un filtre sur les chemins autorisés
|
||||
ShortestPathData data = new ShortestPathData(graph, graph.get(135847), graph.get(103867), ArcInspectorFactory.getAllFilters().get(0));
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathAlgorithm aStar = new AStarAlgorithm(data);
|
||||
ShortestPathSolution solutionAStar = aStar.run();
|
||||
ShortestPathSolution solutionDijkstra = dijkstra.run();
|
||||
assertTrue(solutionDijkstra.getSolvingTime().compareTo(solutionAStar.getSolvingTime()) < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAStarPlusRapideLongTrajet() {
|
||||
// On ne fait le test qu'avec un filtre sur les chemins autorisés
|
||||
ShortestPathData data = new ShortestPathData(graph, graph.get(12305), graph.get(103867), ArcInspectorFactory.getAllFilters().get(0));
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathAlgorithm aStar = new AStarAlgorithm(data);
|
||||
ShortestPathSolution solutionAStar = aStar.run();
|
||||
ShortestPathSolution solutionDijkstra = dijkstra.run();
|
||||
assertTrue(solutionDijkstra.getSolvingTime().compareTo(solutionAStar.getSolvingTime()) > 0);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue