Mon répertoire pour le bureau d'étude graphes de 3MIC à l'INSA de Toulouse
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AStarAlgorithm.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package org.insa.graphs.algorithm.shortestpath;
  2. import org.insa.graphs.algorithm.AbstractInputData.Mode;
  3. import org.insa.graphs.model.Node;
  4. import org.insa.graphs.model.Point;
  5. public class AStarAlgorithm extends DijkstraAlgorithm {
  6. Node arrivee;
  7. Mode mode;
  8. double max_speed;
  9. class LabelStar extends Label {
  10. Node arrivee;
  11. double heuristiqueArrive;
  12. public LabelStar(Node sommet_courant, Node pere, double cout, Node arrivee) {
  13. super(sommet_courant, pere, cout);
  14. this.arrivee = arrivee;
  15. switch (mode) {
  16. case TIME:
  17. this.heuristiqueArrive = this.sommet_courant.getPoint().distanceTo(arrivee.getPoint()) / max_speed;
  18. break;
  19. case LENGTH:
  20. this.heuristiqueArrive = Point.distance(super.sommet_courant.getPoint(), arrivee.getPoint());
  21. break;
  22. }
  23. }
  24. @Override
  25. public int compareTo(Label other) throws IllegalArgumentException {
  26. return Double.compare(
  27. this.cout + heuristiqueArrive,
  28. other.cout + ((LabelStar)other).heuristiqueArrive);
  29. }
  30. }
  31. public AStarAlgorithm(ShortestPathData data) {
  32. super(data);
  33. this.arrivee = data.getDestination();
  34. this.mode = data.getMode();
  35. this.max_speed = (double) data.getMaximumSpeed()/3.6;
  36. if (this.max_speed < 0){
  37. this.max_speed = (double) data.getGraph().getGraphInformation().getMaximumSpeed() / 3.6;
  38. }
  39. }
  40. @Override
  41. public Label createLabel(Node n) {
  42. return new LabelStar(n, null, Float.MAX_VALUE, arrivee);
  43. }
  44. public Label createLabel(Node n, double cout) {
  45. return new LabelStar(n, null, cout, arrivee);
  46. }
  47. }