Amélioration des tests existants, ajout tests A* et tests d'optimalité
This commit is contained in:
parent
a95084f21e
commit
568f779be7
13 changed files with 566 additions and 368 deletions
|
@ -22,13 +22,6 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
|
|||
|
||||
@Override
|
||||
protected Label createLabel(ShortestPathData data, Arc pere, Label noeudPrecedent) {
|
||||
if(pere == null && noeudPrecedent == null) {
|
||||
return new LabelStar(data.getOrigin(),
|
||||
0,
|
||||
Point.distance(data.getOrigin().getPoint(), data.getDestination().getPoint() ) ,
|
||||
null);
|
||||
}
|
||||
|
||||
|
||||
double coutEstime = 0;
|
||||
|
||||
|
@ -67,8 +60,15 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
|
|||
noeudPrecedent.getCost() + data.getCost(pere),
|
||||
coutEstime,
|
||||
pere);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Label createLabelOrigin(ShortestPathData data) {
|
||||
|
||||
return new LabelStar(data.getOrigin(),
|
||||
0,
|
||||
Point.distance(data.getOrigin().getPoint(), data.getDestination().getPoint() ) ,
|
||||
null);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
Label labels[] = new Label[graph.getNodes().size()];
|
||||
Arrays.fill(labels, null);
|
||||
|
||||
Label origine = createLabel(data, null, null);
|
||||
Label origine = createLabelOrigin(data);
|
||||
labels[data.getOrigin().getId()] = origine;
|
||||
tas.insert(origine);
|
||||
|
||||
|
@ -135,17 +135,16 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
solution = new ShortestPathSolution(data, Status.INFEASIBLE);
|
||||
}
|
||||
|
||||
System.out.println("nb erreurs = "+cptErreurs);
|
||||
// System.out.println("nb erreurs = "+cptErreurs);
|
||||
return solution;
|
||||
}
|
||||
|
||||
protected Label createLabel(ShortestPathData data, Arc pere, Label noeudPrecedent) {
|
||||
if(pere != null && noeudPrecedent != null) {
|
||||
return new Label( pere.getDestination() , noeudPrecedent.getCost()+ data.getCost(pere), pere);
|
||||
}else {
|
||||
return new Label(data.getOrigin(), 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected Label createLabelOrigin(ShortestPathData data) {
|
||||
return new Label(data.getOrigin(), 0, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.insa.graphs.algorithm.shortestpath;
|
|||
import org.insa.graphs.model.Arc;
|
||||
import org.insa.graphs.model.Node;
|
||||
|
||||
public class LabelStar extends Label{
|
||||
public class LabelStar extends Label implements Comparable<Label>{
|
||||
|
||||
private Double coutEstime;
|
||||
|
||||
|
@ -16,4 +16,13 @@ public class LabelStar extends Label{
|
|||
public double getTotalCost(){
|
||||
return this.getCost() + this.coutEstime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Label o) {
|
||||
LabelStar other = (LabelStar) o;
|
||||
if(this.getTotalCost() == other.getTotalCost()) {
|
||||
return Double.compare(this.coutEstime, other.coutEstime);
|
||||
}
|
||||
return Double.compare(this.getTotalCost(), o.getTotalCost());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
|||
public BinaryHeap() {
|
||||
this.currentSize = 0;
|
||||
this.array = new ArrayList<E>();
|
||||
// this.indexArray = new Couple[70];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,7 +163,7 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
|||
}
|
||||
|
||||
int index = -1;
|
||||
// Iterate over the array and check if the x exists
|
||||
// Iterate over the array and check if the x exists
|
||||
for(int i=0; i<this.currentSize;i++) {
|
||||
if(this.array.get(i).equals(x)) {
|
||||
index = i;
|
||||
|
@ -204,7 +204,29 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
|||
}
|
||||
|
||||
|
||||
//Met à jour l'arbre à partir à partir d'un élément dont le coût a changé
|
||||
/**
|
||||
* Check that the binary heap is valid
|
||||
*
|
||||
* @return a boolean indicating whether the tree is valid
|
||||
*/
|
||||
public boolean isValid() {
|
||||
E current;
|
||||
E parent;
|
||||
for(int i=1; i<this.currentSize; i++) {
|
||||
current = this.array.get(i);
|
||||
parent = this.array.get(this.indexParent(i));
|
||||
if( current.compareTo(parent) < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the element x in the heap if it exists
|
||||
* Raise ElementNotFoundException otherwise
|
||||
*/
|
||||
public void miseAJour(E x) throws ElementNotFoundException {
|
||||
|
||||
if(this.isEmpty() || x == null){
|
||||
|
@ -230,20 +252,6 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
|
|||
|
||||
}
|
||||
|
||||
|
||||
public boolean isValid() {
|
||||
E current;
|
||||
E parent;
|
||||
for(int i=1; i<this.currentSize; i++) {
|
||||
current = this.array.get(i);
|
||||
parent = this.array.get(this.indexParent(i));
|
||||
if( current.compareTo(parent) < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a multi-lines string representing a sorted view of this binary heap.
|
||||
*
|
||||
|
|
|
@ -1,107 +0,0 @@
|
|||
package org.insa.graphs.algorithm.shortestpath;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
||||
import org.insa.graphs.algorithm.shortestpath.AStarAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathSolution;
|
||||
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.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AStarAlgorithmTest extends algorithmTest{
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAStarShortest() {
|
||||
|
||||
for(int i=0; i<dataShortest.length; i++) {
|
||||
AStarAlgorithm aStar = new AStarAlgorithm(dataShortest[i]);
|
||||
ShortestPathSolution solution = aStar.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
Graph graph = solution.getInputData().getGraph();
|
||||
|
||||
//Vérifie chemin valide
|
||||
assertTrue(cheminSolution.isValid());
|
||||
assertEquals(cheminSolution.getOrigin(), graph.get(tabOrigin[i]));
|
||||
assertEquals(cheminSolution.getDestination(), graph.get(tabDestination[i]));
|
||||
|
||||
// List of nodes
|
||||
ArrayList<Node> nodes = new ArrayList<Node>();
|
||||
List<Arc> arcsSolution = cheminSolution.getArcs();
|
||||
nodes.add(arcsSolution.get(0).getOrigin());
|
||||
|
||||
for(int j=0;j<arcsSolution.size(); j++) {
|
||||
nodes.add(arcsSolution.get(j).getDestination());
|
||||
}
|
||||
|
||||
Path cheminShortest = Path.createShortestPathFromNodes(graph, nodes);
|
||||
|
||||
//Vérifie que les chemins sont identiques (Arcs, taille, temps)
|
||||
assertEquals(cheminSolution.getArcs(), cheminShortest.getArcs());
|
||||
assertTrue(cheminSolution.getLength() == cheminShortest.getLength());
|
||||
assertTrue(cheminSolution.getMinimumTravelTime() == cheminShortest.getMinimumTravelTime());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAStarFastest() {
|
||||
|
||||
for(int i=0; i<dataShortest.length; i++) {
|
||||
AStarAlgorithm aStar = new AStarAlgorithm(dataFastest[i]);
|
||||
ShortestPathSolution solution = aStar.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
Graph graph = solution.getInputData().getGraph();
|
||||
|
||||
//Vérifie chemin valide
|
||||
assertTrue(cheminSolution.isValid());
|
||||
assertEquals(cheminSolution.getOrigin(), graph.get(tabOrigin[i]));
|
||||
assertEquals(cheminSolution.getDestination(), graph.get(tabDestination[i]));
|
||||
|
||||
// List of nodes
|
||||
ArrayList<Node> nodes = new ArrayList<Node>();
|
||||
List<Arc> arcsSolution = cheminSolution.getArcs();
|
||||
nodes.add(arcsSolution.get(0).getOrigin());
|
||||
|
||||
for(int j=0;j<arcsSolution.size(); j++) {
|
||||
nodes.add(arcsSolution.get(j).getDestination());
|
||||
}
|
||||
|
||||
Path cheminFastest = Path.createFastestPathFromNodes(graph, nodes);
|
||||
|
||||
//Vérifie que les chemins sont identiques (Arcs, taille, temps)
|
||||
assertEquals(cheminSolution.getArcs(), cheminFastest.getArcs());
|
||||
assertTrue(cheminSolution.getLength() == cheminFastest.getLength());
|
||||
assertTrue(cheminSolution.getMinimumTravelTime() == cheminFastest.getMinimumTravelTime());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDijkstraInfeasable() {
|
||||
|
||||
AStarAlgorithm aStar = new AStarAlgorithm(dataInfeasable);
|
||||
ShortestPathSolution solution = aStar.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
//Vérifie chemin valide
|
||||
assertEquals(cheminSolution, null);
|
||||
assertEquals(solution.getStatus(), Status.INFEASIBLE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
package org.insa.graphs.algorithm.shortestpath;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.insa.graphs.algorithm.ArcInspector;
|
||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
||||
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathSolution;
|
||||
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.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.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DijkstraAlgorithmTest extends algorithmTest {
|
||||
|
||||
// Small graph use for tests
|
||||
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDijkstraShortest() {
|
||||
|
||||
for(int i=0; i<dataShortest.length; i++) {
|
||||
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(dataShortest[i]);
|
||||
ShortestPathSolution solution = dijkstra.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
Graph graph = solution.getInputData().getGraph();
|
||||
|
||||
//Vérifie chemin valide
|
||||
assertTrue(cheminSolution.isValid());
|
||||
assertEquals(cheminSolution.getOrigin(), graph.get(tabOrigin[i]));
|
||||
assertEquals(cheminSolution.getDestination(), graph.get(tabDestination[i]));
|
||||
|
||||
// List of nodes
|
||||
ArrayList<Node> nodes = new ArrayList<Node>();
|
||||
List<Arc> arcsSolution = cheminSolution.getArcs();
|
||||
nodes.add(arcsSolution.get(0).getOrigin());
|
||||
|
||||
for(int j=0;j< arcsSolution.size(); j++) {
|
||||
nodes.add(arcsSolution.get(j).getDestination());
|
||||
}
|
||||
|
||||
Path cheminShortest = Path.createShortestPathFromNodes(graph, nodes);
|
||||
|
||||
//Vérifie que les chemins sont identiques (Arcs, taille, temps)
|
||||
assertEquals(cheminSolution.getArcs(), cheminShortest.getArcs());
|
||||
assertTrue(cheminSolution.getLength() == cheminShortest.getLength());
|
||||
assertTrue(cheminSolution.getMinimumTravelTime() == cheminShortest.getMinimumTravelTime());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDijkstraFastest() {
|
||||
|
||||
for(int i=0; i<dataShortest.length; i++) {
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(dataFastest[i]);
|
||||
ShortestPathSolution solution = dijkstra.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
Graph graph = solution.getInputData().getGraph();
|
||||
|
||||
//Vérifie chemin valide
|
||||
assertTrue(cheminSolution.isValid());
|
||||
assertEquals(cheminSolution.getOrigin(), graph.get(tabOrigin[i]));
|
||||
assertEquals(cheminSolution.getDestination(), graph.get(tabDestination[i]));
|
||||
|
||||
// List of nodes
|
||||
ArrayList<Node> nodes = new ArrayList<Node>();
|
||||
List<Arc> arcsSolution = cheminSolution.getArcs();
|
||||
nodes.add(arcsSolution.get(0).getOrigin());
|
||||
|
||||
for(int j=0; j<arcsSolution.size(); j++) {
|
||||
nodes.add(arcsSolution.get(j).getDestination());
|
||||
}
|
||||
|
||||
Path cheminFastest = Path.createFastestPathFromNodes(graph, nodes);
|
||||
|
||||
//Vérifie que les chemins sont identiques (Arcs, taille, temps)
|
||||
assertEquals(cheminSolution.getArcs(), cheminFastest.getArcs());
|
||||
assertTrue(cheminSolution.getLength() == cheminFastest.getLength());
|
||||
assertTrue(cheminSolution.getMinimumTravelTime() == cheminFastest.getMinimumTravelTime());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDijkstraInfeasable() {
|
||||
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(dataInfeasable);
|
||||
ShortestPathSolution solution = dijkstra.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
//Vérifie chemin valide
|
||||
assertEquals(cheminSolution, null);
|
||||
assertEquals(solution.getStatus(), Status.INFEASIBLE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
package org.insa.graphs.algorithm.shortestpath;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.insa.graphs.algorithm.ArcInspector;
|
||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
||||
import org.insa.graphs.model.Graph;
|
||||
import org.insa.graphs.model.io.BinaryGraphReader;
|
||||
import org.insa.graphs.model.io.GraphReader;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
public class algorithmTest {
|
||||
|
||||
protected Graph graph, graphPolynesie, graphBelgique;
|
||||
|
||||
|
||||
final String hauteGaronne = "/Users/Kevin/Desktop/programmation/java_files/Maps/europe/france/haute-garonne.mapgr";
|
||||
final String polynesie = "/Users/Kevin/Desktop/programmation/java_files/Maps/europe/france/french-polynesia.mapgr";
|
||||
final String belgique = "/Users/Kevin/Desktop/programmation/java_files/Maps/europe/belgique/belgium.mapgr";
|
||||
|
||||
final static int taille = 5;
|
||||
|
||||
protected ShortestPathData dataShortest[];
|
||||
protected ShortestPathData dataFastest[];
|
||||
protected ShortestPathData dataInfeasable;
|
||||
protected int tabOrigin[], tabDestination[];
|
||||
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
|
||||
List<ArcInspector> arcList = ArcInspectorFactory.getAllFilters();
|
||||
ArcInspector arcShortestAllRoad = arcList.get(0);
|
||||
ArcInspector arcFastestAllRoad = arcList.get(2);
|
||||
|
||||
try (GraphReader readerHauteGaronne = new BinaryGraphReader(new DataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(hauteGaronne))))) {
|
||||
|
||||
// TODO: Read the graph.
|
||||
graph = readerHauteGaronne.read();
|
||||
}
|
||||
|
||||
try (GraphReader readerPolynesie = new BinaryGraphReader(new DataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(polynesie))))) {
|
||||
|
||||
// TODO: Read the graph.
|
||||
graphPolynesie = readerPolynesie.read();
|
||||
}
|
||||
|
||||
try (GraphReader readerBelgique = new BinaryGraphReader(new DataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(belgique))))) {
|
||||
|
||||
// TODO: Read the graph.
|
||||
graphBelgique = readerBelgique.read();
|
||||
}
|
||||
|
||||
dataShortest = new ShortestPathData[taille];
|
||||
dataFastest = new ShortestPathData[taille];
|
||||
tabOrigin = new int[taille]; tabDestination = new int[taille];
|
||||
|
||||
tabOrigin[0] = 10991; tabOrigin[1] = 102582; tabOrigin[2]= 81460; tabOrigin[3]= 942294; tabOrigin[4]= 10228;
|
||||
|
||||
tabDestination[0] = 89149; tabDestination[1]= 84718; tabDestination[2] = 129594; tabDestination[3] = 412806 ; tabDestination[4]= 666164 ;
|
||||
|
||||
|
||||
dataShortest[0] = new ShortestPathData(graph, graph.get(tabOrigin[0]), graph.get(tabDestination[0]), arcShortestAllRoad);
|
||||
dataShortest[1] = new ShortestPathData(graph, graph.get(tabOrigin[1]), graph.get(tabDestination[1]), arcShortestAllRoad);
|
||||
dataShortest[2] = new ShortestPathData(graph, graph.get(tabOrigin[2]), graph.get(tabDestination[2]), arcShortestAllRoad);
|
||||
dataShortest[3] = new ShortestPathData(graphBelgique, graphBelgique.get(tabOrigin[3]), graphBelgique.get(tabDestination[3]), arcShortestAllRoad);
|
||||
dataShortest[4] = new ShortestPathData(graphBelgique, graphBelgique.get(tabOrigin[4]), graphBelgique.get(tabDestination[4]), arcShortestAllRoad);
|
||||
|
||||
dataFastest[0] = new ShortestPathData(graph, graph.get(tabOrigin[0]), graph.get(tabDestination[0]) , arcFastestAllRoad);
|
||||
dataFastest[1] = new ShortestPathData(graph, graph.get(tabOrigin[1]), graph.get(tabDestination[1]), arcFastestAllRoad);
|
||||
dataFastest[2] = new ShortestPathData(graph, graph.get(tabOrigin[2]), graph.get(tabDestination[2]), arcFastestAllRoad);
|
||||
dataFastest[3] = new ShortestPathData(graphBelgique, graphBelgique.get(tabOrigin[3]), graphBelgique.get(tabDestination[3]), arcFastestAllRoad);
|
||||
dataFastest[4] = new ShortestPathData(graphBelgique, graphBelgique.get(tabOrigin[4]), graphBelgique.get(tabDestination[4]), arcFastestAllRoad);
|
||||
|
||||
|
||||
|
||||
dataInfeasable = new ShortestPathData(graphPolynesie, graphPolynesie.get(2984), graphPolynesie.get(10467), arcFastestAllRoad);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
}
|
144
be-graphes-algos/src/test/java/tests/AStarAlgorithmTest.java
Normal file
144
be-graphes-algos/src/test/java/tests/AStarAlgorithmTest.java
Normal file
|
@ -0,0 +1,144 @@
|
|||
package tests;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
||||
import org.insa.graphs.algorithm.shortestpath.AStarAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathSolution;
|
||||
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.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AStarAlgorithmTest extends algorithmTest{
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
//Test pour vérifier que le chemin obtenu avec l'algorithme A*
|
||||
//est le même que celui crée par la méthode createShortestPathFromNodes de la classe Path
|
||||
@Test
|
||||
public void testAStarShortest() {
|
||||
|
||||
for(int i=0; i<dataShortest.length; i++) {
|
||||
AStarAlgorithm aStar = new AStarAlgorithm(dataShortest[i]);
|
||||
ShortestPathSolution solution = aStar.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
Graph graph = solution.getInputData().getGraph();
|
||||
|
||||
if (cheminSolution == null) {
|
||||
|
||||
assertEquals(solution.getStatus(), Status.INFEASIBLE);
|
||||
|
||||
} else {
|
||||
//Vérifie chemin valide
|
||||
assertTrue(cheminSolution.isValid());
|
||||
// assertEquals(cheminSolution.getOrigin(), graph.get(tabOrigin[i]));
|
||||
// assertEquals(cheminSolution.getDestination(), graph.get(tabDestination[i]));
|
||||
|
||||
// List of nodes
|
||||
ArrayList<Node> nodes = new ArrayList<Node>();
|
||||
List<Arc> arcsSolution = cheminSolution.getArcs();
|
||||
nodes.add(arcsSolution.get(0).getOrigin());
|
||||
|
||||
for(int j=0;j<arcsSolution.size(); j++) {
|
||||
nodes.add(arcsSolution.get(j).getDestination());
|
||||
}
|
||||
|
||||
Path cheminShortest = Path.createShortestPathFromNodes(graph, nodes);
|
||||
|
||||
//Vérifie que les chemins sont identiques (Arcs, taille, temps)
|
||||
assertEquals(cheminSolution.getArcs(), cheminShortest.getArcs());
|
||||
assertEquals(cheminSolution.getLength(), cheminShortest.getLength(), 1e-6);
|
||||
assertEquals(cheminSolution.getMinimumTravelTime(), cheminShortest.getMinimumTravelTime(), 1e-6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Test pour vérifier que le chemin obtenu avec l'algorithme A*
|
||||
//est le même que celui crée par la méthode createFastestPathFromNodes de la classe Path
|
||||
@Test
|
||||
public void testAStarFastest() {
|
||||
|
||||
for(int i=0; i<dataShortest.length; i++) {
|
||||
AStarAlgorithm aStar = new AStarAlgorithm(dataFastest[i]);
|
||||
ShortestPathSolution solution = aStar.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
Graph graph = solution.getInputData().getGraph();
|
||||
|
||||
if (cheminSolution == null) {
|
||||
|
||||
assertEquals(solution.getStatus(), Status.INFEASIBLE);
|
||||
|
||||
} else {
|
||||
//Vérifie chemin valide
|
||||
assertTrue(cheminSolution.isValid());
|
||||
// assertEquals(cheminSolution.getOrigin(), graph.get(tabOrigin[i]));
|
||||
// assertEquals(cheminSolution.getDestination(), graph.get(tabDestination[i]));
|
||||
|
||||
// List of nodes
|
||||
ArrayList<Node> nodes = new ArrayList<Node>();
|
||||
List<Arc> arcsSolution = cheminSolution.getArcs();
|
||||
nodes.add(arcsSolution.get(0).getOrigin());
|
||||
|
||||
for(int j=0;j<arcsSolution.size(); j++) {
|
||||
nodes.add(arcsSolution.get(j).getDestination());
|
||||
}
|
||||
|
||||
Path cheminFastest = Path.createFastestPathFromNodes(graph, nodes);
|
||||
|
||||
//Vérifie que les chemins sont identiques (Arcs, taille, temps)
|
||||
assertEquals(cheminSolution.getArcs(), cheminFastest.getArcs());
|
||||
assertEquals(cheminSolution.getLength(), cheminFastest.getLength(), 1e-6);
|
||||
assertEquals(cheminSolution.getMinimumTravelTime(), cheminFastest.getMinimumTravelTime(), 1e-6);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Test pour un chemin entre 2 îles
|
||||
@Test
|
||||
public void testAStarInfeasable() {
|
||||
|
||||
AStarAlgorithm aStar = new AStarAlgorithm(dataInfeasable);
|
||||
ShortestPathSolution solution = aStar.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
//Vérifie chemin valide
|
||||
assertEquals(cheminSolution, null);
|
||||
assertEquals(solution.getStatus(), Status.INFEASIBLE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Test pour un chemin d'un seul noeud
|
||||
@Test
|
||||
public void testAStarOneNode() {
|
||||
|
||||
AStarAlgorithm aStar = new AStarAlgorithm(dataOneNode);
|
||||
ShortestPathSolution solution = aStar.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
// Vérifie que le chemin est de longueur nulle, de temps nul et n'a pas d'arc
|
||||
assertEquals(solution.getStatus(), Status.OPTIMAL);
|
||||
assertEquals(cheminSolution.getLength(), 0f, 0.1e-6);
|
||||
assertEquals(cheminSolution.getMinimumTravelTime(), 0d, 1e-6);
|
||||
assertEquals(cheminSolution.getArcs().size(), 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
11
be-graphes-algos/src/test/java/tests/AllTests.java
Normal file
11
be-graphes-algos/src/test/java/tests/AllTests.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package tests;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ AStarAlgorithmTest.class, DijkstraAlgorithmTest.class, OptimaliteTest.class})
|
||||
public class AllTests {
|
||||
|
||||
}
|
159
be-graphes-algos/src/test/java/tests/DijkstraAlgorithmTest.java
Normal file
159
be-graphes-algos/src/test/java/tests/DijkstraAlgorithmTest.java
Normal file
|
@ -0,0 +1,159 @@
|
|||
package tests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.insa.graphs.algorithm.ArcInspector;
|
||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
||||
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathSolution;
|
||||
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.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.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DijkstraAlgorithmTest extends algorithmTest {
|
||||
|
||||
// Small graph use for tests
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
|
||||
//Test pour vérifier que le chemin obtenu avec l'algorithme de dijkstra
|
||||
//est le même que celui crée par la méthode createShortestPathFromNodes de la classe Path
|
||||
@Test
|
||||
public void testDijkstraShortest() {
|
||||
|
||||
for (int i = 0; i < dataShortest.length; i++) {
|
||||
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(dataShortest[i]);
|
||||
ShortestPathSolution solution = dijkstra.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
Graph graph = solution.getInputData().getGraph();
|
||||
|
||||
if (cheminSolution == null) {
|
||||
|
||||
assertEquals(solution.getStatus(), Status.INFEASIBLE);
|
||||
|
||||
} else {
|
||||
|
||||
// Vérifie chemin valide
|
||||
assertTrue(cheminSolution.isValid());
|
||||
// assertEquals(cheminSolution.getOrigin(), graph.get(tabOrigin[i]));
|
||||
// assertEquals(cheminSolution.getDestination(), graph.get(tabDestination[i]));
|
||||
|
||||
// List of nodes
|
||||
ArrayList<Node> nodes = new ArrayList<Node>();
|
||||
List<Arc> arcsSolution = cheminSolution.getArcs();
|
||||
nodes.add(arcsSolution.get(0).getOrigin());
|
||||
|
||||
for (int j = 0; j < arcsSolution.size(); j++) {
|
||||
nodes.add(arcsSolution.get(j).getDestination());
|
||||
}
|
||||
|
||||
Path cheminShortest = Path.createShortestPathFromNodes(graph, nodes);
|
||||
|
||||
// Vérifie que les chemins sont identiques (Arcs, taille, temps)
|
||||
assertEquals(cheminSolution.getArcs(), cheminShortest.getArcs());
|
||||
assertEquals(cheminSolution.getLength(), cheminShortest.getLength(), 1e-6);
|
||||
assertEquals(cheminSolution.getMinimumTravelTime(), cheminShortest.getMinimumTravelTime(), 1e-6);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Test pour vérifier que le chemin obtenu avec l'algorithme de dijkstra
|
||||
//est le même que celui crée par la méthode createFastestPathFromNodes de la classe Path
|
||||
@Test
|
||||
public void testDijkstraFastest() {
|
||||
|
||||
for (int i = 0; i < dataShortest.length; i++) {
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(dataFastest[i]);
|
||||
ShortestPathSolution solution = dijkstra.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
Graph graph = solution.getInputData().getGraph();
|
||||
|
||||
if (cheminSolution == null) {
|
||||
|
||||
assertEquals(solution.getStatus(), Status.INFEASIBLE);
|
||||
|
||||
} else {
|
||||
// Vérifie chemin valide
|
||||
assertTrue(cheminSolution.isValid());
|
||||
// assertEquals(cheminSolution.getOrigin(), graph.get(tabOrigin[i]));
|
||||
// assertEquals(cheminSolution.getDestination(), graph.get(tabDestination[i]));
|
||||
|
||||
// List of nodes
|
||||
ArrayList<Node> nodes = new ArrayList<Node>();
|
||||
List<Arc> arcsSolution = cheminSolution.getArcs();
|
||||
nodes.add(arcsSolution.get(0).getOrigin());
|
||||
|
||||
for (int j = 0; j < arcsSolution.size(); j++) {
|
||||
nodes.add(arcsSolution.get(j).getDestination());
|
||||
}
|
||||
|
||||
Path cheminFastest = Path.createFastestPathFromNodes(graph, nodes);
|
||||
|
||||
// Vérifie que les chemins sont identiques (Arcs, taille, temps)
|
||||
assertEquals(cheminSolution.getArcs(), cheminFastest.getArcs());
|
||||
assertEquals(cheminSolution.getLength(), cheminFastest.getLength(), 1e-6);
|
||||
assertEquals(cheminSolution.getMinimumTravelTime(), cheminFastest.getMinimumTravelTime(), 1e-6);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Test pour un chemin entre 2 îles
|
||||
@Test
|
||||
public void testDijkstraInfeasable() {
|
||||
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(dataInfeasable);
|
||||
ShortestPathSolution solution = dijkstra.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
// Vérifie qu'il n'y a pas de chemin
|
||||
assertEquals(cheminSolution, null);
|
||||
assertEquals(solution.getStatus(), Status.INFEASIBLE);
|
||||
|
||||
}
|
||||
|
||||
//Test pour un chemin d'un seul noeud
|
||||
@Test
|
||||
public void testDijkstraOneNode() {
|
||||
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(dataOneNode);
|
||||
ShortestPathSolution solution = dijkstra.run();
|
||||
Path cheminSolution = solution.getPath();
|
||||
|
||||
// Vérifie que le chemin est de longueur nulle, de temps nul et n'a pas d'arc
|
||||
assertEquals(solution.getStatus(), Status.OPTIMAL);
|
||||
assertEquals(cheminSolution.getLength(), 0f, 1e-6);
|
||||
assertEquals(cheminSolution.getMinimumTravelTime(), 0d, 1e-6);
|
||||
assertEquals(cheminSolution.getArcs().size(), 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
109
be-graphes-algos/src/test/java/tests/OptimaliteTest.java
Normal file
109
be-graphes-algos/src/test/java/tests/OptimaliteTest.java
Normal file
|
@ -0,0 +1,109 @@
|
|||
package tests;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
||||
import org.insa.graphs.algorithm.shortestpath.AStarAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.BellmanFordAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathSolution;
|
||||
import org.insa.graphs.model.Path;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
public class OptimaliteTest extends algorithmTest {
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShortest() {
|
||||
|
||||
ArrayList<Long> tempsDijkstra = new ArrayList<>(),
|
||||
tempsAStar = new ArrayList<Long>();
|
||||
|
||||
for (int i = 0; i < dataShortest.length; i++) {
|
||||
BellmanFordAlgorithm BF = new BellmanFordAlgorithm(dataShortest[i]);
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(dataShortest[i]);
|
||||
AStarAlgorithm aStar = new AStarAlgorithm(dataShortest[i]);
|
||||
|
||||
ShortestPathSolution solutionBF = BF.run(),
|
||||
solutionDijkstra = dijkstra.run(),
|
||||
solutionAStar = aStar.run();
|
||||
|
||||
|
||||
Path cheminSolutionBF = solutionBF.getPath(),
|
||||
cheminSolutionDijkstra = solutionDijkstra.getPath(),
|
||||
cheminSolutionAStar = solutionAStar.getPath();
|
||||
|
||||
if (cheminSolutionBF == null) {
|
||||
assertEquals(solutionBF.getStatus(), Status.INFEASIBLE);
|
||||
assertEquals(solutionDijkstra.getStatus(), Status.INFEASIBLE);
|
||||
assertEquals(solutionAStar.getStatus(), Status.INFEASIBLE);
|
||||
}else {
|
||||
|
||||
|
||||
tempsDijkstra.add(solutionDijkstra.getSolvingTime().toMillis());
|
||||
tempsAStar.add(solutionAStar.getSolvingTime().toMillis());
|
||||
|
||||
assertEquals(cheminSolutionAStar.getArcs(), cheminSolutionBF.getArcs());
|
||||
assertEquals(cheminSolutionAStar.getLength(), cheminSolutionBF.getLength(), 1e-6);
|
||||
assertEquals(cheminSolutionAStar.getMinimumTravelTime(), cheminSolutionBF.getMinimumTravelTime(), 1e-6);
|
||||
|
||||
assertEquals(cheminSolutionDijkstra.getArcs(), cheminSolutionBF.getArcs());
|
||||
assertEquals(cheminSolutionDijkstra.getLength(), cheminSolutionBF.getLength(), 1e-6);
|
||||
assertEquals(cheminSolutionDijkstra.getMinimumTravelTime(), cheminSolutionBF.getMinimumTravelTime(), 1e-6);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Dijkstra : "+tempsDijkstra.toString());
|
||||
System.out.println("A* : "+tempsAStar.toString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFastest() {
|
||||
|
||||
ArrayList<Long> tempsDijkstra = new ArrayList<>(),
|
||||
tempsAStar = new ArrayList<Long>();
|
||||
|
||||
for (int i = 0; i < dataFastest.length; i++) {
|
||||
BellmanFordAlgorithm BF = new BellmanFordAlgorithm(dataFastest[i]);
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(dataFastest[i]);
|
||||
AStarAlgorithm aStar = new AStarAlgorithm(dataFastest[i]);
|
||||
|
||||
ShortestPathSolution solutionBF = BF.run(),
|
||||
solutionDijkstra = dijkstra.run(),
|
||||
solutionAStar = aStar.run();
|
||||
|
||||
Path cheminSolutionBF = solutionBF.getPath(),
|
||||
cheminSolutionDijkstra = solutionDijkstra.getPath(),
|
||||
cheminSolutionAStar = solutionAStar.getPath();
|
||||
|
||||
if (cheminSolutionBF == null) {
|
||||
assertEquals(solutionBF.getStatus(), Status.INFEASIBLE);
|
||||
assertEquals(solutionDijkstra.getStatus(), Status.INFEASIBLE);
|
||||
assertEquals(solutionAStar.getStatus(), Status.INFEASIBLE);
|
||||
}else {
|
||||
|
||||
tempsDijkstra.add(solutionDijkstra.getSolvingTime().toMillis());
|
||||
tempsAStar.add(solutionAStar.getSolvingTime().toMillis());
|
||||
|
||||
assertEquals(cheminSolutionAStar.getArcs(), cheminSolutionBF.getArcs());
|
||||
assertEquals(cheminSolutionAStar.getLength(), cheminSolutionBF.getLength(), 1e-6);
|
||||
assertEquals(cheminSolutionAStar.getMinimumTravelTime(), cheminSolutionBF.getMinimumTravelTime(), 1e-6);
|
||||
|
||||
assertEquals(cheminSolutionDijkstra.getArcs(), cheminSolutionBF.getArcs());
|
||||
assertEquals(cheminSolutionDijkstra.getLength(), cheminSolutionBF.getLength(), 1e-6);
|
||||
assertEquals(cheminSolutionDijkstra.getMinimumTravelTime(), cheminSolutionBF.getMinimumTravelTime(), 1e-6);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Dijkstra : "+tempsDijkstra.toString());
|
||||
System.out.println("A* : "+tempsAStar.toString());
|
||||
}
|
||||
|
||||
}
|
85
be-graphes-algos/src/test/java/tests/algorithmTest.java
Normal file
85
be-graphes-algos/src/test/java/tests/algorithmTest.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
package tests;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.insa.graphs.algorithm.ArcInspector;
|
||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
||||
import org.insa.graphs.model.Graph;
|
||||
import org.insa.graphs.model.io.BinaryGraphReader;
|
||||
import org.insa.graphs.model.io.GraphReader;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class algorithmTest {
|
||||
|
||||
protected static Graph graphs[];
|
||||
|
||||
//3 cartes, chacune testée pour les mode "shortest path all roads" et "fastest path all roads"
|
||||
// /!\ Chemin des cartes à adapter /!\
|
||||
final static String hauteGaronne = "/Users/Kevin/Desktop/programmation/java_files/Maps/europe/france/haute-garonne.mapgr";
|
||||
final static String polynesie = "/Users/Kevin/Desktop/programmation/java_files/Maps/europe/france/french-polynesia.mapgr";
|
||||
final static String bretagne = "/Users/Kevin/Desktop/programmation/java_files/Maps/europe/france/bretagne.mapgr";
|
||||
|
||||
final static String maps[] = { hauteGaronne, polynesie, bretagne };
|
||||
|
||||
final static int nbRoutesTest = 5; //Variable utilisée pour déterminer le nombre d'itinéraires à tester par carte et par mode
|
||||
//Dans l'état actuel, les tests seront effectués pour nbRoutesTest*3*2 itinéraires
|
||||
|
||||
protected static ShortestPathData dataShortest[];
|
||||
protected static ShortestPathData dataFastest[];
|
||||
protected static ShortestPathData dataInfeasable, dataOneNode;
|
||||
protected static int tabOrigin[], tabDestination[];
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
|
||||
List<ArcInspector> arcList = ArcInspectorFactory.getAllFilters();
|
||||
ArcInspector arcShortestAllRoad = arcList.get(0);
|
||||
ArcInspector arcFastestAllRoad = arcList.get(2);
|
||||
|
||||
graphs = new Graph[3];
|
||||
|
||||
//Lecture des différentes cartes
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try (GraphReader reader = new BinaryGraphReader(
|
||||
new DataInputStream(new BufferedInputStream(new FileInputStream(maps[i]))))) {
|
||||
// TODO: Read the graph.
|
||||
graphs[i] = reader.read();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dataShortest = new ShortestPathData[nbRoutesTest * 3];
|
||||
dataFastest = new ShortestPathData[nbRoutesTest * 3];
|
||||
tabOrigin = new int[nbRoutesTest * 3];
|
||||
tabDestination = new int[nbRoutesTest * 3];
|
||||
|
||||
Random rand = new Random(100l);
|
||||
int origine, destination;
|
||||
|
||||
// Pour chaque carte, génère un nombre nbRoutes*2 d'itinéraires (plus court et
|
||||
// plus rapide)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
||||
for (int j = 0; j < nbRoutesTest; j++) {
|
||||
|
||||
origine = rand.nextInt(graphs[i].getNodes().size());
|
||||
destination = rand.nextInt(graphs[i].getNodes().size());
|
||||
dataShortest[i * nbRoutesTest + j] = new ShortestPathData(graphs[i], graphs[i].get(origine),
|
||||
graphs[i].get(destination), arcShortestAllRoad);
|
||||
dataFastest[i * nbRoutesTest + j] = new ShortestPathData(graphs[i], graphs[i].get(origine),
|
||||
graphs[i].get(destination), arcFastestAllRoad);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
dataInfeasable = new ShortestPathData(graphs[1], graphs[1].get(2984), graphs[1].get(10467), arcFastestAllRoad);
|
||||
dataOneNode = new ShortestPathData(graphs[0], graphs[0].get(535), graphs[0].get(535), arcShortestAllRoad);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -298,7 +298,11 @@ public class Path {
|
|||
* kilometers-per-hour).
|
||||
*/
|
||||
public double getTravelTime(double speed) {
|
||||
return this.getLength()/(speed/3.6f);
|
||||
float res = 0.0f;
|
||||
for(Arc a : this.arcs) {
|
||||
res+= a.getTravelTime(speed);
|
||||
}
|
||||
return res;//this.getLength()/(speed/3.6f);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue