Browse Source

A* valide long/time

Favary Pierre 2 years ago
parent
commit
d8fe9068ac

+ 20
- 1
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java View File

@@ -1,22 +1,41 @@
1 1
 package org.insa.graphs.algorithm.shortestpath;
2 2
 
3 3
 
4
+import org.insa.graphs.algorithm.AbstractInputData.Mode;
4 5
 import org.insa.graphs.model.Arc;
5 6
 import org.insa.graphs.model.Node;
6 7
 
7 8
 public class AStarAlgorithm extends DijkstraAlgorithm {
8 9
 	
10
+	
11
+	private int sineg(int a, int b) {
12
+		int retour=a;
13
+		if (a<1)
14
+			retour=b;
15
+		return retour;
16
+	}
17
+	
18
+	private int vitessemax=sineg(data.getMaximumSpeed(), data.getGraph().getGraphInformation().getMaximumSpeed());
19
+	
9 20
 		
10 21
     public AStarAlgorithm(ShortestPathData data) {
11 22
         super(data);
12 23
     }
13 24
     
14 25
     public Label LabelTyped(Node sommet, Arc padre, float prix) {
15
-    	return new LabelStar(sommet, padre, prix, (float)this.getInputData().getDestination().getPoint().distanceTo(sommet.getPoint()));
26
+    	
27
+    	float difference=(float)this.getInputData().getDestination().getPoint().distanceTo(sommet.getPoint());
28
+    	//prend la valeur de la distance à vol d'oiseau  		
29
+    	    	
30
+    	if (data.getMode()==Mode.TIME) 
31
+    		difference=difference/this.vitessemax;
32
+    	
33
+    	return new LabelStar(sommet, padre, prix, difference);
16 34
     }
17 35
     
18 36
     //particularités de A*:
19 37
     //-comment trouver la distance à vol d'oiseau entre deux nodes?--------node.getpoint().distanceTo()?
38
+    //comment avoir (le temps min ou) la vitesse max?
20 39
     //-comment initialiser le labelstar.estim de chaque node avec cette méthode
21 40
     //-comment avoir des LabelStar et non des Label
22 41
     

+ 1
- 3
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java View File

@@ -51,7 +51,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
51 51
         		
52 52
 	        	tablabel[x].marque=true;
53 53
 	        	this.notifyNodeMarked(tablabel[x].sommet_courant);
54
-	        	//System.out.printf("%f\n",tablabel[x].cout);
54
+	        	//System.out.printf("%f\n",tablabel[x].getTotalCost());
55 55
 	        	//System.out.printf("%d\n",tablabel[x].sommet_courant.getNumberOfSuccessors());
56 56
 	        	nomark--;
57 57
 	        	int y;
@@ -76,7 +76,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
76 76
 	        				
77 77
 	        			}
78 78
 	        		}
79
-	             	//penser à gérer le cas "aucun chemin n'existe" (avec l'initialisation par défaut?)
80 79
 	        	}
81 80
 	        }
82 81
         }
@@ -103,7 +102,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
103 102
         	//System.out.printf("distance réelle origine-destination (test): %f", (float)this.getInputData().getOrigin().getPoint().distanceTo(this.getInputData().getDestination().getPoint()));
104 103
         	
105 104
         	
106
-        	//comparer le coût avec celui de la méthode Path en utilisant equals ou compareTo, mais Dijkstra ne renvoie pas de coût de lui-même, ni ShortestPathSolution?
107 105
         	}
108 106
         
109 107
         return solution;

+ 0
- 4
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/LabelStar.java View File

@@ -25,10 +25,6 @@ public class LabelStar extends Label implements Comparable<Label>{
25 25
 		return this.cout+this.estim;
26 26
 	}
27 27
 	
28
-	//...
29
-	public void setEstimation(Node destination) {
30
-		this.estim=(float)destination.getPoint().distanceTo(this.sommet_courant.getPoint());
31
-	}
32 28
 	
33 29
 	//note: pourquoi l'icône de ce fichier dans eclipse est-elle un peu différente?
34 30
 }

Loading…
Cancel
Save