Browse Source

Brouillon Dijkstra

Favary Pierre 3 years ago
parent
commit
2a5ac7f244

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

@@ -1,6 +1,9 @@
1 1
 package org.insa.graphs.algorithm.shortestpath;
2 2
 
3
+import org.insa.graphs.algorithm.utils.BinaryHeap;
4
+
3 5
 public class DijkstraAlgorithm extends ShortestPathAlgorithm {
6
+	
4 7
 
5 8
     public DijkstraAlgorithm(ShortestPathData data) {
6 9
         super(data);
@@ -11,6 +14,38 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
11 14
         final ShortestPathData data = getInputData();
12 15
         ShortestPathSolution solution = null;
13 16
         // TODO:
17
+        
18
+        //initialisation
19
+        BinaryHeap tas=new BinaryHeap();
20
+        Label[] tablabel=new Label[data.getGraph().size()];
21
+        for (int i=0;i<tablabel.length;i++) {
22
+        	tablabel[i]=new Label(data.getGraph().get(i),null,Integer.MAX_VALUE);
23
+        }
24
+        tablabel[data.getOrigin().getId()].cout=0;
25
+        tas.insert(data.getOrigin().getId());
26
+        
27
+        boolean exnonmar=true;
28
+        int min;
29
+        //itérations
30
+        while (exnonmar) {
31
+        	min=tas.deleteMin();
32
+        	tablabel[min].marque=true;
33
+        	for (successeurs y) {
34
+        		if (!tablabel[y].marque) {
35
+        			if (tablabel[y].cout>tablabel[x].cout+(int)tablabel[y].pere.getMinimumTravelTime()) {
36
+        				tablabel[y].cout=tablabel[x].cout+(int)tablabel[y].pere.getMinimumTravelTime();
37
+        				if (exist y in tas) {
38
+        					tas.update(y);
39
+        				}else {
40
+        					tas.insert(y);
41
+        				}
42
+        			}
43
+        		}
44
+        	}
45
+        	
46
+        	exnonmar=false;
47
+        }
48
+        
14 49
         return solution;
15 50
     }
16 51
 

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

@@ -5,10 +5,6 @@ import org.insa.graphs.model.Node;
5 5
 
6 6
 public class Label {
7 7
 	
8
-	//comment avoir le nombre de nodes dans le graph? (pour lier un unique label à chaque node)
9
-	private Label[] tablabel=new Label[50000000];//5000000 placeholder
10
-	
11
-		
12 8
 	//quelles valeurs de protection?
13 9
 	protected Node sommet_courant;
14 10
 	
@@ -24,29 +20,20 @@ public class Label {
24 20
 	
25 21
 	//constructeur
26 22
 	public Label(Node sommet,Arc padre, int prix) {
27
-		if (tablabel[sommet.getId()]==null)
28
-			this.sommet_courant=sommet;
23
+		this.sommet_courant=sommet;
29 24
 		this.pere=padre;
30 25
 		this.cout=prix;
31 26
 		this.marque=false;//!\\ pas sûr que ce soit une bonne idée
32
-		tablabel[sommet.getId()]=this;		
33
-	}
27
+	}	
34 28
 	
35
-	//la condition tablabel==null est un placeholder /!\
36 29
 	public Label(Node sommet,Arc padre, int prix, boolean mark) {
37
-		if (tablabel[sommet.getId()]==null)
38
-			this.sommet_courant=sommet;
30
+		this.sommet_courant=sommet;
39 31
 		this.pere=padre;
40 32
 		this.cout=prix;
41 33
 		this.marque=mark;
42
-		tablabel[sommet.getId()]=this;
43 34
 		
44 35
 	}
45 36
 	
46
-	public Label getLabel(Node unnode) {
47
-		return tablabel[unnode.getId()];
48
-	}
49
-	
50 37
 	public int getCost() {
51 38
 		return this.cout;
52 39
 	}

Loading…
Cancel
Save