Browse Source

On branch master

 Changes to be committed:
	modified:   be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java
	modified:   be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeap.java
	new file:   be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/Label.java
	new file:   be-graphes-model/src/main/java/org/insa/graphs/model/Label.java
Jdihadi Ahamdy 3 years ago
parent
commit
43c08bf88e

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

@@ -1,5 +1,16 @@
1 1
 package org.insa.graphs.algorithm.shortestpath;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.Arrays;
5
+import java.util.Collections;
6
+import java.util.Iterator;
7
+
8
+import org.insa.graphs.model.Arc;
9
+import org.insa.graphs.model.Graph;
10
+import org.insa.algo.AbstractSolution.Status;
11
+import org.insa.algo.utils.*;
12
+import org.insa.graph.*;
13
+
3 14
 public class DijkstraAlgorithm extends ShortestPathAlgorithm {
4 15
 
5 16
     public DijkstraAlgorithm(ShortestPathData data) {
@@ -8,8 +19,28 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
8 19
 
9 20
     @Override
10 21
     protected ShortestPathSolution doRun() {
11
-        final ShortestPathData data = getInputData();
12 22
         ShortestPathSolution solution = null;
23
+        
24
+        			// Initialisation
25
+    	// du graphe
26
+    	final ShortestPathData data = getInputData();
27
+        Graph graph = data.getGraph();
28
+        final int nbNodes = graph.size();
29
+        // des couts 
30
+        double[] distances = new double[nbNodes];
31
+        Arrays.fill(distances, Double.POSITIVE_INFINITY);
32
+        distances[data.getOrigin().getId()] = 0;
33
+        
34
+        // Notify observers about the first event (origin processed).
35
+        notifyOriginProcessed(data.getOrigin());
36
+        
37
+        // Initialize array of predecessors.
38
+        Arc[] predecessorArcs = new Arc[nbNodes];
39
+        
40
+
41
+        while (solution == null) { //Tant qu'il y a pas de solution 
42
+        	
43
+        }
13 44
         // TODO:
14 45
         return solution;
15 46
     }

+ 20
- 2
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeap.java View File

@@ -137,8 +137,26 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
137 137
 
138 138
     @Override
139 139
     public void remove(E x) throws ElementNotFoundException {
140
-        // TODO:
141
-    }
140
+    	int index;
141
+    	int lastindex;
142
+    	E lastItem;
143
+    	if(this.isEmpty())
144
+    		throw new ElementNotFoundException(x);
145
+    	else {
146
+    		index = this.array.indexOf(x);
147
+    		if(index == -1 || index >= this.currentSize) {
148
+    			throw new ElementNotFoundException(x);
149
+    		}
150
+    		else {
151
+    			lastindex=--this.currentSize;
152
+	    		lastItem = this.array.get(lastindex);
153
+	    		this.array.set(index, lastItem);
154
+	    		this.percolateDown(index);
155
+	    		this.percolateUp(index);
156
+    			}
157
+    		}
158
+    	}   
159
+    
142 160
 
143 161
     @Override
144 162
     public E findMin() throws EmptyPriorityQueueException {

+ 38
- 0
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/Label.java View File

@@ -0,0 +1,38 @@
1
+package org.insa.graphs.algorithm.utils;
2
+
3
+import org.insa.graphs.model.Node;
4
+
5
+public class Label {
6
+	
7
+	private boolean mark;
8
+	private int cost;
9
+	private Node father;
10
+	private Node nodes;
11
+	
12
+	public Label(Node noeud) {
13
+		this.nodes=noeud;
14
+		this.mark=false;
15
+		this.cost=100000;
16
+		this.father=null;
17
+	}
18
+		
19
+	public int getCost() {
20
+		return this.cost;
21
+	}
22
+	
23
+	public boolean getMark() {
24
+		return this.mark;
25
+	}
26
+	
27
+	public Node getfather() {
28
+		return this.father;
29
+	}
30
+	
31
+	public boolean setMark() {
32
+		return this.mark=true;
33
+	}
34
+	
35
+	
36
+	
37
+	
38
+}

+ 10
- 0
be-graphes-model/src/main/java/org/insa/graphs/model/Label.java View File

@@ -0,0 +1,10 @@
1
+package org.insa.graphs.model;
2
+
3
+public class Label {
4
+
5
+	public static void main(String[] args) {
6
+		// TODO Auto-generated method stub
7
+
8
+	}
9
+
10
+}

Loading…
Cancel
Save