Browse Source

added images and commented code

Lacroix Raphael 1 year ago
parent
commit
47150a44b1

+ 77
- 0
DeLorean.java View File

@@ -0,0 +1,77 @@
1
+// pseudo code du rapport sur le problme ouvert
2
+
3
+
4
+public class DeLoreanShortestPath extends ShortestPathAlgorithm {
5
+    public DijkstraAlgorithm(ShortestPathData data) {
6
+        super(data);
7
+    }
8
+
9
+    ShortestPathSolution solution;
10
+
11
+    // on pourra par exemple mettre le graphe des stations dans data
12
+    final ShortestPathData data = getInputData();
13
+    Graph gr = data.getGraph();
14
+    StationGraph grS = data.getStationGraph();
15
+    double maximumDist = ... //(ici 200000, on pourrait passer cette variable dans data puisque certains voitures n'auront pas la même autonomie)
16
+
17
+    /*On part du principe ici que le coût en temps prend déjà en compte les 10 minutes de rechargement. Il suffirait si ce n'est pas le cas de regarder si la destination de l'arc est la destination finale et si ce n'est pas le cas de rajouter 10 au coût temporel*/
18
+
19
+    // on récupère la destination et l'origine
20
+    NodeStation nodeA = getNodeStationFromNode(...)
21
+    NodeStation nodeB = getNodeStationFromNode(...)
22
+
23
+    //On récupère la liste des nodes correspondantes aux stations (stockée dans notre graphe des stations).
24
+    arrayList<NodeStation> list = getNodeStationsFromNode(...)
25
+
26
+        /*
27
+        int UpdateGraphIsodistance(Node,double,Graph)
28
+        est une méthode de la classe StationGraph qui met à jour le StationGraph par rapport à l'Isodistance autour de A dans le graphe graph. Elle renvoie le nombre d'arrêtes crées (-1 si aucune).*/
29
+            // on calcule l'Isodistance de A
30
+            if (grS.UpdateIsodistance(NodeA,maximumDist,gr) != -1){
31
+
32
+        // A.hasSuccessor(B) itère sur les successeurs d'un NodeStation (A) et vérifie si l'un d'entre eux est B
33
+        if(!NodeA.hasSuccessor(NodeB)){
34
+            // on calcule l'Isodistance de B
35
+            if (grS.UpdateIsodistance(NodeB,maximumDist,gr) != -1){
36
+
37
+                /*StationAStarAlgorithm(ShortestPathData, double) hérite de AStar et ne fait que s'adapter aux classes "Station" pour rechercher quel est le plus court chemin sur le graphe des stations*/
38
+
39
+                StationAStarAlgorithm AAlgo = new StationAStarAlgorithm(data);
40
+                StationPath aStarResult = AAlgo.doRun();
41
+                arrayList<ArcStation> way = aStarResult.getStationArc();
42
+                Path[] pathArray = new Path[way.size()];
43
+
44
+                int i = 0;
45
+                for(ArcStation i : way){
46
+                    if (data.getMode() == AbstractInputData.Mode.TIME) {
47
+                        pathArray[i] = way.getTimePath()
48
+                        // à noter qu'on pourrait également retourner le path renvoyé par un ModifiedAStarAlgorithm lancé en temps si le choix a été fait de ne pas stocker dans les arc le chemin correspondant.
49
+                    } else {
50
+                        pathArray[i] = way.getLengthPath()
51
+                    }
52
+                }
53
+                // à noter également que si l'on choisit de stocker des listes d'Arc plutôt que des Path il suffira de faire remplacer le Path.concatenate(...) par un new Path(gr, arcs)
54
+
55
+
56
+                // il nous faut maintenant concaténer les chemins entre chaque station
57
+                solution = new ShortestPathSolution(data, AbstractSolution.Status.OPTIMAL, Path.concatenate(pathArray));
58
+
59
+
60
+            } else {
61
+                // aucune solution car aucune NodeS dans l'isodistance de B
62
+
63
+                solution = new ShortestPathSolution(data, AbstractSolution.Status.INFEASIBLE);
64
+            }
65
+        } else {
66
+            /*ModifiedAStarAlgorithm(ShortestPathData, double) hérite de AStar et ne change que le fait qu'un arc n'est inséré que si son coût depuis l'origine est inférieur à la valeur passée en argument du constructeur */
67
+
68
+
69
+            // pas besoin de stations car B est dans l'isodistance de A
70
+            ModifiedAStarAlgorithm AAlgo = new ModifiedAStarAlgorithm(data, maximumDist);
71
+            solution = AAlgo.doRun();
72
+        }
73
+    } else {
74
+        // aucune solution car aucune NodeS dans l'isodistance de A
75
+        solution = new ShortestPathSolution(data, AbstractSolution.Status.INFEASIBLE);
76
+    }
77
+}

BIN
UML1.png View File


BIN
UML2.png View File


+ 17
- 0
be-graphes-algos/.classpath View File

@@ -23,5 +23,22 @@
23 23
 			<attribute name="maven.pomderived" value="true"/>
24 24
 		</attributes>
25 25
 	</classpathentry>
26
+	<classpathentry kind="src" path="target/generated-sources/annotations">
27
+		<attributes>
28
+			<attribute name="optional" value="true"/>
29
+			<attribute name="maven.pomderived" value="true"/>
30
+			<attribute name="ignore_optional_problems" value="true"/>
31
+			<attribute name="m2e-apt" value="true"/>
32
+		</attributes>
33
+	</classpathentry>
34
+	<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
35
+		<attributes>
36
+			<attribute name="optional" value="true"/>
37
+			<attribute name="maven.pomderived" value="true"/>
38
+			<attribute name="ignore_optional_problems" value="true"/>
39
+			<attribute name="m2e-apt" value="true"/>
40
+			<attribute name="test" value="true"/>
41
+		</attributes>
42
+	</classpathentry>
26 43
 	<classpathentry kind="output" path="target/classes"/>
27 44
 </classpath>

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

@@ -19,15 +19,23 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
19 19
         super(data);
20 20
     }
21 21
 
22
+
23
+    // only difference with Dijkstra : using different labels
22 24
     @Override
23 25
     protected void initLabel(){
24 26
         int i = 0;
27
+
28
+        // usefull for the estimated crowlength time,
29
+        // if there are no maximal speed we use 130 km/h
25 30
         double maxSpeed = 130;
31
+
26 32
         if (data.getMode() == AbstractInputData.Mode.TIME){
27 33
             if (gr.getGraphInformation().hasMaximumSpeed()){
28 34
                 maxSpeed = gr.getGraphInformation().getMaximumSpeed();
29 35
             }
30 36
         }
37
+
38
+        // initialization close to Dijkstra's
31 39
         for (Node l : gr.getNodes()){
32 40
             if (data.getMode() == AbstractInputData.Mode.TIME){
33 41
                 labels[i] = new LabelStar(l, false, null,data.getDestination(), maxSpeed);

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

@@ -15,15 +15,22 @@ import java.util.List;
15 15
 
16 16
 public class DijkstraAlgorithm extends ShortestPathAlgorithm {
17 17
 
18
+    /* === Used for testing purposes ===
19
+        private long nodes = 0;
20
+    */
21
+
18 22
     public DijkstraAlgorithm(ShortestPathData data) {
19 23
         super(data);
20 24
     }
25
+
21 26
     final ShortestPathData data = getInputData();
22 27
     Graph gr = data.getGraph();
23 28
 
24 29
     // array containing all the labels
25 30
     Label[] labels = new Label[gr.size()];
26 31
 
32
+
33
+    // initialization (separate so that it can be overridden by the A*)
27 34
     protected void initLabel(){
28 35
         int i = 0;
29 36
         for (Node l : gr.getNodes()){
@@ -45,27 +52,41 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
45 52
         // initialization of the heap & the first node
46 53
         BinaryHeap<Label> pQueue = new BinaryHeap<Label>();
47 54
         labels[data.getOrigin().getId()].setCost(0);
55
+
48 56
         pQueue.insert(labels[data.getOrigin().getId()]);
49 57
 
50 58
         boolean found = false;
51
-        /*double prev = 0;*/
52
-        // Pathfinding
59
+        /* === Used for testing purposes ===
60
+            double prev = 0;
61
+        */
62
+
63
+        // Pathfinding : we iterate while there are still nodes
64
+        // to find and we have not found the destination yet
53 65
         while(!pQueue.isEmpty() && !found){
54 66
 
55 67
             Label labelX = pQueue.deleteMin();
56 68
 
57
-            /*if (labelX.getCost()<prev){System.out.println(labelX.getCost()-prev);}
58
-            prev = labelX.getCost();*/
69
+            /* === Used for testing purposes ===
70
+                if (labelX.getCost()<prev){System.out.println(labelX.getCost()-prev);}
71
+                prev = labelX.getCost();
72
+            */
73
+
74
+            /* === Used for testing purposes ===
75
+                nodes++;
76
+            */
59 77
 
60 78
             labelX.setMarked(true);
61
-            notifyNodeReached(labelX.getCurrNode());
62
-            found = (data.getDestination() == labelX.getCurrNode());
79
+            notifyNodeReached(labelX.getCurrNode()); // displaying function
80
+
81
+            found = (data.getDestination() == labelX.getCurrNode()); // check for destination reaching
63 82
 
64
-            for (Arc y : labelX.getCurrNode().getSuccessors()){
83
+            for (Arc y : labelX.getCurrNode().getSuccessors()){ // iterate over all the successors
65 84
                 Label labelY = labels[y.getDestination().getId()];
66
-                if (!labelY.isMarked() && data.isAllowed(y)){
85
+
86
+                if (!labelY.isMarked() && data.isAllowed(y)){ // check for path types
67 87
 
68 88
                     if (labelY.getCost() > labelX.getCost()+data.getCost(y)){
89
+                        // updating the label with a better cost
69 90
                         if (labels[labelY.getCurrNode().getId()].getCost() != Double.POSITIVE_INFINITY) {
70 91
                             pQueue.remove(labelY);
71 92
                         }
@@ -81,7 +102,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
81 102
         ShortestPathSolution solution = null;
82 103
 
83 104
         // Destination has no predecessor, the solution is infeasible...
84
-        if (!found || labels[data.getDestination().getId()] == null) {
105
+        if (!found || labels[data.getDestination().getId()] == null || data.getDestination().getId()==data.getOrigin().getId()) {
85 106
             solution = new ShortestPathSolution(data, AbstractSolution.Status.INFEASIBLE);
86 107
         }
87 108
         else {
@@ -103,7 +124,9 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
103 124
             // Create the final solution.
104 125
             solution = new ShortestPathSolution(data, AbstractSolution.Status.OPTIMAL, new Path(gr, arcs));
105 126
         }
106
-
127
+        /* === Used for testing purposes ===
128
+            System.out.print(" ... number of nodes : "+nodes);
129
+        */
107 130
         return solution;
108 131
     }
109 132
 

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

@@ -148,7 +148,8 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
148 148
     public void remove(E x) throws ElementNotFoundException {
149 149
     	/* LEGACY CODE :
150 150
     	Index of is not optimized but it's better than nothing. We will come back to improve it if we have time at the end
151
-    	int i = this.array.indexOf(x) */
151
+        int i = this.array.indexOf(x);
152
+    	 */
152 153
 
153 154
 
154 155
         int i = -1;
@@ -164,8 +165,13 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
164 165
         if (i > this.currentSize - 1 || i == -1) {
165 166
     		throw new ElementNotFoundException(x);
166 167
     	}
168
+
169
+        // we decrement the index of the last element and set our value to be after this one
167 170
         E lastItem = this.array.get(--this.currentSize);
171
+
168 172
         this.arraySet(i, lastItem);
173
+
174
+        // need to update the heap
169 175
         this.percolateDown(i);
170 176
         this.percolateUp(i);
171 177
 

+ 17
- 0
be-graphes-gui/.classpath View File

@@ -28,5 +28,22 @@
28 28
 			<attribute name="maven.pomderived" value="true"/>
29 29
 		</attributes>
30 30
 	</classpathentry>
31
+	<classpathentry kind="src" path="target/generated-sources/annotations">
32
+		<attributes>
33
+			<attribute name="optional" value="true"/>
34
+			<attribute name="maven.pomderived" value="true"/>
35
+			<attribute name="ignore_optional_problems" value="true"/>
36
+			<attribute name="m2e-apt" value="true"/>
37
+		</attributes>
38
+	</classpathentry>
39
+	<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
40
+		<attributes>
41
+			<attribute name="optional" value="true"/>
42
+			<attribute name="maven.pomderived" value="true"/>
43
+			<attribute name="ignore_optional_problems" value="true"/>
44
+			<attribute name="m2e-apt" value="true"/>
45
+			<attribute name="test" value="true"/>
46
+		</attributes>
47
+	</classpathentry>
31 48
 	<classpathentry kind="output" path="target/classes"/>
32 49
 </classpath>

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

@@ -22,10 +22,15 @@ import org.insa.graphs.model.io.GraphReader;
22 22
 import org.insa.graphs.model.io.PathReader;
23 23
 
24 24
 // for colouring
25
+import java.time.Duration;
25 26
 import java.util.Random;
26 27
  import java.awt.Color;
28
+import java.util.concurrent.TimeUnit;
27 29
 
28 30
 public class Launch {
31
+    private static int verbose = 1;
32
+    private static long timeA = 0;
33
+    private static long timeD = 0;
29 34
 
30 35
 
31 36
     /**
@@ -52,6 +57,8 @@ public class Launch {
52 57
         return basicDrawing;
53 58
     }
54 59
 
60
+
61
+    // generates a path with the chosen algorithm
55 62
     public static Path createTestPath(Graph graph,int idOrigin,int idDest,String algo){
56 63
         Node A = graph.get(idOrigin);
57 64
         Node B = graph.get(idDest);
@@ -60,31 +67,37 @@ public class Launch {
60 67
         ShortestPathSolution sol;
61 68
         ShortestPathData data= new ShortestPathData(graph,A,B,ins);
62 69
 
63
-        switch (algo){
70
+        switch (algo){ // we chose the algo we want
64 71
             case "A*":
65 72
                 AStarAlgorithm AAlgo = new AStarAlgorithm(data);
66 73
                 sol =  AAlgo.doRun();
67 74
                 resu = sol.getPath();
75
+
68 76
                 break;
69 77
             case "D":
70 78
                 DijkstraAlgorithm DAlgo = new DijkstraAlgorithm(data);
71 79
                 sol =  DAlgo.doRun();
72 80
                 resu = sol.getPath();
81
+
73 82
                 break;
83
+
74 84
             case "BF":
75 85
                 BellmanFordAlgorithm BF = new BellmanFordAlgorithm(data);
76 86
                 sol =  BF.doRun();
77 87
                 resu = sol.getPath();
88
+
78 89
                 break;
79 90
             default:
80
-                System.out.println("no known algorithm");
91
+                if (verbose == 1) { System.out.println("no known algorithm");}
81 92
                 break;
82 93
         }
83
-
84 94
         return resu;
85 95
 
86 96
     }
87 97
     public static int comparePath(Path p1, Path p2,boolean time){
98
+        // true if both are null or if they have
99
+        //    - the same time cost
100
+        //    - the same length
88 101
         if (p1 == null){
89 102
             if (p2 == null){
90 103
                 return 1;
@@ -96,66 +109,102 @@ public class Launch {
96 109
                 return 0;
97 110
             }
98 111
         }
99
-        if(time)
100
-            if (Double.compare(p1.getMinimumTravelTime(),p2.getMinimumTravelTime())==0) {
112
+
113
+
114
+        if(time) {
115
+            if (Double.compare(p1.getMinimumTravelTime(), p2.getMinimumTravelTime()) == 0) {
101 116
                 return 1;
102
-            }
103
-            else
104
-            {
117
+            } else {
105 118
                 return 0;
106 119
             }
107
-        else
108
-            if (Float.compare(p1.getLength(),p2.getLength())==0) {
120
+        }else{
121
+            if (Float.compare(p1.getLength(), p2.getLength()) == 0) {
109 122
                 return 1;
110
-            }
111
-            else
112
-            {
123
+            } else {
113 124
                 return 0;
114 125
             }
126
+        }
115 127
     }
116 128
 
129
+    private static void displayResult(String algo, int justeD, int nbTest, long time){
130
+        if (verbose == 1) {
131
+            System.out.println(
132
+                    algo + " : number of good tests : " + Integer.toString(justeD) + "/"
133
+                            + Integer.toString(nbTest * 2) + ". Total execution time : " + Long.toString(time) + "ms");
134
+        }
135
+    }
117 136
 
118 137
 
119 138
 
120 139
 
121
-    private static int test(Graph graph, String testType,Drawing drawing){
122
-        int Id1 = (int) Math.floor(Math.random()*graph.size());
123
-        int Id2 = (int) Math.floor(Math.random()*graph.size());
140
+    private static int test(Graph graph, String testType,Drawing drawing, int id1, int id2){
124 141
         int resu = 0;
125
-        System.out.println("testing with nodes " + Id1 + " and " + Id2);
126
-        if (comparePath(createTestPath(graph,  Id1, Id2, testType),createTestPath(graph,  Id1, Id2, "BF"), true) == 0) {
127
-            resu++;
128
-        }
129
-        else
130
-        {
131
-            resu++;
142
+        long endTime;
143
+        long startTime;
144
+        if (verbose == 1) { System.out.print("testing " + testType +" with nodes " + id1 + " and " + id2);}
145
+
146
+        Path pathAlgo = null;
147
+
148
+        if (testType == "A*"){
149
+
150
+            // times the run of the algorithm
151
+
152
+            startTime = System.currentTimeMillis();
153
+            pathAlgo = createTestPath(graph,  id1, id2, "A*");
154
+            endTime = System.currentTimeMillis();
155
+
156
+            if (verbose == 2){System.out.println(endTime-startTime);}
157
+            timeA += (endTime-startTime);
158
+        } else {
159
+
160
+            // times the run of the algorithm
161
+
162
+            startTime = System.currentTimeMillis();
163
+            pathAlgo = createTestPath(graph,  id1, id2, "D");
164
+            endTime = System.currentTimeMillis();
165
+            timeD += (endTime-startTime);
166
+            if (verbose == 2){if (pathAlgo != null) {System.out.print(pathAlgo.getLength()+","+(endTime-startTime) + ",");}}
132 167
         }
133 168
 
134
-        if (comparePath(createTestPath(graph,  Id1, Id2, "D"),createTestPath(graph,  Id1, Id2, "BF"), false) == 0) {
169
+        Path pathBF = createTestPath(graph,  id1, id2, "BF");
170
+
171
+
172
+        // tests if the results are the same in terms of time and length
173
+        if (comparePath(pathAlgo, pathBF, true) == 1) {
135 174
             resu++;
136 175
         }
137
-        else
138
-        {
176
+
177
+        if (comparePath(pathAlgo, pathBF,false) == 1) {
139 178
             resu++;
140 179
         }
141
-        Path drawPath = createTestPath(graph,  Id1, Id2, "BF");
180
+
181
+        // draw the path created on the map (purely visual)
182
+        Path drawPath = pathAlgo;
142 183
         if (drawPath != null){
143 184
             if (!drawPath.isEmpty()){
144
-
145
-                Random rand = new Random();
146
-                float r = rand.nextFloat();
147
-                float g = rand.nextFloat();
148
-                float b = rand.nextFloat();
149
-                drawing.drawPath(drawPath,new Color(r, g, b));
185
+                try {
186
+                    if (testType == "A*") {
187
+                        drawing.drawPath(drawPath, new Color(150, 0, 150));
188
+                    } else {
189
+                        drawing.drawPath(drawPath, new Color(20, 200, 20));
190
+                    }
191
+                } catch (Exception e) {}
192
+                if (verbose == 1) { System.out.println(" ... Done (length : " + Float.toString(drawPath.getLength()) + " found in " + Long.toString(endTime-startTime) + " ms)");}
150 193
             }
151 194
         }
152 195
         return resu;
153 196
     }
154 197
 
198
+
199
+
200
+
201
+
155 202
     public static void main(String[] args) throws Exception {
156 203
 
157 204
         // Visit these directory to see the list of available files on Commetud.
158
-        final String mapName = "/home/rlacroix/Bureau/3MIC/Be Graphe/mapinsa/insa.mapgr";
205
+        //final String mapName = "/home/rlacroix/Bureau/3MIC/Be Graphe/mapinsa/insa.mapgr";
206
+        //final String mapName = "/home/rlacroix/Bureau/3MIC/Be Graphe/mapinsa/carre-dense.mapgr";
207
+        final String mapName = "/home/rlacroix/Bureau/3MIC/Be Graphe/mapinsa/california.mapgr";
159 208
         //final String pathName = "/home/rlacroix/Bureau/3MIC/Be Graphe/mapinsa/path_fr31insa_rangueil_r2.path";
160 209
 
161 210
         // Create a graph reader.
@@ -171,6 +220,8 @@ public class Launch {
171 220
         // TODO: Draw the graph on the drawing.
172 221
         drawing.drawGraph(graph);
173 222
 
223
+
224
+
174 225
         // TODO: Create a PathReader.
175 226
         //final PathReader pathReader = new BinaryPathReader(
176 227
         //        new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))));
@@ -181,20 +232,35 @@ public class Launch {
181 232
         // TODO: Draw the path.
182 233
         //drawing.drawPath(path);
183 234
 
184
-        System.out.println("==TESTS==");
185 235
 
186 236
 
187
-        int nbTest = 10000;
188
-        int juste = 0;
237
+        int nbTest = 2000;
238
+        int justeD = 0;
239
+        int justeA = 0;
240
+
241
+        if (verbose == 1) { System.out.println("== LAUNCHING " + nbTest + " TESTS ==");}
189 242
 
190 243
         for (int i = 0; i < nbTest; i++){
244
+            // picks two nodes at random
245
+            int id1 = (int) Math.floor(Math.random()*graph.size());
246
+            int id2 = (int) Math.floor(Math.random()*graph.size());
247
+
191 248
             if (i%10 == 0){
249
+                // cleans the board every 10 runs and display the comparative runtimes
192 250
                 drawing.clearOverlays();
251
+                displayResult("Dijkstra",justeD,i,timeD);
252
+                displayResult("A*",justeA,i,timeA);
253
+                if (verbose == 1) { System.out.println("A* takes "+ Long.toString(100*(timeA+1)/(timeD+1)) +"% of Dijkstra's execution time");}
193 254
             }
194
-            juste += test(graph,"A*",drawing);
255
+            if (verbose == 1) { System.out.println("Test number " + Integer.toString(i));}
256
+            justeD += test(graph,"D",drawing, id1, id2);
257
+            justeA += test(graph,"A*",drawing,id1, id2);
195 258
         }
196
-        System.out.println(
197
-                "number of good tests : " + Integer.toString(juste) + "/" + Integer.toString(nbTest*2)
198
-        );
259
+        if (verbose == 1) { System.out.println("===== Final Results =====");}
260
+        displayResult("Dijkstra",justeD,nbTest,timeD);
261
+        displayResult("A*",justeA,nbTest,timeA);
262
+        if (verbose == 1) { System.out.println("A* takes "+ Long.toString(100*timeA/timeD) +"% of Dijkstra's execution time");}
263
+
264
+
199 265
     }
200 266
 }

+ 17
- 0
be-graphes-model/.classpath View File

@@ -23,5 +23,22 @@
23 23
 			<attribute name="maven.pomderived" value="true"/>
24 24
 		</attributes>
25 25
 	</classpathentry>
26
+	<classpathentry kind="src" path="target/generated-sources/annotations">
27
+		<attributes>
28
+			<attribute name="optional" value="true"/>
29
+			<attribute name="maven.pomderived" value="true"/>
30
+			<attribute name="ignore_optional_problems" value="true"/>
31
+			<attribute name="m2e-apt" value="true"/>
32
+		</attributes>
33
+	</classpathentry>
34
+	<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
35
+		<attributes>
36
+			<attribute name="optional" value="true"/>
37
+			<attribute name="maven.pomderived" value="true"/>
38
+			<attribute name="ignore_optional_problems" value="true"/>
39
+			<attribute name="m2e-apt" value="true"/>
40
+			<attribute name="test" value="true"/>
41
+		</attributes>
42
+	</classpathentry>
26 43
 	<classpathentry kind="output" path="target/classes"/>
27 44
 </classpath>

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

@@ -36,16 +36,19 @@ public class Path {
36 36
     	if (nodes.size() == 1) {
37 37
     		return new Path(graph, nodes.get(0));
38 38
     	}
39
-    	if (nodes.size() == 1) {
40
-    		return new Path(graph);
41
-    	}
39
+
42 40
         List<Arc> arcs = new ArrayList<Arc>();
43
-        for (int i = 0 ; i < nodes.size(); i++) {
41
+
42
+        // we iterate over the list of nodes
43
+    	for (int i = 0 ; i < nodes.size(); i++) {
44 44
         	Node currNode = nodes.get(i);
45
-        	if (i < nodes.size() -1) {
45
+
46
+        	if (i < nodes.size() -1) { // if it's not the last
46 47
 	        	Node nextNode = nodes.get(i+1);
47 48
 	        	if (currNode.hasSuccessors()) { 
48 49
         			Arc better = null;
50
+
51
+                    // we compare all the edges to pick the best one
49 52
 	        		for (Arc j : currNode.getSuccessors()) {
50 53
 	        			if (j.getDestination() == nextNode) {
51 54
 	        				if (better == null || better.getMinimumTravelTime() > j.getMinimumTravelTime()) {
@@ -53,6 +56,8 @@ public class Path {
53 56
 	        				}
54 57
 	        			}
55 58
 	            	}
59
+
60
+                    // If it exists we add it else we throw an exception
56 61
 	        		if (better == null) {
57 62
 	        			throw (new IllegalArgumentException());
58 63
 	        		} else {
@@ -80,19 +85,23 @@ public class Path {
80 85
      */
81 86
     public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes)
82 87
             throws IllegalArgumentException {
88
+        //
83 89
     	if (nodes.size() == 1) {
84 90
     		return new Path(graph, nodes.get(0));
85 91
     	}
86
-    	if (nodes.size() == 1) {
87
-    		return new Path(graph);
88
-    	}
92
+
89 93
         List<Arc> arcs = new ArrayList<Arc>();
94
+
95
+    	// we iterate over the list of nodes
90 96
         for (int i = 0 ; i < nodes.size(); i++) {
91 97
         	Node currNode = nodes.get(i);
92
-        	if (i < nodes.size() -1) {
98
+
99
+        	if (i < nodes.size() -1) { // if it's not the last
93 100
 	        	Node nextNode = nodes.get(i+1);
94 101
 	        	if (currNode.hasSuccessors()) { 
95 102
         			Arc better = null;
103
+
104
+        			// we compare all the edges to pick the best one
96 105
 	        		for (Arc j : currNode.getSuccessors()) {
97 106
 	        			if (j.getDestination() == nextNode) {
98 107
 	        				if (better == null || better.getLength() > j.getLength()) {
@@ -100,6 +109,8 @@ public class Path {
100 109
 	        				}
101 110
 	        			}
102 111
 	            	}
112
+
113
+                    // If it exists we add it else we throw an exception
103 114
 	        		if (better == null) {
104 115
 	        			throw (new IllegalArgumentException());
105 116
 	        		} else {
@@ -253,17 +264,14 @@ public class Path {
253 264
      */
254 265
     public boolean isValid() {
255 266
     	Arc old = null;
256
-        // it is empty
257 267
     	if (this.isEmpty()) {
268
+            // it is empty so true
258 269
     		return true;
259 270
     	}
260
-    	// Origin is ok
261 271
     	if ((this.origin != null) && (this.arcs.size() == 0)) {
272
+            // only origin is ok: single node (without arcs)
262 273
     		return true;
263 274
     	}
264
-    	if (this.arcs.size() == 0) {
265
-    		return false;
266
-    	}
267 275
     	// destination of the first one is the origin of the second node
268 276
     	if (this.arcs.get(0).getOrigin() == this.origin) {
269 277
     		for (Arc a : this.arcs) {
@@ -292,6 +300,7 @@ public class Path {
292 300
      */
293 301
     public float getLength() {
294 302
     	float acc = 0;
303
+        // sum all of the lengths
295 304
     	for (Arc l : this.arcs) {
296 305
     		acc += l.getLength();
297 306
     	}
@@ -309,7 +318,7 @@ public class Path {
309 318
      * 
310 319
      */
311 320
     public double getTravelTime(double speed) {
312
-    	double speed2 = speed * 1000/3600; 
321
+    	double speed2 = speed * 1000/3600;  // conversion from km/h to m/s
313 322
         return (this.getLength()/speed2);
314 323
     }
315 324
 
@@ -322,6 +331,7 @@ public class Path {
322 331
      */
323 332
     public double getMinimumTravelTime() {
324 333
     	float acc = 0;
334
+    	// sum all of the minimum travel times
325 335
     	for (Arc l : this.arcs) {
326 336
     		acc += l.getMinimumTravelTime();
327 337
     	}

BIN
img.png View File


BIN
img2.png View File


+ 2
- 2
reponses.md View File

@@ -4,9 +4,9 @@ On a une liste de liste et non une matrice. L'avantage est de prendre bien moins
4 4
 
5 5
 ## Diagram UML
6 6
 Diagrame UML : <br>
7
-<img src="./img.png">
7
+<img src="./UML1.png">
8 8
 
9 9
 ## deuxieme diagram UML
10 10
 
11 11
 Diagrame UML : <br>
12
-<img src="./img2.png">
12
+<img src="./UML2.png">

Loading…
Cancel
Save