JUnits avec Oracle
This commit is contained in:
parent
b428e17ce8
commit
0484234692
3 changed files with 190 additions and 35 deletions
|
@ -27,9 +27,10 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
|
|||
vitesse = vitesse / 3.6 ;
|
||||
}
|
||||
for (Node node: graph.getNodes()) { // on crée un Label pour chaque node
|
||||
double distance = Point.distance( node.getPoint(), data.getDestination().getPoint() );
|
||||
TabLabel[node.getId()]= new LabelStar(node,distance/vitesse);
|
||||
}
|
||||
double distance = Point.distance( node.getPoint(), data.getDestination().getPoint() );
|
||||
TabLabel[node.getId()]= new LabelStar(node,distance/vitesse);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
TabLabel[data.getOrigin().getId()].setCost(0); // on met le cost du sommet à 0
|
||||
Tas.insert(TabLabel[data.getOrigin().getId()]); // on insert le label du sommet dans le tas
|
||||
|
||||
notifyOriginProcessed(data.getOrigin());
|
||||
this.notifyOriginProcessed(data.getOrigin());
|
||||
|
||||
double old_cost = 0 ; // on utilisera cette variable pour vérifier si le coût est croissant
|
||||
|
||||
|
@ -53,32 +53,36 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
}
|
||||
TabLabel[X.getId()].setMarque(true); // on le marque
|
||||
this.notifyNodeMarked(X);
|
||||
|
||||
if(old_cost > TabLabel[X.getId()].getTotalCost()) { //Vérification que le coût des labels marqués est croissant au cours des itérations.
|
||||
System.out.println("Le coût des Labels marqués n'est pas croissant");
|
||||
if( X == data.getDestination()) {
|
||||
this.notifyDestinationReached(data.getDestination());
|
||||
}
|
||||
old_cost = TabLabel[X.getId()].getTotalCost();
|
||||
|
||||
Tas.remove(TabLabel[X.getId()]);
|
||||
nbMarque++;
|
||||
for(Arc a : X.getSuccessors() ){ // Le nombre de successeurs explorés à chaque itération = au nombre de successeurs d'un node
|
||||
if (data.isAllowed(a)) {
|
||||
Node Y = a.getDestination();
|
||||
if(!(TabLabel[Y.getId()].isMarque() ) ) {
|
||||
if(TabLabel[Y.getId()].getCost()==Double.POSITIVE_INFINITY ) { //Y n'est pas dans le tas
|
||||
TabLabel[Y.getId()].setCost( TabLabel[X.getId()].getCost()+ data.getCost(a) );
|
||||
Tas.insert(TabLabel[Y.getId()]);
|
||||
TabLabel[Y.getId()].setFather(a);
|
||||
this.notifyNodeReached(Y);
|
||||
}
|
||||
else if(TabLabel[Y.getId()].getCost() > TabLabel[X.getId()].getCost()+ data.getCost(a)) {
|
||||
TabLabel[Y.getId()].setCost( TabLabel[X.getId()].getCost()+ data.getCost(a) );
|
||||
Tas.remove(TabLabel[Y.getId()]);
|
||||
Tas.insert(TabLabel[Y.getId()]);
|
||||
TabLabel[Y.getId()].setFather(a);
|
||||
}
|
||||
else {
|
||||
if(old_cost > TabLabel[X.getId()].getTotalCost()) { //Vérification que le coût des labels marqués est croissant au cours des itérations.
|
||||
System.out.println("Le coût des Labels marqués n'est pas croissant");
|
||||
}
|
||||
old_cost = TabLabel[X.getId()].getTotalCost();
|
||||
|
||||
Tas.remove(TabLabel[X.getId()]);
|
||||
nbMarque++;
|
||||
for(Arc a : X.getSuccessors() ){ // Le nombre de successeurs explorés à chaque itération = au nombre de successeurs d'un node
|
||||
if (data.isAllowed(a)) {
|
||||
Node Y = a.getDestination();
|
||||
if(!(TabLabel[Y.getId()].isMarque() ) ) {
|
||||
if(TabLabel[Y.getId()].getCost()==Double.POSITIVE_INFINITY ) { //Y n'est pas dans le tas
|
||||
TabLabel[Y.getId()].setCost( TabLabel[X.getId()].getCost()+ data.getCost(a) );
|
||||
Tas.insert(TabLabel[Y.getId()]);
|
||||
TabLabel[Y.getId()].setFather(a);
|
||||
this.notifyNodeReached(Y);
|
||||
}
|
||||
else if(TabLabel[Y.getId()].getCost() > TabLabel[X.getId()].getCost()+ data.getCost(a)) {
|
||||
TabLabel[Y.getId()].setCost( TabLabel[X.getId()].getCost()+ data.getCost(a) );
|
||||
Tas.remove(TabLabel[Y.getId()]);
|
||||
Tas.insert(TabLabel[Y.getId()]);
|
||||
TabLabel[Y.getId()].setFather(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,11 +97,9 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
solution = new ShortestPathSolution(data, Status.INFEASIBLE);
|
||||
}
|
||||
else {
|
||||
float length = 0;
|
||||
notifyDestinationReached(dest);
|
||||
double length = Labeldest.getTotalCost();
|
||||
while (a != null ) {
|
||||
arcs.add(a);
|
||||
length += a.getLength();
|
||||
a = TabLabel[a.getOrigin().getId()].getFather();
|
||||
//System.out.println(a);
|
||||
}
|
||||
|
@ -108,13 +110,13 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
|
||||
|
||||
|
||||
// Vérifier que la longueur du chemin (avec methode de la class Path) est identique au PCC de l'algorithme
|
||||
System.out.println("TEST : Vérifier que la longueur du chemin (avec methode de la class Path) est identique au PCC de l'algorithme");
|
||||
// Vérifier que la longueur du chemin (avec methode de la class Path) est identique à la longueur du PCC de l'algorithme
|
||||
System.out.println("TEST : Vérifier que la longueur du chemin (avec methode de la class Path) est identique à celle du PCC de l'algorithme");
|
||||
if( (int) path.getLength() == (int)length) {
|
||||
System.out.println("La longueur du chemin (avec methode de la class Path) est identique au PCC de l'algorithme");
|
||||
System.out.println("La longueur du chemin (avec methode de la class Path) est identique à celle du PCC de l'algorithme");
|
||||
}
|
||||
else {
|
||||
System.out.println( "Erreur : la longueur du chemin (avec methode de la class Path) n'est pas identique au PCC de l'algorithme, " + "Avec methode Path "+ path.getLength() + ", algorithme " + length) ;
|
||||
System.out.println( "Erreur : la longueur du chemin (avec methode de la class Path) n'est pas identique à celle du PCC de l'algorithme, " + "Avec methode Path "+ path.getLength() + ", algorithme " + length) ;
|
||||
}
|
||||
|
||||
//Vérifier que le chemin solution obtenu par Dijsktra est valide
|
||||
|
|
|
@ -0,0 +1,152 @@
|
|||
package org.insa.graphs.algorithm.utils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.insa.graphs.algorithm.ArcInspector;
|
||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||
import org.insa.graphs.algorithm.shortestpath.AStarAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.BellmanFordAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
||||
import org.insa.graphs.algorithm.utils.PriorityQueueTest.MutableInteger;
|
||||
import org.insa.graphs.algorithm.utils.PriorityQueueTest.TestParameters;
|
||||
import org.insa.graphs.model.Graph;
|
||||
import org.insa.graphs.model.Node;
|
||||
import org.insa.graphs.model.Path;
|
||||
import org.insa.graphs.model.io.BinaryGraphReader;
|
||||
import org.insa.graphs.model.io.GraphReader;
|
||||
import org.insa.graphs.model.io.PathReader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameter;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class ComparerAlgoTest {
|
||||
private static Graph graph1; // INSA --> Bikini
|
||||
private static Graph graph2; // Deux iles de Grèce
|
||||
|
||||
@Parameters
|
||||
public static Collection<ShortestPathData> data() {
|
||||
final String mapName1 = "/Users/auriane/Desktop/Maps/haute-garonne/haute-garonne.mapgr";
|
||||
final String mapName2 = "/Users/auriane/Desktop/Maps/greece/greece.mapgr";
|
||||
|
||||
try {
|
||||
FileInputStream F1 = new FileInputStream(mapName1);
|
||||
FileInputStream F2 = new FileInputStream(mapName2);
|
||||
}
|
||||
catch(Exception e){
|
||||
System.out.println("Maps not found");
|
||||
}
|
||||
|
||||
try {
|
||||
// Create a graph reader1.
|
||||
final GraphReader reader1 = new BinaryGraphReader(
|
||||
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName1))));
|
||||
//Read the graph1.
|
||||
graph1 = reader1.read();
|
||||
// Create a graph reader.
|
||||
final GraphReader reader2 = new BinaryGraphReader(
|
||||
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName2))));
|
||||
//Read the graph.
|
||||
graph2 = reader2.read();
|
||||
}
|
||||
catch(Exception e){
|
||||
System.out.println("Carte non lu");
|
||||
}
|
||||
|
||||
List<ArcInspector> ListeInspector = ArcInspectorFactory.getAllFilters() ;
|
||||
|
||||
Collection<ShortestPathData> objects = new ArrayList<>();
|
||||
// ---------------------Shortest path, all roads allowed : INSA --> Bikini -------------------------------------
|
||||
objects.add(new ShortestPathData(graph1, graph1.get(10991), graph1.get(10991), ListeInspector.get(0)));
|
||||
objects.add(new ShortestPathData(graph1, graph1.get(10991), graph1.get(63104), ListeInspector.get(0)));
|
||||
//---------------------Fastest path, all roads allowed : INSA --> Bikini ---------------------------------------
|
||||
objects.add(new ShortestPathData(graph1, graph1.get(10991), graph1.get(10991), ListeInspector.get(2)));
|
||||
objects.add(new ShortestPathData(graph1, graph1.get(10991), graph1.get(63104), ListeInspector.get(2)));
|
||||
// ---------------------Path with no solution : 2 islands in Greece ---------------------------------------------
|
||||
objects.add(new ShortestPathData(graph2, graph2.get(4368), graph1.get(4374), ListeInspector.get(0)));
|
||||
objects.add(new ShortestPathData(graph2, graph2.get(4368), graph1.get(4374), ListeInspector.get(2)));
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
||||
@Parameter
|
||||
public ShortestPathData parameters;
|
||||
|
||||
// -----------------------------DijkstraSingleNodeSP-------------------------------------
|
||||
@Test
|
||||
public void DijkstraSingleNodeSP() {
|
||||
Assume.assumeTrue(parameters.getOrigin() == parameters.getDestination() && parameters.getGraph().getMapName() != graph2.getMapName());
|
||||
ShortestPathAlgorithm DA = new DijkstraAlgorithm(parameters);
|
||||
ShortestPathAlgorithm BF = new BellmanFordAlgorithm(parameters);
|
||||
assertEquals( DA.run().getPath() , BF.run().getPath());
|
||||
}
|
||||
|
||||
// -----------------------------DijkstraNormalPathSP-------------------------------------
|
||||
@Test
|
||||
public void DijkstraNormalPathSP() {
|
||||
Assume.assumeFalse(parameters.getOrigin() == parameters.getDestination() || parameters.getGraph().getMapName() == graph2.getMapName());
|
||||
ShortestPathAlgorithm DA = new DijkstraAlgorithm(parameters);
|
||||
ShortestPathAlgorithm BF = new BellmanFordAlgorithm(parameters);
|
||||
//on compare la longueur des deux paths trouvés
|
||||
assertEquals( DA.run().getPath().getLength(), BF.run().getPath().getLength(), 0.01 );
|
||||
//on compare le temps de trajet des deux paths trouvés
|
||||
assertEquals( DA.run().getPath().getMinimumTravelTime(), DA.run().getPath().getMinimumTravelTime() , 0.01);
|
||||
}
|
||||
|
||||
// ---------------------------------AStarSingleNodeSP-------------------------------------
|
||||
@Test
|
||||
public void AStarSingleNodeSP() {
|
||||
Assume.assumeTrue(parameters.getOrigin() == parameters.getDestination() && parameters.getGraph().getMapName() != graph2.getMapName());
|
||||
AStarAlgorithm AS = new AStarAlgorithm(parameters);
|
||||
ShortestPathAlgorithm BF = new BellmanFordAlgorithm(parameters);
|
||||
assertEquals( AS.run().getPath() , BF.run().getPath());
|
||||
}
|
||||
|
||||
// ----------------------------------AStarNormalPathSP-------------------------------------
|
||||
@Test
|
||||
public void AStarNormalPathSP() {
|
||||
Assume.assumeFalse(parameters.getOrigin() == parameters.getDestination() || parameters.getGraph().getMapName() == graph2.getMapName());
|
||||
AStarAlgorithm AS = new AStarAlgorithm(parameters);
|
||||
ShortestPathAlgorithm BF = new BellmanFordAlgorithm(parameters);
|
||||
//on compare la longueur des deux paths trouvés
|
||||
assertEquals( AS.run().getPath().getLength(), BF.run().getPath().getLength(), 0.01 );
|
||||
//on compare le temps de trajet des deux paths trouvés
|
||||
assertEquals( AS.run().getPath().getMinimumTravelTime(), BF.run().getPath().getMinimumTravelTime() , 0.01);
|
||||
}
|
||||
|
||||
// ----------------------------------Dijkstra No Solution-------------------------------------
|
||||
public void DijkstraNoSolution() {
|
||||
Assume.assumeTrue(parameters.getGraph().getMapName() == graph2.getMapName() );
|
||||
ShortestPathAlgorithm DA = new DijkstraAlgorithm(parameters);
|
||||
ShortestPathAlgorithm BF = new BellmanFordAlgorithm(parameters);
|
||||
assertEquals( DA.run().getStatus() , BF.run().getStatus());
|
||||
}
|
||||
|
||||
// ----------------------------------AStar No Solution-------------------------------------
|
||||
public void AStarNoSolution() {
|
||||
Assume.assumeTrue(parameters.getGraph().getMapName() == graph2.getMapName() );
|
||||
AStarAlgorithm AS = new AStarAlgorithm(parameters);
|
||||
ShortestPathAlgorithm BF = new BellmanFordAlgorithm(parameters);
|
||||
assertEquals( AS.run().getStatus() , BF.run().getStatus());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in a new issue