Browse Source

fin séance

Favary Pierre 2 years ago
parent
commit
3c2d58faec

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

@@ -1,27 +0,0 @@
1
-package org.insa.graphs.algorithm.shortestpath;
2
-
3
-import org.insa.graphs.model.Arc;
4
-import org.insa.graphs.model.Path;//trier tout ça
5
-
6
-public class AStar extends DijkstraAlgorithm {
7
-	
8
-	
9
-	public void initLabel() {
10
-		int placeholder=0;
11
-		
12
-	}
13
-	
14
-	
15
-    public AStar(ShortestPathData data) {
16
-        super(data);
17
-    }
18
-
19
-    public void proc1modifDijk() {
20
-    	this.getInputData().getDestination();
21
-    }
22
-    
23
-    //particularités de A*:
24
-    //-comment trouver la distance à vol d'oiseau entre deux nodes?--------node.getpoint().distanceTo()?
25
-    //-comment initialiser le labelstar.estim de chaque node avec cette méthode
26
-    //-comment avoir des LabelStar et non des Label
27
-}

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

@@ -1,9 +1,23 @@
1 1
 package org.insa.graphs.algorithm.shortestpath;
2 2
 
3
-public class AStarAlgorithm extends DijkstraAlgorithm {
4 3
 
4
+import org.insa.graphs.model.Arc;
5
+import org.insa.graphs.model.Node;
6
+
7
+public class AStarAlgorithm extends DijkstraAlgorithm {
8
+	
9
+		
5 10
     public AStarAlgorithm(ShortestPathData data) {
6 11
         super(data);
7 12
     }
8
-
13
+    
14
+    public Label LabelTyped(Node sommet, Arc padre, float prix) {
15
+    	return new LabelStar(sommet, padre, prix, (float)this.getInputData().getDestination().getPoint().distanceTo(sommet.getPoint()));
16
+    }
17
+    
18
+    //particularités de A*:
19
+    //-comment trouver la distance à vol d'oiseau entre deux nodes?--------node.getpoint().distanceTo()?
20
+    //-comment initialiser le labelstar.estim de chaque node avec cette méthode
21
+    //-comment avoir des LabelStar et non des Label
22
+    
9 23
 }

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

@@ -3,6 +3,7 @@ package org.insa.graphs.algorithm.shortestpath;
3 3
 import org.insa.graphs.algorithm.AbstractSolution.Status;
4 4
 import org.insa.graphs.algorithm.utils.BinaryHeap;
5 5
 import org.insa.graphs.model.Arc;
6
+import org.insa.graphs.model.Node;
6 7
 import org.insa.graphs.model.Path;
7 8
 import java.util.ArrayList;
8 9
 import java.util.Collections;//trier tout ça
@@ -13,7 +14,11 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
13 14
     public DijkstraAlgorithm(ShortestPathData data) {
14 15
         super(data);
15 16
     }
16
-
17
+    
18
+    public Label LabelTyped(Node sommet,Arc padre, float prix){
19
+    	return new Label(sommet,padre, prix);
20
+    }
21
+    
17 22
     @Override
18 23
     protected ShortestPathSolution doRun() {
19 24
     	
@@ -22,17 +27,19 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
22 27
         
23 28
         //initialisation
24 29
         BinaryHeap<Label> tas=new BinaryHeap<Label>();//les Label sont comparés via leurs coûts
30
+        
25 31
         Label[] tablabel=new Label[data.getGraph().size()];
26 32
         for (int i=0;i<tablabel.length;i++) {
27
-        	tablabel[i]=new Label(data.getGraph().get(i),null,Float.MAX_VALUE);//non marqué par défaut
33
+        	tablabel[i]=LabelTyped(data.getGraph().get(i),null,Float.MAX_VALUE);//non marqué par défaut
28 34
         }//dans le tablabel[idnode] on peut retrouver node
29 35
         tablabel[data.getOrigin().getId()].cout=0;
30
-        tas.insert(tablabel[data.getOrigin().getId()]);
31
-                
36
+        
37
+        tas.insert(tablabel[data.getOrigin().getId()]);                
32 38
         int nomark=tablabel.length;//nombre de sommets non marqués (pas optimal?)
33 39
         int x;//id du node qu'on étudie
34 40
         boolean arrive=false;//node de destination atteint ou pas
35 41
         
42
+        
36 43
         //itérations
37 44
         while (nomark>0 && !arrive && !tas.isEmpty()){
38 45
         	
@@ -56,14 +63,14 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
56 63
 	        		
57 64
 	        		if (!tablabel[y].marque && data.isAllowed(arcy)) {//ligne 108 de l'excel d'avancement
58 65
 	        			
59
-	        			if (tablabel[y].cout>tablabel[x].cout+(float)data.getCost(arcy)) {
66
+	        			if (tablabel[y].getCost()>tablabel[x].getCost()+(float)data.getCost(arcy)) {
60 67
 	        				
61
-	        				if (tablabel[y].cout!=Float.MAX_VALUE) {
68
+	        				if (tablabel[y].getCost()!=Float.MAX_VALUE) {
62 69
 	        					tas.remove(tablabel[y]);
63 70
 	        					this.notifyNodeReached(arcy.getDestination());
64 71
 	        				}
65 72
 	        				
66
-	        				tablabel[y].cout=tablabel[x].cout+(float)data.getCost(arcy);
73
+	        				tablabel[y].cout=tablabel[x].getCost()+(float)data.getCost(arcy);
67 74
 	        				tablabel[y].pere=arcy;//ligne non dans le poly
68 75
 	        				tas.insert(tablabel[y]);
69 76
 	        				
@@ -86,7 +93,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
86 93
         	while (labelact.pere!=null) {
87 94
         		bonsarcs.add(labelact.pere);
88 95
         		labelact=tablabel[labelact.pere.getOrigin().getId()];
89
-        		}
96
+        	}
90 97
         	
91 98
         	Collections.reverse(bonsarcs);
92 99
         	solution = new ShortestPathSolution(data,Status.OPTIMAL,new Path(data.getGraph(),bonsarcs));

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

@@ -3,7 +3,7 @@ package org.insa.graphs.algorithm.shortestpath;
3 3
 import org.insa.graphs.model.Arc;
4 4
 import org.insa.graphs.model.Node;
5 5
 
6
-public class LabelStar extends Label{
6
+public class LabelStar extends Label implements Comparable<Label>{
7 7
 	
8 8
 	protected float estim;
9 9
 
@@ -12,11 +12,11 @@ public class LabelStar extends Label{
12 12
 		this.estim=estimation;
13 13
 	}
14 14
 	
15
-	public LabelStar(Node sommet, Arc padre, float prix, float estimation, boolean mark) {
15
+	public LabelStar(Node sommet,Arc padre, float prix, float estimation, boolean mark) {
16 16
 		super(sommet, padre, prix, mark);
17 17
 		this.estim=estimation;
18 18
 	}
19
-	
19
+		
20 20
 	public float getEstimation() {
21 21
 		return this.estim;//même remarque que pour son pendant dans Label
22 22
 	}
@@ -30,5 +30,5 @@ public class LabelStar extends Label{
30 30
 		this.estim=(float)destination.getPoint().distanceTo(this.sommet_courant.getPoint());
31 31
 	}
32 32
 	
33
-	//note: pourquoi l'icône de ce fichier de eclipse est-elle un peu différente?
33
+	//note: pourquoi l'icône de ce fichier dans eclipse est-elle un peu différente?
34 34
 }

Loading…
Cancel
Save