tests junit achevés et valides
This commit is contained in:
parent
f75175a71a
commit
320b07bc7f
2 changed files with 19 additions and 16 deletions
|
@ -3,7 +3,7 @@
|
||||||
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
||||||
import org.insa.graphs.algorithm.utils.BinaryHeap;
|
import org.insa.graphs.algorithm.utils.BinaryHeap;
|
||||||
import org.insa.graphs.model.Arc;
|
import org.insa.graphs.model.Arc;
|
||||||
import org.insa.graphs.model.Node;
|
import org.insa.graphs.model.Node;
|
||||||
import org.insa.graphs.model.Path;
|
import org.insa.graphs.model.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;//trier tout ça
|
import java.util.Collections;//trier tout ça
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
ShortestPathSolution solution = new ShortestPathSolution(data,Status.UNKNOWN);//modifié
|
ShortestPathSolution solution = new ShortestPathSolution(data,Status.UNKNOWN);//modifié
|
||||||
|
|
||||||
if (data.getDestination()==null || data.getOrigin()==null) {
|
if (data.getDestination()==null || data.getOrigin()==null) {
|
||||||
solution= new ShortestPathSolution(data, Status.INFEASIBLE, new Path(null));
|
solution= new ShortestPathSolution(data, Status.INFEASIBLE, new Path(data.getGraph()));
|
||||||
}else {
|
}else {
|
||||||
|
|
||||||
//initialisation
|
//initialisation
|
||||||
|
@ -95,7 +95,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!arrive) {
|
if (!arrive) {
|
||||||
solution= new ShortestPathSolution(data,Status.INFEASIBLE);
|
solution= new ShortestPathSolution(data,Status.INFEASIBLE, new Path(data.getGraph()));
|
||||||
}else {
|
}else {
|
||||||
|
|
||||||
this.notifyDestinationReached(data.getDestination());
|
this.notifyDestinationReached(data.getDestination());
|
||||||
|
|
|
@ -125,7 +125,6 @@ public class DijkstraAlgorithm_et_AStarTest{
|
||||||
onenodijk = (new DijkstraAlgorithm(onenodata)).run();
|
onenodijk = (new DijkstraAlgorithm(onenodata)).run();
|
||||||
emptydijk = (new DijkstraAlgorithm(emptydata)).run();
|
emptydijk = (new DijkstraAlgorithm(emptydata)).run();
|
||||||
invalidijk = (new DijkstraAlgorithm(invalidata)).run();
|
invalidijk = (new DijkstraAlgorithm(invalidata)).run();
|
||||||
System.out.print(invalidijk.toString());//----------------------hey, look here
|
|
||||||
|
|
||||||
//initialisation des A*
|
//initialisation des A*
|
||||||
asal = (new DijkstraAlgorithm(dataal)).run();
|
asal = (new DijkstraAlgorithm(dataal)).run();
|
||||||
|
@ -165,8 +164,8 @@ public class DijkstraAlgorithm_et_AStarTest{
|
||||||
assertTrue(dijkpt.getPath().isValid());
|
assertTrue(dijkpt.getPath().isValid());
|
||||||
assertTrue(onenodijk.getPath().isValid());
|
assertTrue(onenodijk.getPath().isValid());
|
||||||
assertTrue(emptydijk.getPath().isValid());
|
assertTrue(emptydijk.getPath().isValid());
|
||||||
assertFalse(invalidijk.getPath().isValid());
|
assertTrue(invalidijk.getPath().isValid());
|
||||||
}
|
}//note: invalidata ne peut pas trouver de chemin et contient ainsi un path null, donc valide
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cheminValideA() {
|
public void cheminValideA() {
|
||||||
|
@ -177,7 +176,7 @@ public class DijkstraAlgorithm_et_AStarTest{
|
||||||
assertTrue(aspt.getPath().isValid());
|
assertTrue(aspt.getPath().isValid());
|
||||||
assertTrue(asonenod.getPath().isValid());
|
assertTrue(asonenod.getPath().isValid());
|
||||||
assertTrue(asempty.getPath().isValid());
|
assertTrue(asempty.getPath().isValid());
|
||||||
assertFalse(asinvalid.getPath().isValid());
|
assertTrue(asinvalid.getPath().isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -225,7 +224,7 @@ public class DijkstraAlgorithm_et_AStarTest{
|
||||||
|
|
||||||
//grand scénario avec oracle:
|
//grand scénario avec oracle:
|
||||||
@Test
|
@Test
|
||||||
public void testmap() throws FileNotFoundException, IOException{//A FAIRE
|
public void testMap() throws FileNotFoundException, IOException{//A FAIRE
|
||||||
|
|
||||||
String mapaddr = "/home/favary/Bureau/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/haute-garonne.mapgr";
|
String mapaddr = "/home/favary/Bureau/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/haute-garonne.mapgr";
|
||||||
String pathaddr ="/home/favary/Bureau/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31_insa_aeroport_length.path";
|
String pathaddr ="/home/favary/Bureau/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31_insa_aeroport_length.path";
|
||||||
|
@ -244,23 +243,27 @@ public class DijkstraAlgorithm_et_AStarTest{
|
||||||
//comparaison de la longueur
|
//comparaison de la longueur
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: sans oracle
|
//long car la map bretagne (sans oracle possible) est assez importante
|
||||||
@Test
|
@Test
|
||||||
public void testMapNoOracle() throws FileNotFoundException, IOException{//A FAIRE
|
public void testMapNoOracle() throws FileNotFoundException, IOException{//A FAIRE
|
||||||
|
|
||||||
/*String mapaddr = "/home/favary/Bureau/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/bretagne.mapgr";
|
String mapaddr = "/home/favary/Bureau/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/bretagne.mapgr";
|
||||||
|
|
||||||
GraphReader graphread = new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream(mapaddr))));
|
GraphReader graphread = new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream(mapaddr))));
|
||||||
|
|
||||||
Graph graphmap = graphread.read();
|
Graph graphmap = graphread.read();
|
||||||
Node Origine = null;
|
Node Origine = graphmap.getNodes().get(100000);//Brest
|
||||||
Node Destination = null;//ces trois lignes à faire!
|
Node Destination = graphmap.getNodes().get(6000);//Rennes
|
||||||
Path pathmap = Path.createShortestPathFromNodes(graphmap, null);
|
|
||||||
|
//sans possibilité d'utiliser un pathmap, on fait une estimation arbitrairement basée sur la distance réelle
|
||||||
|
float estimation=1.2f*(float) (Origine.getPoint().distanceTo(Destination.getPoint()));
|
||||||
|
//1.2 très arbitraire, choisi car entre 1 (absurde) et sqrt(2)
|
||||||
|
//ne peut pas être adapté à tous les trajets, mais ici le graphe est assez couvrant et le trajet assez long
|
||||||
|
|
||||||
DijkstraAlgorithm dijkmap = new DijkstraAlgorithm(new ShortestPathData(graphmap, Origine, Destination, carlen));
|
DijkstraAlgorithm dijkmap = new DijkstraAlgorithm(new ShortestPathData(graphmap, Origine, Destination, carlen));
|
||||||
AStarAlgorithm asmap = new AStarAlgorithm(new ShortestPathData(graphmap, Origine, Destination, carlen));
|
AStarAlgorithm asmap = new AStarAlgorithm(new ShortestPathData(graphmap, Origine, Destination, carlen));
|
||||||
assertTrue(dijkmap.run().getPath().getLength()<=pathmap.getLength());
|
assertTrue(dijkmap.run().getPath().getLength()<estimation);
|
||||||
assertTrue(asmap.run().getPath().getLength()<=pathmap.getLength());
|
assertTrue(asmap.run().getPath().getLength()<estimation);//<= car pas optimal sans oracle
|
||||||
//comparaison de la longueur */
|
//comparaison de la longueur
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue