Compare commits

...

2 commits

Author SHA1 Message Date
ac18c2d522 Added more test cases 2020-05-22 14:53:53 +02:00
e8331864ab Improved A* time estimation 2020-05-22 14:53:37 +02:00
2 changed files with 22 additions and 27 deletions

View file

@ -1,10 +1,6 @@
package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.algorithm.AbstractInputData;
import org.insa.graphs.model.Graph;
import org.insa.graphs.model.Node;
import org.insa.graphs.model.Point;
import org.insa.graphs.model.RoadInformation;
public class AStarAlgorithm extends DijkstraAlgorithm {
@ -23,11 +19,11 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
final double distance = graph.getNodes().get(i).getPoint().distanceTo(
data.getDestination().getPoint()
);
final double maxSpeed = data.getMaximumSpeed();
double estimatedCost = distance;
if (data.getMode() == ShortestPathData.Mode.TIME)
estimatedCost /= maxSpeed;
labels[i].setEstimatedCost(estimatedCost);
final double maxSpeed = graph.getGraphInformation().getMaximumSpeed();
double estimatedCost = distance;
if (data.getMode() == ShortestPathData.Mode.TIME)
estimatedCost /= maxSpeed;
labels[i].setEstimatedCost(estimatedCost);
}
return this.doDijkstra(labels, data, graph);
}

View file

@ -27,7 +27,7 @@ public abstract class AlgoTest {
protected ArrayList<PathDataset> invalidTestData;
// Graphs to use
private Graph graphInsa, graphSquare, graphBretagne;
private Graph graphInsa, graphSquare, graphBretagne, graphGuadeloupe;
/**
* Class used to store all data related to a path and its computed solutions
@ -129,6 +129,7 @@ public abstract class AlgoTest {
graphInsa = readGraph("../Maps/insa.mapgr");
graphSquare = readGraph("../Maps/carre.mapgr");
graphBretagne = readGraph("../Maps/bretagne.mapgr");
graphGuadeloupe = readGraph("../Maps/guadeloupe.mapgr");
}
/**
@ -139,20 +140,23 @@ public abstract class AlgoTest {
filterTime = ArcInspectorFactory.getAllFilters().get(2);
}
private PathDataset getNewPathDataset(Graph graph, int originID, int destinationID) {
return new PathDataset(
graph,
graph.getNodes().get(originID),
graph.getNodes().get(destinationID)
);
}
/**
* Creates valid data sets
*/
private void initValidPathList() {
validTestData = new ArrayList<>();
validTestData.add(new PathDataset(
graphInsa,
graphInsa.getNodes().get(512),
graphInsa.getNodes().get(526)));
validTestData.add(new PathDataset(
graphSquare,
graphSquare.getNodes().get(21),
graphSquare.getNodes().get(17)));
validTestData.add(getNewPathDataset(graphInsa, 512, 526));
validTestData.add(getNewPathDataset(graphGuadeloupe, 12822, 13687));
validTestData.add(getNewPathDataset(graphSquare, 21, 17));
}
/**
@ -161,15 +165,10 @@ public abstract class AlgoTest {
private void initInvalidPathList() {
invalidTestData = new ArrayList<>();
invalidTestData.add(new PathDataset(
graphBretagne,
graphBretagne.getNodes().get(29270),
graphBretagne.getNodes().get(545599)));
invalidTestData.add(new PathDataset(
graphSquare,
graphSquare.getNodes().get(10),
graphSquare.getNodes().get(10)));
invalidTestData.add(getNewPathDataset(graphBretagne, 29270, 545599));
invalidTestData.add(getNewPathDataset(graphGuadeloupe, 26963, 4307));
invalidTestData.add(getNewPathDataset(graphGuadeloupe, 8185, 8185));
invalidTestData.add(getNewPathDataset(graphSquare, 10, 10));
}
/**