fin de séance, abandon des AccessRestrictions

This commit is contained in:
Favary Pierre 2021-05-18 18:18:48 +02:00
parent af1f34f75b
commit f75175a71a

View file

@ -56,31 +56,35 @@ public class DijkstraAlgorithm_et_AStarTest{
public static void initAll() throws IOException {
//TODO: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHHH
/*//gestion des restrictions pour pouvoir créer les Bellman-Ford
//rabbithole, mission annulée
//sinon, utilisation de toAccessInformation(), à condition de savoir quel bit correspond à quoi...
//gestion des restrictions pour pouvoir créer les Bellman-Ford
AccessRestrictions voiture, pedestre;
AccessRestrictions.AccessRestriction authorise = AccessRestrictions.AccessRestriction.ALLOWED;
/*AccessRestrictions.AccessRestriction authorise = AccessRestrictions.AccessRestriction.ALLOWED;
EnumMap<AccessMode, AccessRestrictions.AccessRestriction> pmap, vmap;
pmap = null;//dkgfvbwslidfue djeflmmqff^dfomqf^sf652s894fd5swrtwedf+e
vmap = new EnumMap<AccessMode, AccessRestrictions.AccessRestriction>();
vmap = null;//cette initalisation ne marche pas, COMMENT faire? ->toAccessInformation de voiture et pedestre sans passer par des EnumMap
pmap.put(AccessMode.FOOT, authorise);
vmap.put(AccessMode.MOTORCAR, authorise);
pedestre = new AccessRestrictions(pmap);
voiture = new AccessRestrictions(vmap);*/
//vmap.put(AccessMode.MOTORCAR, authorise);*/
//bloc actuellement inutile
RoadInformation speed10 = new RoadInformation(RoadType.MOTORWAY, null, false, 36, ""),
speed20 = new RoadInformation(RoadType.MOTORWAY, null, false, 72, ""),
pietonable = new RoadInformation(RoadType.PEDESTRIAN, null, false, 5, "");
voiture = new AccessRestrictions();//vmap en paramètre si possible
pedestre = new AccessRestrictions();//pmap en paramètre si possible
RoadInformation speed10 = new RoadInformation(RoadType.MOTORWAY, voiture, false, 36, ""),
speed20 = new RoadInformation(RoadType.MOTORWAY, voiture, false, 72, ""),
pietonable = new RoadInformation(RoadType.PEDESTRIAN, pedestre, false, 5, "");
//cyclable = new RoadInformation(RoadType.CYCLEWAY, null, false, 20, ""),
//toutes les routes ici sont à double sens
//attention, les piétons ont une maxspeed définie à 5
// Create nodes
nodes = new Node[8];
nodes = new Node[9];
for (int i = 0; i < nodes.length; ++i) {
nodes[i] = new Node(i, null);
}
// définition des arcs
// définition des arcs (graphe custom)
ab = Node.linkNodes(nodes[0], nodes[1], 10, speed10, null);
ac = Node.linkNodes(nodes[0], nodes[2], 50, speed20, null);
ad = Node.linkNodes(nodes[0], nodes[3], 15, speed10, null);
@ -103,45 +107,46 @@ public class DijkstraAlgorithm_et_AStarTest{
//initialisation des datas
dataal= new ShortestPathData(graph, nodes[0], nodes[4], alllen);//a->e
datacl= new ShortestPathData(graph, nodes[0], nodes[0], carlen);//b->g
dataat= new ShortestPathData(graph, nodes[0], nodes[0], alltime);//h->b
datact= new ShortestPathData(graph, nodes[0], nodes[0], cartime);//c->b
datapt= new ShortestPathData(graph, nodes[5], nodes[0], pietime);//f->e
datacl= new ShortestPathData(graph, nodes[1], nodes[6], carlen);//b->g
dataat= new ShortestPathData(graph, nodes[7], nodes[1], alltime);//h->b
datact= new ShortestPathData(graph, nodes[2], nodes[1], cartime);//c->b
datapt= new ShortestPathData(graph, nodes[5], nodes[4], pietime);//f->e
onenodata=new ShortestPathData(graph, nodes[2], nodes[2], pietime);
emptydata=new ShortestPathData(graph, null, null, pietime);
invalidata=new ShortestPathData(graph, nodes[0], nodes[7], carlen);//h est accessible uniquement aux piétons
invalidata=new ShortestPathData(graph, nodes[0], nodes[8], carlen);//h aurait être inaccessible aux voitures
//pour compenser, ajout du node i non relié
//initialisation des Dijkstras
dijkal = (new DijkstraAlgorithm(dataal)).run();
dijkcl = (new DijkstraAlgorithm(datacl)).run();
dijkat = (new DijkstraAlgorithm(dataat)).run();
dijkct = (new DijkstraAlgorithm(datact)).run();
//dijkpt = (new DijkstraAlgorithm(datapt)).run();//erreur ici
dijkpt = (new DijkstraAlgorithm(datapt)).run();
onenodijk = (new DijkstraAlgorithm(onenodata)).run();
emptydijk = (new DijkstraAlgorithm(emptydata)).run();//erreur ici
//invalidijk = (new DijkstraAlgorithm(invalidata)).run();//et erreur
emptydijk = (new DijkstraAlgorithm(emptydata)).run();
invalidijk = (new DijkstraAlgorithm(invalidata)).run();
System.out.print(invalidijk.toString());//----------------------hey, look here
//initialisation des A*
asal = (new DijkstraAlgorithm(dataal)).run();
ascl = (new DijkstraAlgorithm(datacl)).run();
asat = (new DijkstraAlgorithm(dataat)).run();
asct = (new DijkstraAlgorithm(datact)).run();
//aspt = (new DijkstraAlgorithm(datapt)).run();//erreur ici
aspt = (new DijkstraAlgorithm(datapt)).run();
asonenod = (new DijkstraAlgorithm(onenodata)).run();
asempty = (new DijkstraAlgorithm(emptydata)).run();//erreur ici
//asinvalid = (new DijkstraAlgorithm(invalidata)).run();//et erreur
asempty = (new DijkstraAlgorithm(emptydata)).run();
asinvalid = (new DijkstraAlgorithm(invalidata)).run();
//initialisation des Bellman-Ford pour comparaison
bfaal = (new BellmanFordAlgorithm(dataal)).run();
//bfacl = (new BellmanFordAlgorithm(datacl)).run();
/*bfaat = (new BellmanFordAlgorithm(dataat)).run();
bfacl = (new BellmanFordAlgorithm(datacl)).run();
bfaat = (new BellmanFordAlgorithm(dataat)).run();
bfact = (new BellmanFordAlgorithm(datact)).run();
bfapt = (new BellmanFordAlgorithm(datapt)).run();*/ //erreurs partout ici...
bfapt = (new BellmanFordAlgorithm(datapt)).run();
}
//créer plus et avec des maps différentes
//faire des test spécifiques pour longs trajets
/* ( Test faits directement via la console et DijkstraAlgorithm.java, actuellement commentés:
@ -149,16 +154,18 @@ public class DijkstraAlgorithm_et_AStarTest{
- nbr successeurs cohérents
- tas valide. ) */
@Test
public void cheminValideD() {
assertTrue(dijkal.getPath().isValid());
assertTrue(dijkcl.getPath().isValid());
assertTrue(dijkat.getPath().isValid());
assertTrue(dijkct.getPath().isValid());
//assertTrue(dijkpt.getPath().isValid());//pas normal
assertTrue(dijkpt.getPath().isValid());
assertTrue(onenodijk.getPath().isValid());
assertTrue(emptydijk.getPath().isValid());
//assertFalse(invalidijk.getPath().isValid());
assertFalse(invalidijk.getPath().isValid());
}
@Test
@ -167,10 +174,10 @@ public class DijkstraAlgorithm_et_AStarTest{
assertTrue(ascl.getPath().isValid());
assertTrue(asat.getPath().isValid());
assertTrue(asct.getPath().isValid());
//assertTrue(aspt.getPath().isValid());//pas normal
assertTrue(aspt.getPath().isValid());
assertTrue(asonenod.getPath().isValid());
assertTrue(asempty.getPath().isValid());
//assertFalse(asinvalid.getPath().isValid());
assertFalse(asinvalid.getPath().isValid());
}
@Test
@ -179,10 +186,10 @@ public class DijkstraAlgorithm_et_AStarTest{
assertTrue(dijkcl.isFeasible());
assertTrue(dijkat.isFeasible());
assertTrue(dijkct.isFeasible());
//assertTrue(dijkpt.isFeasible());
assertTrue(dijkpt.isFeasible());
assertTrue(onenodijk.isFeasible());
assertFalse(emptydijk.isFeasible());
//assertFalse(invalidijk.isFeasible());
assertFalse(invalidijk.isFeasible());
}
@Test
@ -191,29 +198,29 @@ public class DijkstraAlgorithm_et_AStarTest{
assertTrue(ascl.isFeasible());
assertTrue(asat.isFeasible());
assertTrue(asct.isFeasible());
//assertTrue(aspt.isFeasible());
assertTrue(aspt.isFeasible());
assertTrue(asonenod.isFeasible());
assertFalse(asempty.isFeasible());
//assertFalse(asinvalid.isFeasible());
assertFalse(asinvalid.isFeasible());
}
//résultat identique à Bellman-Ford (sur les petits scénarios)
@Test
public void DsameasBF() {
assertTrue(Float.compare(dijkal.getPath().getLength(),bfaal.getPath().getLength())==0);
//assertTrue(Float.compare(dijkcl.getPath().getLength(),bfacl.getPath().getLength())==0);
//assertTrue(Double.compare(dijkat.getPath().getMinimumTravelTime(),bfaat.getPath().getMinimumTravelTime())==0);
//assertTrue(Double.compare(dijkct.getPath().getMinimumTravelTime(),bfact.getPath().getMinimumTravelTime())==0);
//assertTrue(Double.compare(dijkpt.getPath().getMinimumTravelTime(),bfapt.getPath().getMinimumTravelTime())==0);
assertTrue(Float.compare(dijkcl.getPath().getLength(),bfacl.getPath().getLength())==0);
assertTrue(Double.compare(dijkat.getPath().getMinimumTravelTime(),bfaat.getPath().getMinimumTravelTime())==0);
assertTrue(Double.compare(dijkct.getPath().getMinimumTravelTime(),bfact.getPath().getMinimumTravelTime())==0);
assertTrue(Double.compare(dijkpt.getPath().getMinimumTravelTime(),bfapt.getPath().getMinimumTravelTime())==0);
}
@Test
public void AsameasBF() {
assertTrue(Float.compare(asal.getPath().getLength(),bfaal.getPath().getLength())==0);
//assertTrue(Float.compare(ascl.getPath().getLength(),bfacl.getPath().getLength())==0);
//assertTrue(Double.compare(asat.getPath().getMinimumTravelTime(),bfaat.getPath().getMinimumTravelTime())==0);
//assertTrue(Double.compare(asct.getPath().getMinimumTravelTime(),bfact.getPath().getMinimumTravelTime())==0);
//assertTrue(Double.compare(aspt.getPath().getMinimumTravelTime(),bfapt.getPath().getMinimumTravelTime())==0);
assertTrue(Float.compare(ascl.getPath().getLength(),bfacl.getPath().getLength())==0);
assertTrue(Double.compare(asat.getPath().getMinimumTravelTime(),bfaat.getPath().getMinimumTravelTime())==0);
assertTrue(Double.compare(asct.getPath().getMinimumTravelTime(),bfact.getPath().getMinimumTravelTime())==0);
assertTrue(Double.compare(aspt.getPath().getMinimumTravelTime(),bfapt.getPath().getMinimumTravelTime())==0);
}
//grand scénario avec oracle:
@ -227,18 +234,33 @@ public class DijkstraAlgorithm_et_AStarTest{
PathReader pathread = new BinaryPathReader(new DataInputStream(new BufferedInputStream(new FileInputStream(pathaddr))));
Graph graphmap = graphread.read();
Path pathmap = pathread.readPath(graphmap);//erreur ici mais pas mapmismatch, donc pourquoi? Path impossible? (hem) TODO: correct this
//quel inspector prendre? Le path est en longueur mais voitures seulement ou tout autorisé?
DijkstraAlgorithm dijkmap = new DijkstraAlgorithm(new ShortestPathData(graphmap, pathmap.getOrigin(), pathmap.getDestination(), alllen));
AStarAlgorithm asmap = new AStarAlgorithm(new ShortestPathData(graphmap, pathmap.getOrigin(), pathmap.getDestination(), alllen));
Path pathmap = pathread.readPath(graphmap);
//après test, il faut prendre carlen et non alllen en ArcInspector (sinon A* et Dijkstra sont plus courts)
DijkstraAlgorithm dijkmap = new DijkstraAlgorithm(new ShortestPathData(graphmap, pathmap.getOrigin(), pathmap.getDestination(), carlen));
AStarAlgorithm asmap = new AStarAlgorithm(new ShortestPathData(graphmap, pathmap.getOrigin(), pathmap.getDestination(), carlen));
assertTrue(dijkmap.run().getPath().getLength()==pathmap.getLength());
assertTrue(asmap.run().getPath().getLength()==pathmap.getLength());
//comparaison de la longueur
}
//TODO: sans oracle
//idem mais au lieu du path trouver les ids de deux nodes valides?
@Test
public void testMapNoOracle() throws FileNotFoundException, IOException{//A FAIRE
/*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))));
Graph graphmap = graphread.read();
Node Origine = null;
Node Destination = null;//ces trois lignes à faire!
Path pathmap = Path.createShortestPathFromNodes(graphmap, null);
DijkstraAlgorithm dijkmap = new DijkstraAlgorithm(new ShortestPathData(graphmap, Origine, Destination, carlen));
AStarAlgorithm asmap = new AStarAlgorithm(new ShortestPathData(graphmap, Origine, Destination, carlen));
assertTrue(dijkmap.run().getPath().getLength()<=pathmap.getLength());
assertTrue(asmap.run().getPath().getLength()<=pathmap.getLength());
//comparaison de la longueur */
}
}