Browse Source

fin séance

Favary Pierre 3 years ago
parent
commit
3c2d58faec

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

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