forked from lebotlan/BE-Graphes
Init ShortestPathTest, testInsaBikini et testCheminInexistant
This commit is contained in:
parent
23be38ee2b
commit
07029f751d
1 changed files with 105 additions and 0 deletions
|
|
@ -0,0 +1,105 @@
|
|||
package org.insa.graphs.algorithm.utils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
||||
import org.insa.graphs.algorithm.ArcInspector;
|
||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||
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.shortestpath.ShortestPathSolution;
|
||||
import org.insa.graphs.model.Graph;
|
||||
import org.insa.graphs.model.Path;
|
||||
import org.insa.graphs.model.io.BinaryGraphReader;
|
||||
import org.insa.graphs.model.io.BinaryPathReader;
|
||||
import org.insa.graphs.model.io.GraphReader;
|
||||
import org.insa.graphs.model.io.PathReader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ShortestPathTest {
|
||||
|
||||
final static String midiPyreneesFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Maps/midi-pyrenees.mapgr";
|
||||
final static String hauteGaronneFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Maps/haute-garonne.mapgr";
|
||||
final static String insaFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
||||
|
||||
final static String insaBikiniCanalPathFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Paths/path_fr31_insa_bikini_canal.path";
|
||||
|
||||
static Graph midiPyrenees;
|
||||
static Graph hauteGaronne;
|
||||
static Graph insa;
|
||||
|
||||
static Path insaBikiniCanal;
|
||||
|
||||
static ArcInspector onlyPedestrianByTime;
|
||||
static ArcInspector onlyCarsByLengthArcInspector;
|
||||
static ArcInspector noFilterByLengthArcInspector;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws FileNotFoundException, IOException {
|
||||
|
||||
try (final GraphReader reader = new BinaryGraphReader(new DataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(midiPyreneesFile))))) {
|
||||
midiPyrenees = reader.read();
|
||||
}
|
||||
try (final GraphReader reader = new BinaryGraphReader(new DataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(hauteGaronneFile))))) {
|
||||
hauteGaronne = reader.read();
|
||||
}
|
||||
try (final GraphReader reader = new BinaryGraphReader(new DataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(insaFile))))) {
|
||||
insa = reader.read();
|
||||
}
|
||||
|
||||
try (final PathReader pathReader = new BinaryPathReader(new DataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(insaBikiniCanalPathFile))))) {
|
||||
insaBikiniCanal = pathReader.readPath(hauteGaronne);
|
||||
}
|
||||
|
||||
List<ArcInspector> inspectors = ArcInspectorFactory.getAllFilters();
|
||||
noFilterByLengthArcInspector = inspectors.get(0);
|
||||
onlyCarsByLengthArcInspector = inspectors.get(1);
|
||||
onlyPedestrianByTime = inspectors.get(3);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCheminInsaBikiniCanal() {
|
||||
ShortestPathData insaBikiniCanalPathData = new ShortestPathData(hauteGaronne, insaBikiniCanal.getOrigin(), insaBikiniCanal.getDestination(), noFilterByLengthArcInspector);
|
||||
// System.out.println("" + insaBikiniCanal.getOrigin().getId() +" "+ insaBikiniCanal.getDestination().getId());
|
||||
ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(insaBikiniCanalPathData);
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(insaBikiniCanalPathData);
|
||||
|
||||
ShortestPathSolution solutionBellmanFord = bellmanFord.run();
|
||||
ShortestPathSolution solutionDijkstra = dijkstra.run();
|
||||
|
||||
assertEquals(insaBikiniCanal.getLength(), solutionBellmanFord.getPath().getLength(),1.0);
|
||||
assertEquals(insaBikiniCanal.getLength(), solutionDijkstra.getPath().getLength(), 1.0);
|
||||
|
||||
assertEquals(insaBikiniCanal.getTravelTime(120), solutionBellmanFord.getPath().getTravelTime(120),1.0);
|
||||
assertEquals(insaBikiniCanal.getTravelTime(120), solutionDijkstra.getPath().getTravelTime(120), 1.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheminInexistant() {
|
||||
ShortestPathData cheminInexistant = new ShortestPathData(insa, insa.get(940), insa.get(702), onlyCarsByLengthArcInspector);
|
||||
ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(cheminInexistant);
|
||||
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(cheminInexistant);
|
||||
|
||||
ShortestPathSolution solutionBellmanFord = bellmanFord.run();
|
||||
ShortestPathSolution solutionDijkstra = dijkstra.run();
|
||||
|
||||
assertEquals(Status.INFEASIBLE, solutionBellmanFord.getStatus());
|
||||
assertEquals(Status.INFEASIBLE, solutionDijkstra.getStatus());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue