Fixed A* time
This commit is contained in:
parent
8168b86d09
commit
d46ea7fcb4
3 changed files with 36 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
|||
package org.insa.graphs.algorithm.shortestpath;
|
||||
|
||||
import org.insa.graphs.algorithm.AbstractInputData;
|
||||
import org.insa.graphs.algorithm.AbstractSolution;
|
||||
import org.insa.graphs.algorithm.utils.BinaryHeap;
|
||||
import org.insa.graphs.algorithm.utils.Label;
|
||||
|
@ -21,8 +22,18 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
|
|||
@Override
|
||||
protected void initLabel(){
|
||||
int i = 0;
|
||||
double maxSpeed = 130;
|
||||
if (data.getMode() == AbstractInputData.Mode.TIME){
|
||||
if (gr.getGraphInformation().hasMaximumSpeed()){
|
||||
maxSpeed = gr.getGraphInformation().getMaximumSpeed();
|
||||
}
|
||||
}
|
||||
for (Node l : gr.getNodes()){
|
||||
labels[i] = new LabelStar(l, false, null,data.getDestination());
|
||||
if (data.getMode() == AbstractInputData.Mode.TIME){
|
||||
labels[i] = new LabelStar(l, false, null,data.getDestination(), maxSpeed);
|
||||
} else {
|
||||
labels[i] = new LabelStar(l, false, null,data.getDestination());
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.insa.graphs.algorithm.utils;
|
||||
|
||||
import org.insa.graphs.algorithm.AbstractInputData;
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
||||
import org.insa.graphs.model.Arc;
|
||||
import org.insa.graphs.model.Node;
|
||||
|
||||
|
@ -7,6 +9,11 @@ public class LabelStar extends Label{
|
|||
|
||||
private double crowCost;
|
||||
|
||||
public LabelStar(Node currNode, boolean marked, Arc father, Node dest, double maxSpeed){
|
||||
super(currNode,marked,father);
|
||||
this.crowCost = currNode.getPoint().distanceTo(dest.getPoint())/(maxSpeed*3.6);
|
||||
}
|
||||
|
||||
public LabelStar(Node currNode, boolean marked, Arc father, Node dest){
|
||||
super(currNode,marked,father);
|
||||
this.crowCost = currNode.getPoint().distanceTo(dest.getPoint());
|
||||
|
|
|
@ -21,8 +21,13 @@ import org.insa.graphs.model.io.BinaryPathReader;
|
|||
import org.insa.graphs.model.io.GraphReader;
|
||||
import org.insa.graphs.model.io.PathReader;
|
||||
|
||||
// for colouring
|
||||
import java.util.Random;
|
||||
import java.awt.Color;
|
||||
|
||||
public class Launch {
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Drawing inside a JFrame an return it.
|
||||
*
|
||||
|
@ -136,7 +141,12 @@ public class Launch {
|
|||
Path drawPath = createTestPath(graph, Id1, Id2, "BF");
|
||||
if (drawPath != null){
|
||||
if (!drawPath.isEmpty()){
|
||||
drawing.drawPath(drawPath);
|
||||
|
||||
Random rand = new Random();
|
||||
float r = rand.nextFloat();
|
||||
float g = rand.nextFloat();
|
||||
float b = rand.nextFloat();
|
||||
drawing.drawPath(drawPath,new Color(r, g, b));
|
||||
}
|
||||
}
|
||||
return resu;
|
||||
|
@ -146,7 +156,7 @@ public class Launch {
|
|||
|
||||
// Visit these directory to see the list of available files on Commetud.
|
||||
final String mapName = "/home/rlacroix/Bureau/3MIC/Be Graphe/mapinsa/insa.mapgr";
|
||||
final String pathName = "/home/rlacroix/Bureau/3MIC/Be Graphe/mapinsa/path_fr31insa_rangueil_r2.path";
|
||||
//final String pathName = "/home/rlacroix/Bureau/3MIC/Be Graphe/mapinsa/path_fr31insa_rangueil_r2.path";
|
||||
|
||||
// Create a graph reader.
|
||||
final GraphReader reader = new BinaryGraphReader(
|
||||
|
@ -162,19 +172,19 @@ public class Launch {
|
|||
drawing.drawGraph(graph);
|
||||
|
||||
// TODO: Create a PathReader.
|
||||
final PathReader pathReader = new BinaryPathReader(
|
||||
new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))));
|
||||
//final PathReader pathReader = new BinaryPathReader(
|
||||
// new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))));
|
||||
|
||||
// TODO: Read the path.
|
||||
final Path path = pathReader.readPath(graph);
|
||||
//final Path path = pathReader.readPath(graph);
|
||||
|
||||
// TODO: Draw the path.
|
||||
drawing.drawPath(path);
|
||||
//drawing.drawPath(path);
|
||||
|
||||
System.out.println("==TESTS==");
|
||||
|
||||
|
||||
int nbTest = 1000;
|
||||
int nbTest = 10000;
|
||||
int juste = 0;
|
||||
|
||||
for (int i = 0; i < nbTest; i++){
|
||||
|
|
Loading…
Reference in a new issue