pause repas (junit en cours)
This commit is contained in:
parent
d8fe9068ac
commit
d1acc6cdf5
3 changed files with 99 additions and 38 deletions
|
@ -7,7 +7,7 @@ import org.insa.graphs.model.Node;
|
|||
|
||||
public class AStarAlgorithm extends DijkstraAlgorithm {
|
||||
|
||||
|
||||
// au cas où data.getMaximumSpeed soit parfois définie
|
||||
private int sineg(int a, int b) {
|
||||
int retour=a;
|
||||
if (a<1)
|
||||
|
@ -17,11 +17,13 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
|
|||
|
||||
private int vitessemax=sineg(data.getMaximumSpeed(), data.getGraph().getGraphInformation().getMaximumSpeed());
|
||||
|
||||
|
||||
|
||||
public AStarAlgorithm(ShortestPathData data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
|
||||
public Label LabelTyped(Node sommet, Arc padre, float prix) {
|
||||
|
||||
float difference=(float)this.getInputData().getDestination().getPoint().distanceTo(sommet.getPoint());
|
||||
|
@ -32,11 +34,5 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
|
|||
|
||||
return new LabelStar(sommet, padre, prix, difference);
|
||||
}
|
||||
|
||||
//particularités de A*:
|
||||
//-comment trouver la distance à vol d'oiseau entre deux nodes?--------node.getpoint().distanceTo()?
|
||||
//comment avoir (le temps min ou) la vitesse max?
|
||||
//-comment initialiser le labelstar.estim de chaque node avec cette méthode
|
||||
//-comment avoir des LabelStar et non des Label
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,36 +2,96 @@ package org.insa.graphs.algorithm.shortestpath;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.insa.graphs.*;//voir si on ne peut pas importer launch autrement
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.insa.graphs.algorithm.ArcInspector;
|
||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||
import org.insa.graphs.algorithm.shortestpath.*;
|
||||
import org.insa.graphs.model.Arc;
|
||||
import org.insa.graphs.model.Graph;
|
||||
import org.insa.graphs.model.Node;
|
||||
import org.insa.graphs.model.Path;
|
||||
import org.insa.graphs.model.RoadInformation;
|
||||
import org.insa.graphs.model.*;
|
||||
import org.insa.graphs.model.RoadInformation.RoadType;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DijkstraAlgorithmTest {
|
||||
public class DijkstraAlgorithmTest{
|
||||
|
||||
//copié sur PathTest.java
|
||||
// Small graph use for tests
|
||||
private static Graph graph;
|
||||
|
||||
// List of nodes
|
||||
private static Node[] nodes;
|
||||
|
||||
// List of arcs in the graph, a2b is the arc from node A (0) to B (1).
|
||||
@SuppressWarnings("unused")
|
||||
private static Arc a2b, a2c, a2e, b2c, c2d_1, c2d_2, c2d_3, c2a, d2a, d2e, e2d;
|
||||
|
||||
// Some paths...
|
||||
private static Path emptyPath, singleNodePath, shortPath, longPath, loopPath, longLoopPath,
|
||||
invalidPath;
|
||||
|
||||
@BeforeClass
|
||||
public static void initAll() throws IOException {
|
||||
|
||||
// 10 and 20 meters per seconds
|
||||
RoadInformation speed10 = new RoadInformation(RoadType.MOTORWAY, null, true, 36, ""),
|
||||
speed20 = new RoadInformation(RoadType.MOTORWAY, null, true, 72, "");
|
||||
|
||||
// Create nodes
|
||||
nodes = new Node[5];
|
||||
for (int i = 0; i < nodes.length; ++i) {
|
||||
nodes[i] = new Node(i, null);
|
||||
}
|
||||
|
||||
// Add arcs...
|
||||
a2b = Node.linkNodes(nodes[0], nodes[1], 10, speed10, null);
|
||||
a2c = Node.linkNodes(nodes[0], nodes[2], 15, speed10, null);
|
||||
a2e = Node.linkNodes(nodes[0], nodes[4], 15, speed20, null);
|
||||
b2c = Node.linkNodes(nodes[1], nodes[2], 10, speed10, null);
|
||||
c2d_1 = Node.linkNodes(nodes[2], nodes[3], 20, speed10, null);
|
||||
c2d_2 = Node.linkNodes(nodes[2], nodes[3], 10, speed10, null);
|
||||
c2d_3 = Node.linkNodes(nodes[2], nodes[3], 15, speed20, null);
|
||||
d2a = Node.linkNodes(nodes[3], nodes[0], 15, speed10, null);
|
||||
d2e = Node.linkNodes(nodes[3], nodes[4], 22.8f, speed20, null);
|
||||
e2d = Node.linkNodes(nodes[4], nodes[0], 10, speed10, null);
|
||||
|
||||
graph = new Graph("ID", "", Arrays.asList(nodes), null);
|
||||
|
||||
emptyPath = new Path(graph, new ArrayList<Arc>());
|
||||
singleNodePath = new Path(graph, nodes[1]);
|
||||
shortPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1 }));
|
||||
longPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2e }));
|
||||
loopPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2a }));
|
||||
longLoopPath = new Path(graph,
|
||||
Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2a, a2c, c2d_3, d2a, a2b, b2c }));
|
||||
invalidPath = new Path(graph, Arrays.asList(new Arc[] { a2b, c2d_1, d2e }));
|
||||
|
||||
}
|
||||
//---fin de la copie de PathTest.java
|
||||
|
||||
//regarder LAUNCH.JAVA pour ouvrir une map
|
||||
|
||||
private static DijkstraAlgorithm samenode, bikinsatime, bikinsalong, invalinsa;
|
||||
private static BellmanFordAlgorithm Bsamenode, Bbikinsatime, Bbikinsalong, Binvalinsa;
|
||||
private static ShortestPathData samenodespd, bikinsatimespd, bikinsalongspd, invalinsaspd;
|
||||
|
||||
private static Graph graph;
|
||||
private static Node origine;//trouver ces nodes
|
||||
private static Node bikini;
|
||||
private static Node inaccessible;
|
||||
//en créer plus et avec des maps différentes
|
||||
// (cf l.187 excel ggdoc) permet de savoir quels arcs autoriser
|
||||
private ArcInspector inspecteuruno=ArcInspectorFactory.getAllFilters().get(0);// No filter (all arcs allowed)
|
||||
private ArcInspector inspecteurtres=ArcInspectorFactory.getAllFilters().get(2);// Only road allowed for cars and time
|
||||
|
||||
|
||||
//créer plus et avec des maps différentes
|
||||
//faire des test spécifiques pour longs trajets
|
||||
|
||||
@BeforeClass
|
||||
public static void initAll() {
|
||||
|
||||
/*@BeforeClass
|
||||
public static void initAllbis() {
|
||||
//en fait pas sûr que ça marche comme ça, voir avec Launch
|
||||
samenodespd=new ShortestPathData(graph, null, null, null);
|
||||
bikinsatimespd=new ShortestPathData(graph, null, null, null);
|
||||
bikinsalongspd=new ShortestPathData(graph, null, null, null);
|
||||
|
@ -46,15 +106,23 @@ public class DijkstraAlgorithmTest {
|
|||
Bbikinsatime= new BellmanFordAlgorithm(bikinsatimespd);
|
||||
Bbikinsalong=new BellmanFordAlgorithm(bikinsalongspd);
|
||||
Binvalinsa=new BellmanFordAlgorithm(invalinsaspd);
|
||||
}
|
||||
}*/
|
||||
|
||||
//test faits directement via la console et DijkstraAlgorithm.java:
|
||||
//(coûts croissants)
|
||||
//(nbr successeurs cohérents)
|
||||
//(tas valide)
|
||||
//comment trouver les noeuds dans une map? Ne comparer que les grands chemins (qui font ouvrir la map) avec BF
|
||||
|
||||
/*(Test faits directement via la console et DijkstraAlgorithm.java, actuellement commentés:
|
||||
-coûts croissants
|
||||
-nbr successeurs cohérents
|
||||
-tas valide.)*/
|
||||
|
||||
@Test
|
||||
public void cheminValide() {
|
||||
ShortestPathData data1=new ShortestPathData(null, null, null, inspecteuruno);
|
||||
ShortestPathData data3=new ShortestPathData(null, null, null, inspecteurtres);
|
||||
ShortestPathAlgorithm Dijkstra1=new DijkstraAlgorithm(data1);
|
||||
ShortestPathAlgorithm Dijkstra3=new DijkstraAlgorithm(data3);
|
||||
assertTrue(Dijkstra1.doRun().getPath().isValid());
|
||||
assertTrue(Dijkstra3.doRun().getPath().isValid());
|
||||
assertTrue(samenode.doRun().getPath().isValid());
|
||||
assertTrue(bikinsatime.doRun().getPath().isValid());
|
||||
assertTrue(bikinsalong.doRun().getPath().isValid());
|
||||
|
@ -63,22 +131,18 @@ public class DijkstraAlgorithmTest {
|
|||
|
||||
@Test
|
||||
public void faisable() {
|
||||
ShortestPathData data1=new ShortestPathData(null, null, null, inspecteuruno);
|
||||
ShortestPathData data3=new ShortestPathData(null, null, null, inspecteurtres);
|
||||
ShortestPathAlgorithm Dijkstra1=new DijkstraAlgorithm(data1);
|
||||
ShortestPathAlgorithm Dijkstra3=new DijkstraAlgorithm(data3);
|
||||
assertTrue(Dijkstra1.doRun().isFeasible());
|
||||
assertTrue(Dijkstra3.doRun().isFeasible());
|
||||
assertTrue(samenode.doRun().isFeasible());
|
||||
assertTrue(bikinsatime.doRun().isFeasible());
|
||||
assertTrue(bikinsalong.doRun().isFeasible());
|
||||
assertFalse(invalinsa.doRun().isFeasible());
|
||||
}
|
||||
|
||||
//cout calculé par Dijkstra identique à celui calculé par Path (comparaison pas avec ==)
|
||||
//comment ça? Dijkstra ne renvoie pas le cout du path dans ShortestPathSolution, obligé d'utiliser getPath.getCout
|
||||
//sans doute à voir avec comment demander un cout en temps ou en longueur
|
||||
@Test
|
||||
public void sameasPath() {
|
||||
assertTrue(samenode.doRun().getPath().isValid());//à faire
|
||||
assertTrue(bikinsatime.doRun().getPath().isValid());
|
||||
assertTrue(bikinsalong.doRun().getPath().isValid());
|
||||
assertTrue(invalinsa.doRun().getPath().isValid());
|
||||
}
|
||||
|
||||
//résultat identique à Bellman-Ford (sur les petits scénarios)
|
||||
@Test
|
||||
|
@ -89,7 +153,8 @@ public class DijkstraAlgorithmTest {
|
|||
assertTrue(invalinsa.doRun().getPath().equals(Binvalinsa.doRun().getPath()));
|
||||
}
|
||||
|
||||
//tests applicables aussi pour des grands scénarios
|
||||
//tests applicables aussi pour des grands scénarios:
|
||||
//...
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue