Browse Source

Launch.java fini et BinaryHeap Remove() fini

Guillaume Vincent 4 years ago
parent
commit
870726461b

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

@@ -83,7 +83,6 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
83 83
 
84 84
         this.arraySet(index, x);
85 85
     }
86
-
87 86
     /**
88 87
      * Internal method to percolate down in the heap.
89 88
      * 
@@ -138,6 +137,14 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
138 137
     @Override
139 138
     public void remove(E x) throws ElementNotFoundException {
140 139
         // TODO:
140
+        int index = array.indexOf(x);
141
+        if (isEmpty() || index < 0 || index >= this.currentSize) {
142
+            throw new ElementNotFoundException(x); 
143
+        }
144
+        E lastItem = this.array.get(--this.currentSize);
145
+        this.arraySet(index,lastItem);
146
+        this.percolateUp(index);
147
+        this.percolateDown(index);
141 148
     }
142 149
 
143 150
     @Override

+ 11
- 7
be-graphes-gui/src/main/java/org/insa/graphs/gui/simple/Launch.java View File

@@ -14,6 +14,7 @@ import org.insa.graphs.gui.drawing.components.BasicDrawing;
14 14
 import org.insa.graphs.model.Graph;
15 15
 import org.insa.graphs.model.Path;
16 16
 import org.insa.graphs.model.io.BinaryGraphReader;
17
+import org.insa.graphs.model.io.BinaryPathReader;
17 18
 import org.insa.graphs.model.io.GraphReader;
18 19
 import org.insa.graphs.model.io.PathReader;
19 20
 
@@ -46,28 +47,31 @@ public class Launch {
46 47
     public static void main(String[] args) throws Exception {
47 48
 
48 49
         // Visit these directory to see the list of available files on Commetud.
49
-        final String mapName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
50
-        final String pathName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path";
50
+        final String mapName = "C:/Users/guill/OneDrive/Bureau/Graphes/GraphesGit/Cartes/insa.mapgr";
51
+        final String pathName = "C:/Users/guill/OneDrive/Bureau/Graphes/GraphesGit/Cartes/paths/path_fr31insa_rangueil_r2.path";
51 52
 
52 53
         // Create a graph reader.
53 54
         final GraphReader reader = new BinaryGraphReader(
54 55
                 new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
55 56
 
56 57
         // TODO: Read the graph.
57
-        final Graph graph = null;
58
+        final Graph graph = reader.read();
58 59
 
59 60
         // Create the drawing:
60 61
         final Drawing drawing = createDrawing();
61 62
 
62 63
         // TODO: Draw the graph on the drawing.
64
+        drawing.drawGraph(graph);
63 65
 
64 66
         // TODO: Create a PathReader.
65
-        final PathReader pathReader = null;
66
-
67
+        final PathReader pathReader = new BinaryPathReader(
68
+                new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))));
69
+        
67 70
         // TODO: Read the path.
68
-        final Path path = null;
69
-
71
+        final Path path = pathReader.readPath(graph);
72
+        
70 73
         // TODO: Draw the path.
74
+        drawing.drawPath(path);
71 75
     }
72 76
 
73 77
 }

+ 1
- 1
be-graphes-model/src/main/java/org/insa/graphs/model/Path.java View File

@@ -35,7 +35,7 @@ public class Path {
35 35
 	public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
36 36
             throws IllegalArgumentException {
37 37
         List<Arc> arcs = new ArrayList<Arc>();
38
-        // TODO:
38
+        // DONE:
39 39
         if (nodes.size() == 1) {
40 40
         	return new Path(graph,nodes.get(0));
41 41
         }

Loading…
Cancel
Save