123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- 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.*;
- import org.insa.graphs.model.RoadInformation.RoadType;
- import org.junit.BeforeClass;
- import org.junit.Test;
-
- 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;
-
- private static ShortestPathData dataal, datacl, dataat, datact, datapt, onenodata, emptydata, invalidata;
-
- // permet de savoir quels arcs autoriser(cf l.187 excel ggdoc)
- private static ArcInspector alllen = ArcInspectorFactory.getAllFilters().get(0);
- private static ArcInspector carlen = ArcInspectorFactory.getAllFilters().get(1);
- private static ArcInspector alltime = ArcInspectorFactory.getAllFilters().get(2);
- private static ArcInspector cartime = ArcInspectorFactory.getAllFilters().get(3);
- private static ArcInspector pietime = ArcInspectorFactory.getAllFilters().get(4);
-
- private static DijkstraAlgorithm dijkal, dijkcl, dijkat, dijkct, dijkpt, onenodijk, emptydijk, invalidijk;
- private static BellmanFordAlgorithm bfaal, bfacl, bfaat, bfact, bfapt;
-
-
- @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);
-
- //initialisation des datas
- dataal= new ShortestPathData(graph, null, null, alllen);
- datacl= new ShortestPathData(graph, null, null, carlen);
- dataat= new ShortestPathData(graph, null, null, alltime);
- datact= new ShortestPathData(graph, null, null, cartime);
- datapt= new ShortestPathData(graph, null, null, pietime);
- onenodata=new ShortestPathData(graph, nodes[2], nodes[2], pietime);
- emptydata=new ShortestPathData(graph, null, null, pietime);
- invalidata=new ShortestPathData(graph, null, null, pietime);
-
- //initialisation des Dijkstras
- dijkal=new DijkstraAlgorithm(dataal);
- dijkcl=new DijkstraAlgorithm(datacl);
- dijkat=new DijkstraAlgorithm(dataat);
- dijkct=new DijkstraAlgorithm(datact);
- dijkpt=new DijkstraAlgorithm(datapt);
- onenodijk=new DijkstraAlgorithm(onenodata);
- emptydijk=new DijkstraAlgorithm(emptydata);
- invalidijk=new DijkstraAlgorithm(invalidata);
-
- //initialisation des Bellman-Ford pour comparaison
- bfaal=new BellmanFordAlgorithm(dataal);
- bfacl=new BellmanFordAlgorithm(datacl);
- bfaat=new BellmanFordAlgorithm(dataat);
- bfact=new BellmanFordAlgorithm(datact);
- bfapt=new BellmanFordAlgorithm(datapt);
-
- }
-
- //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:
- -coûts croissants
- -nbr successeurs cohérents
- -tas valide.)*/
-
- @Test
- public void cheminValide() {
- assertTrue(dijkal.doRun().getPath().isValid());
- }
-
- @Test
- public void faisable() {
- assertTrue(dijkal.doRun().isFeasible());
- }
-
-
- //résultat identique à Bellman-Ford (sur les petits scénarios)
- @Test
- public void sameasBF() {
- assertTrue(Float.compare(dijkal.doRun().getPath().getLength(),bfaal.doRun().getPath().getLength())==0);
- }
-
- //tests applicables aussi pour des grands scénarios:
- //...
-
- //graph = new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream("a")))).read;
- }
|